* PaypalApiController.cs: starting a paypal account access
* Catalog.xml: tests input with multiple values * FileSystemController.cs: Xml catalog path is now specified ala ~/ * WorkFlowController.cs: Gives the response a message * SimpleFormatter.cs: * FrontOfficeApiController.cs: document formatting * Global.asax.cs: due to refactoring * SimpleJsonPostMethod.cs: (code formatting) * Web.config: due to refactoring * Web.config: - document formatting - PayPal configuration * Web.csproj: references the PayPalCoreSdk.1.6.0 * packages.config: using the .Net 4.5.1 plateform
This commit is contained in:
parent
3c6c3f19aa
commit
da87d0ea97
12 changed files with 264 additions and 177 deletions
|
|
@ -12,9 +12,10 @@ namespace Yavsc.Controllers
|
|||
/// <summary>
|
||||
/// File system controller.
|
||||
/// </summary>
|
||||
public class FileSystemController : Controller
|
||||
{
|
||||
private static string usersDir ="~/users";
|
||||
public class FileSystemController : Controller
|
||||
{
|
||||
private static string usersDir = "~/users";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the users dir.
|
||||
/// </summary>
|
||||
|
|
@ -24,51 +25,54 @@ namespace Yavsc.Controllers
|
|||
return usersDir;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
public ActionResult Index ()
|
||||
{
|
||||
string user = Membership.GetUser ().UserName;
|
||||
ViewData ["UserName"] = user;
|
||||
|
||||
DirectoryInfo di = new DirectoryInfo (
|
||||
Path.Combine(
|
||||
Server.MapPath(UsersDir),
|
||||
user));
|
||||
Path.Combine (
|
||||
Server.MapPath (UsersDir),
|
||||
user));
|
||||
if (!di.Exists)
|
||||
di.Create ();
|
||||
return View (new FileInfoCollection( di.GetFiles()));
|
||||
}
|
||||
return View (new FileInfoCollection (di.GetFiles ()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Details the specified id.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
public ActionResult Details(string id)
|
||||
{
|
||||
public ActionResult Details (string id)
|
||||
{
|
||||
foreach (char x in Path.GetInvalidPathChars()) {
|
||||
if (id.Contains (x)) {
|
||||
ViewData ["Message"] =
|
||||
string.Format (
|
||||
"Something went wrong following the following path : {0} (\"{1}\")",
|
||||
id,x);
|
||||
"Something went wrong following the following path : {0} (\"{1}\")",
|
||||
id, x);
|
||||
return RedirectToAction ("Index");
|
||||
}
|
||||
}
|
||||
string fpath = Path.Combine (BaseDir, id);
|
||||
ViewData["Content"] = Url.Content (fpath);
|
||||
ViewData ["Content"] = Url.Content (fpath);
|
||||
FileInfo fi = new FileInfo (fpath);
|
||||
|
||||
return View (fi);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create this instance.
|
||||
/// </summary>
|
||||
public ActionResult Create()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
public ActionResult Create ()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the specified collection.
|
||||
|
|
@ -76,36 +80,32 @@ namespace Yavsc.Controllers
|
|||
/// <param name="collection">Collection.</param>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public ActionResult Create(FormCollection collection)
|
||||
public ActionResult Create (FormCollection collection)
|
||||
{
|
||||
try {
|
||||
string fnre = "[A-Za-z0-9~\\-.]+";
|
||||
HttpFileCollectionBase hfc = Request.Files;
|
||||
|
||||
for (int i=0; i<hfc.Count; i++)
|
||||
{
|
||||
if (!Regex.Match(hfc[i].FileName,fnre).Success)
|
||||
{
|
||||
ViewData ["Message"] += string.Format("<p>File name '{0}' refused</p>",hfc[i].FileName);
|
||||
ModelState.AddModelError(
|
||||
for (int i = 0; i < hfc.Count; i++) {
|
||||
if (!Regex.Match (hfc [i].FileName, fnre).Success) {
|
||||
ViewData ["Message"] += string.Format ("<p>File name '{0}' refused</p>", hfc [i].FileName);
|
||||
ModelState.AddModelError (
|
||||
"AFile",
|
||||
string.Format(
|
||||
string.Format (
|
||||
"The file name {0} dosn't match an acceptable file name {1}",
|
||||
hfc[i].FileName,fnre))
|
||||
;
|
||||
return View();
|
||||
hfc [i].FileName, fnre));
|
||||
return View ();
|
||||
}
|
||||
}
|
||||
for (int i=0; i<hfc.Count; i++)
|
||||
{
|
||||
for (int i = 0; i < hfc.Count; i++) {
|
||||
// TODO Limit with hfc[h].ContentLength
|
||||
string filename = Path.Combine(Server.MapPath(BaseDir),hfc[i].FileName);
|
||||
hfc[i].SaveAs(filename);
|
||||
ViewData ["Message"] += string.Format("<p>File name '{0}' saved</p>",hfc[i].FileName);
|
||||
string filename = Path.Combine (Server.MapPath (BaseDir), hfc [i].FileName);
|
||||
hfc [i].SaveAs (filename);
|
||||
ViewData ["Message"] += string.Format ("<p>File name '{0}' saved</p>", hfc [i].FileName);
|
||||
}
|
||||
return RedirectToAction ("Index","FileSystem");
|
||||
return RedirectToAction ("Index", "FileSystem");
|
||||
} catch (Exception e) {
|
||||
ViewData ["Message"] = "Exception:"+e.Message;
|
||||
ViewData ["Message"] = "Exception:" + e.Message;
|
||||
return View ();
|
||||
}
|
||||
}
|
||||
|
|
@ -115,49 +115,53 @@ namespace Yavsc.Controllers
|
|||
/// </summary>
|
||||
/// <value>The base dir.</value>
|
||||
public static string BaseDir { get { return Path.Combine (UsersDir, Membership.GetUser ().UserName); } }
|
||||
|
||||
/// <summary>
|
||||
/// Edit the specified id.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
public ActionResult Edit(int id)
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
public ActionResult Edit (int id)
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edit the specified id and collection.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
/// <param name="collection">Collection.</param>
|
||||
[HttpPost]
|
||||
public ActionResult Edit(int id, FormCollection collection)
|
||||
{
|
||||
try {
|
||||
return RedirectToAction ("Index");
|
||||
} catch {
|
||||
return View ();
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public ActionResult Edit (int id, FormCollection collection)
|
||||
{
|
||||
try {
|
||||
return RedirectToAction ("Index");
|
||||
} catch {
|
||||
return View ();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the specified id.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
public ActionResult Delete (int id)
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the specified id and collection.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
/// <param name="collection">Collection.</param>
|
||||
[HttpPost]
|
||||
public ActionResult Delete(int id, FormCollection collection)
|
||||
{
|
||||
try {
|
||||
return RedirectToAction ("Index");
|
||||
} catch {
|
||||
return View ();
|
||||
}
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public ActionResult Delete (int id, FormCollection collection)
|
||||
{
|
||||
try {
|
||||
return RedirectToAction ("Index");
|
||||
} catch {
|
||||
return View ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -49,23 +49,23 @@ namespace Yavsc.ApiControllers
|
|||
/// <summary>
|
||||
/// Catalog this instance.
|
||||
/// </summary>
|
||||
[AcceptVerbs("GET")]
|
||||
[AcceptVerbs ("GET")]
|
||||
public Catalog Catalog ()
|
||||
{
|
||||
Catalog c = CatalogManager.GetCatalog (Request.RequestUri.AbsolutePath);
|
||||
return c;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the product categorie.
|
||||
/// </summary>
|
||||
/// <returns>The product categorie.</returns>
|
||||
/// <param name="brandName">Brand name.</param>
|
||||
/// <param name="prodCategorie">Prod categorie.</param>
|
||||
[AcceptVerbs("GET")]
|
||||
[AcceptVerbs ("GET")]
|
||||
public ProductCategory GetProductCategorie (string brandName, string prodCategorie)
|
||||
{
|
||||
return CatalogManager.GetCatalog (Request.RequestUri.AbsolutePath).GetBrand (brandName).GetProductCategory (prodCategorie)
|
||||
;
|
||||
return CatalogManager.GetCatalog (Request.RequestUri.AbsolutePath).GetBrand (brandName).GetProductCategory (prodCategorie);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -81,30 +81,32 @@ namespace Yavsc.ApiControllers
|
|||
return est;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the estim tex.
|
||||
/// </summary>
|
||||
/// <returns>The estim tex.</returns>
|
||||
/// <param name="estimid">Estimid.</param>
|
||||
[AcceptVerbs("GET")]
|
||||
public HttpResponseMessage GetEstimTex(long estimid)
|
||||
[AcceptVerbs ("GET")]
|
||||
public HttpResponseMessage GetEstimTex (long estimid)
|
||||
{
|
||||
string texest = null;
|
||||
try {
|
||||
texest = getEstimTex (estimid);
|
||||
}
|
||||
catch (TemplateException ex) {
|
||||
return new HttpResponseMessage (HttpStatusCode.OK){ Content =
|
||||
} catch (TemplateException ex) {
|
||||
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||
new ObjectContent (typeof(string),
|
||||
ex.Message, new ErrorHtmlFormatter(HttpStatusCode.NotAcceptable,
|
||||
LocalizedText.DocTemplateException
|
||||
))};
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.Message, new ErrorHtmlFormatter (HttpStatusCode.NotAcceptable,
|
||||
LocalizedText.DocTemplateException
|
||||
))
|
||||
};
|
||||
} catch (Exception ex) {
|
||||
|
||||
return new HttpResponseMessage (HttpStatusCode.OK){ Content =
|
||||
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||
new ObjectContent (typeof(string),
|
||||
ex.Message, new SimpleFormatter("text/text")) };
|
||||
ex.Message, new SimpleFormatter ("text/text"))
|
||||
};
|
||||
}
|
||||
if (texest == null)
|
||||
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||
|
|
@ -119,20 +121,20 @@ namespace Yavsc.ApiControllers
|
|||
};
|
||||
}
|
||||
|
||||
private string getEstimTex(long estimid)
|
||||
private string getEstimTex (long estimid)
|
||||
{
|
||||
Yavsc.templates.Estim tmpe = new Yavsc.templates.Estim();
|
||||
Yavsc.templates.Estim tmpe = new Yavsc.templates.Estim ();
|
||||
Estimate e = wfmgr.GetEstimate (estimid);
|
||||
tmpe.Session = new Dictionary<string,object>();
|
||||
tmpe.Session = new Dictionary<string,object> ();
|
||||
tmpe.Session.Add ("estim", e);
|
||||
|
||||
Profile prpro = new Profile(ProfileBase.Create(e.Responsible));
|
||||
Profile prpro = new Profile (ProfileBase.Create (e.Responsible));
|
||||
if (!prpro.HasBankAccount)
|
||||
throw new TemplateException ("NotBankable:"+e.Responsible);
|
||||
throw new TemplateException ("NotBankable:" + e.Responsible);
|
||||
|
||||
Profile prcli = new Profile(ProfileBase.Create(e.Client));
|
||||
Profile prcli = new Profile (ProfileBase.Create (e.Client));
|
||||
if (!prcli.IsBillable)
|
||||
throw new TemplateException ("NotBillable:"+e.Client);
|
||||
throw new TemplateException ("NotBillable:" + e.Client);
|
||||
tmpe.Session.Add ("from", prpro);
|
||||
tmpe.Session.Add ("to", prcli);
|
||||
tmpe.Init ();
|
||||
|
|
@ -145,7 +147,7 @@ namespace Yavsc.ApiControllers
|
|||
/// </summary>
|
||||
/// <returns>The estim pdf.</returns>
|
||||
/// <param name="estimid">Estimid.</param>
|
||||
public HttpResponseMessage GetEstimPdf(long estimid)
|
||||
public HttpResponseMessage GetEstimPdf (long estimid)
|
||||
{
|
||||
Estimate estim = wfmgr.GetEstimate (estimid);
|
||||
//TODO better with pro.IsBankable && cli.IsBillable
|
||||
|
|
|
|||
48
web/Controllers/PaypalApiController.cs
Normal file
48
web/Controllers/PaypalApiController.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// PaypalApiController.cs
|
||||
//
|
||||
// Author:
|
||||
// Paul Schneider <paulschneider@free.fr>
|
||||
//
|
||||
// Copyright (c) 2015 Paul Schneider
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using System.Web.Http;
|
||||
|
||||
#if HASPAYPALAPI
|
||||
|
||||
using PayPal.Api;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
public class PaypalApiController: ApiController
|
||||
{
|
||||
public void GetPayments()
|
||||
{
|
||||
OAuthTokenCredential tokenCredential =
|
||||
new OAuthTokenCredential("<CLIENT_ID>", "<CLIENT_SECRET>");
|
||||
|
||||
string accessToken = tokenCredential.GetAccessToken();
|
||||
var parameters = new PayPal.Util.QueryParameters();
|
||||
parameters.Add ("Count", "10");
|
||||
|
||||
PaymentHistory paymentHistory = Payment.Get(apiContext, accessToken, parameters);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -108,7 +108,7 @@ namespace Yavsc.ApiControllers
|
|||
public HttpResponseMessage UpdateWritting([FromBody] Writting wr)
|
||||
{
|
||||
wfmgr.UpdateWritting (wr);
|
||||
return Request.CreateResponse (System.Net.HttpStatusCode.OK);
|
||||
return Request.CreateResponse<string> (System.Net.HttpStatusCode.OK,"WrittingUpdated:"+wr.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue