* IValueProvider.cs:
* TemplateException.cs: * Login.aspx: * Profile.aspx: * WebApiConfig.cs: * MyProfile.aspx: * IValueProvider.cs: * BlogsController.cs: * BasketController.cs: * ModuleController.cs: * AccountController.cs: * TemplateException.cs: * WorkFlowController.cs: * BlogsApiController.cs: * PaypalApiController.cs: * BasketController.cs: * BlogsApiController.cs: * WorkFlowController.cs: * PaypalApiController.cs: * FrontOfficeApiController.cs: * FrontOfficeApiController.cs: refactoring * jquery-ui.js: may be usefull at taking a date * Web.csproj: * WebApiConfig.cs: * App.master: added a spacer for a better rendering * style.css: better style * DateQuery.aspx: may use the jQuery "full calendar" * FreeDate.cs: refactoring
This commit is contained in:
parent
b2fdbc8d2e
commit
944009936d
19 changed files with 16721 additions and 119 deletions
|
|
@ -43,35 +43,15 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
return View ();
|
||||
}
|
||||
/// <summary>
|
||||
/// Login the specified returnUrl.
|
||||
/// </summary>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
public ActionResult Login (string returnUrl)
|
||||
{
|
||||
ViewData ["returnUrl"] = returnUrl;
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the profile.
|
||||
/// </summary>
|
||||
/// <returns>The profile.</returns>
|
||||
/// <param name="user">User.</param>
|
||||
public static Profile GetProfile (string user)
|
||||
{
|
||||
return new Profile (ProfileBase.Create (user));
|
||||
}
|
||||
|
||||
|
||||
// TODO [ValidateAntiForgeryToken]
|
||||
/// <summary>
|
||||
/// Dos the login.
|
||||
/// Does login.
|
||||
/// </summary>
|
||||
/// <returns>The login.</returns>
|
||||
/// <param name="model">Model.</param>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
public ActionResult DoLogin (LoginModel model, string returnUrl)
|
||||
public ActionResult Login (LoginModel model, string returnUrl)
|
||||
{
|
||||
if (ModelState.IsValid) {
|
||||
if (Membership.ValidateUser (model.UserName, model.Password)) {
|
||||
|
|
@ -88,7 +68,7 @@ namespace Yavsc.Controllers
|
|||
ViewData ["returnUrl"] = returnUrl;
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
return View ("Login", model);
|
||||
return View (model);
|
||||
}
|
||||
/// <summary>
|
||||
/// Register the specified model and returnUrl.
|
||||
|
|
@ -255,11 +235,11 @@ namespace Yavsc.Controllers
|
|||
/// <param name="model">Model.</param>
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public ActionResult MyProfile (Profile model)
|
||||
public ActionResult Profile (Profile model)
|
||||
{
|
||||
string username = Membership.GetUser ().UserName;
|
||||
ViewData ["UserName"] = username;
|
||||
model = GetProfile (username);
|
||||
model = new Profile (ProfileBase.Create (username));
|
||||
model.RememberMe = FormsAuthentication.GetAuthCookie (username, true) == null;
|
||||
return View (model);
|
||||
}
|
||||
|
|
@ -272,7 +252,7 @@ namespace Yavsc.Controllers
|
|||
[Authorize]
|
||||
[HttpPost]
|
||||
// ASSERT("Membership.GetUser ().UserName is made of simple characters, no slash nor backslash"
|
||||
public ActionResult MyProfile (Profile model, HttpPostedFileBase AvatarFile)
|
||||
public ActionResult Profile (Profile model, HttpPostedFileBase AvatarFile)
|
||||
{
|
||||
string username = Membership.GetUser ().UserName;
|
||||
ViewData ["UserName"] = username;
|
||||
|
|
|
|||
|
|
@ -1,92 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.Http;
|
||||
using Yavsc.Model.WorkFlow;
|
||||
using System.Collections.Specialized;
|
||||
using Yavsc.Model.FrontOffice;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Basket controller.
|
||||
/// Maintains a collection of articles
|
||||
/// qualified with name value pairs
|
||||
/// </summary>
|
||||
public class BasketController : ApiController
|
||||
{
|
||||
/// <summary>
|
||||
/// The wfmgr.
|
||||
/// </summary>
|
||||
protected WorkFlowManager wfmgr = null;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the specified controllerContext.
|
||||
/// </summary>
|
||||
/// <param name="controllerContext">Controller context.</param>
|
||||
protected override void Initialize (System.Web.Http.Controllers.HttpControllerContext controllerContext)
|
||||
{
|
||||
base.Initialize (controllerContext);
|
||||
wfmgr = new WorkFlowManager ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current basket, creates a new one, if it doesn't exist.
|
||||
/// </summary>
|
||||
/// <value>The current basket.</value>
|
||||
protected CommandSet CurrentBasket {
|
||||
get {
|
||||
CommandSet b = wfmgr.GetCommands (Membership.GetUser ().UserName);
|
||||
if (b == null) b = new CommandSet ();
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the specified basket item using specified command parameters.
|
||||
/// </summary>
|
||||
/// <param name="cmdParams">Command parameters.</param>
|
||||
[Authorize]
|
||||
public long Create(NameValueCollection cmdParams)
|
||||
{
|
||||
// HttpContext.Current.Request.Files
|
||||
Command cmd = new Command(cmdParams, HttpContext.Current.Request.Files);
|
||||
CurrentBasket.Add (cmd);
|
||||
return cmd.Id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the specified basket item.
|
||||
/// </summary>
|
||||
/// <param name="itemid">Itemid.</param>
|
||||
[Authorize]
|
||||
Command Read(long itemid){
|
||||
return CurrentBasket[itemid];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the specified item parameter using the specified value.
|
||||
/// </summary>
|
||||
/// <param name="itemid">Item identifier.</param>
|
||||
/// <param name="param">Parameter name.</param>
|
||||
/// <param name="value">Value.</param>
|
||||
[Authorize]
|
||||
public void UpdateParam(long itemid, string param, string value)
|
||||
{
|
||||
CurrentBasket [itemid].Parameters [param] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the specified item.
|
||||
/// </summary>
|
||||
/// <param name="itemid">Item identifier.</param>
|
||||
[Authorize]
|
||||
public void Delete(long itemid)
|
||||
{
|
||||
CurrentBasket.Remove (itemid);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.Http;
|
||||
using Npgsql.Web.Blog;
|
||||
using Yavsc.Model.Blogs;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Blogs API controller.
|
||||
/// </summary>
|
||||
public class BlogsApiController : ApiController
|
||||
{
|
||||
private const string adminRoleName = "Admin";
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the specified controllerContext.
|
||||
/// </summary>
|
||||
/// <param name="controllerContext">Controller context.</param>
|
||||
protected override void Initialize (System.Web.Http.Controllers.HttpControllerContext controllerContext)
|
||||
{
|
||||
base.Initialize (controllerContext);
|
||||
if (!Roles.RoleExists (adminRoleName)) {
|
||||
Roles.CreateRole (adminRoleName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tag the specified postid and tag.
|
||||
/// </summary>
|
||||
/// <param name="postid">Postid.</param>
|
||||
/// <param name="tag">Tag.</param>
|
||||
public long Tag (long postid,string tag) {
|
||||
BlogEntry e = BlogManager.GetPost (postid);
|
||||
if (!Roles.IsUserInRole ("Admin")) {
|
||||
string rguser = Membership.GetUser ().UserName;
|
||||
if (rguser != e.UserName) {
|
||||
throw new AccessViolationException (
|
||||
string.Format (
|
||||
"Vous n'avez pas le droit de tagger des billets du Blog de {0}",
|
||||
e.UserName));
|
||||
}
|
||||
}
|
||||
return BlogManager.Tag (postid, tag);
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes the post.
|
||||
/// </summary>
|
||||
/// <param name="user">User.</param>
|
||||
/// <param name="title">Title.</param>
|
||||
public void RemovePost(string user, string title) {
|
||||
BlogEntry e = BlogManager.GetPost (user, title);
|
||||
if (e == null) {
|
||||
throw new KeyNotFoundException (
|
||||
string.Format("Aucun post portant le titre \"{0}\" pour l'utilisateur {1}",
|
||||
title, user));
|
||||
}
|
||||
BlogManager.RemovePost (user, title);
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes the tag.
|
||||
/// </summary>
|
||||
/// <param name="tagid">Tagid.</param>
|
||||
public void RemoveTag(long tagid) {
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ namespace Yavsc.Controllers
|
|||
// find entries
|
||||
BlogEntryCollection c = BlogManager.FindPost (user, sf, pageIndex, pageSize, out tr);
|
||||
// Get author's meta data
|
||||
Profile bupr = AccountController.GetProfile (user);
|
||||
Profile bupr = new Profile (ProfileBase.Create (user));
|
||||
ViewData ["BlogUserProfile"] = bupr;
|
||||
// Inform of listing meta data
|
||||
ViewData ["BlogTitle"] = bupr.BlogTitle;
|
||||
|
|
@ -155,7 +155,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
if (e == null)
|
||||
return View ("TitleNotFound");
|
||||
Profile pr = AccountController.GetProfile (e.UserName);
|
||||
Profile pr = new Profile (ProfileBase.Create (e.UserName));
|
||||
if (pr==null)
|
||||
return View ("TitleNotFound");
|
||||
ViewData ["BlogUserProfile"] = pr;
|
||||
|
|
|
|||
|
|
@ -1,184 +0,0 @@
|
|||
using System;
|
||||
using Yavsc;
|
||||
using SalesCatalog;
|
||||
using System.Web.Routing;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using System.Web.Http;
|
||||
using System.Net.Http;
|
||||
using System.Web;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Web.Security;
|
||||
using Yavsc.Model.WorkFlow;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using Yavsc.Model.RolesAndMembers;
|
||||
using Yavsc.Controllers;
|
||||
using Yavsc.Formatters;
|
||||
using System.Text;
|
||||
using System.Web.Profile;
|
||||
using System.Collections.Specialized;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Model.FrontOffice;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Front office controller.
|
||||
/// </summary>
|
||||
public class FrontOfficeController : ApiController
|
||||
{
|
||||
/// <summary>
|
||||
/// The wfmgr.
|
||||
/// </summary>
|
||||
protected WorkFlowManager wfmgr = null;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the specified controllerContext.
|
||||
/// </summary>
|
||||
/// <param name="controllerContext">Controller context.</param>
|
||||
protected override void Initialize (System.Web.Http.Controllers.HttpControllerContext controllerContext)
|
||||
{
|
||||
base.Initialize (controllerContext);
|
||||
wfmgr = new WorkFlowManager ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Catalog this instance.
|
||||
/// </summary>
|
||||
[AcceptVerbs ("GET")]
|
||||
public Catalog Catalog ()
|
||||
{
|
||||
Catalog c = CatalogManager.GetCatalog ();
|
||||
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")]
|
||||
public ProductCategory GetProductCategorie (string brandName, string prodCategorie)
|
||||
{
|
||||
return CatalogManager.GetCatalog ().GetBrand (brandName).GetProductCategory (prodCategorie);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the estimate.
|
||||
/// </summary>
|
||||
/// <returns>The estimate.</returns>
|
||||
/// <param name="id">Estimate Id.</param>
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public Estimate GetEstimate (long id)
|
||||
{
|
||||
Estimate est = wfmgr.ContentProvider.GetEstimate (id);
|
||||
return est;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the estim tex.
|
||||
/// </summary>
|
||||
/// <returns>The estim tex.</returns>
|
||||
/// <param name="id">Estimate id.</param>
|
||||
[AcceptVerbs ("GET")]
|
||||
public HttpResponseMessage EstimateToTex (long id)
|
||||
{
|
||||
string texest = null;
|
||||
try {
|
||||
texest = estimateToTex (id);
|
||||
} catch (TemplateException ex) {
|
||||
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||
new ObjectContent (typeof(string),
|
||||
ex.Message, new ErrorHtmlFormatter (HttpStatusCode.NotAcceptable,
|
||||
LocalizedText.DocTemplateException
|
||||
))
|
||||
};
|
||||
} catch (Exception ex) {
|
||||
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||
new ObjectContent (typeof(string),
|
||||
ex.Message, new ErrorHtmlFormatter (HttpStatusCode.InternalServerError,
|
||||
LocalizedText.DocTemplateException))
|
||||
};
|
||||
}
|
||||
if (texest == null)
|
||||
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||
new ObjectContent (typeof(string), "Not an estimation id:" + id,
|
||||
new ErrorHtmlFormatter (HttpStatusCode.NotFound,
|
||||
LocalizedText.Estimate_not_found))
|
||||
};
|
||||
|
||||
return new HttpResponseMessage () {
|
||||
Content = new ObjectContent (typeof(string),
|
||||
texest,
|
||||
new SimpleFormatter ("text/x-tex"))
|
||||
};
|
||||
}
|
||||
|
||||
private string estimateToTex (long estimid)
|
||||
{
|
||||
Yavsc.templates.Estim tmpe = new Yavsc.templates.Estim ();
|
||||
Estimate e = wfmgr.GetEstimate (estimid);
|
||||
tmpe.Session = new Dictionary<string,object> ();
|
||||
tmpe.Session.Add ("estim", e);
|
||||
|
||||
Profile prpro = new Profile (ProfileBase.Create (e.Responsible));
|
||||
if (!prpro.HasBankAccount)
|
||||
throw new TemplateException ("NotBankable:" + e.Responsible);
|
||||
|
||||
Profile prcli = new Profile (ProfileBase.Create (e.Client));
|
||||
if (!prcli.IsBillable)
|
||||
throw new TemplateException ("NotBillable:" + e.Client);
|
||||
tmpe.Session.Add ("from", prpro);
|
||||
tmpe.Session.Add ("to", prcli);
|
||||
tmpe.Init ();
|
||||
return tmpe.TransformText ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the estimate in pdf format from tex generation.
|
||||
/// </summary>
|
||||
/// <returns>The to pdf.</returns>
|
||||
/// <param name="estimid">Estimid.</param>
|
||||
[AcceptVerbs("GET")]
|
||||
public HttpResponseMessage EstimateToPdf (long estimid)
|
||||
{
|
||||
string texest = null;
|
||||
try {
|
||||
texest = estimateToTex (estimid);
|
||||
} catch (TemplateException ex) {
|
||||
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||
new ObjectContent (typeof(string),
|
||||
ex.Message, new ErrorHtmlFormatter (HttpStatusCode.NotAcceptable,
|
||||
LocalizedText.DocTemplateException
|
||||
))
|
||||
};
|
||||
} catch (Exception ex) {
|
||||
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||
new ObjectContent (typeof(string),
|
||||
ex.Message, new ErrorHtmlFormatter (HttpStatusCode.InternalServerError,
|
||||
LocalizedText.DocTemplateException))
|
||||
};
|
||||
}
|
||||
if (texest == null)
|
||||
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||
new ObjectContent (typeof(string), "Not an estimation id:" + estimid,
|
||||
new ErrorHtmlFormatter (HttpStatusCode.NotFound,
|
||||
LocalizedText.Estimate_not_found))
|
||||
};
|
||||
|
||||
return new HttpResponseMessage () {
|
||||
Content = new ObjectContent (typeof(string),
|
||||
texest,
|
||||
new TexToPdfFormatter ())
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
using System;
|
||||
using Yavsc;
|
||||
using SalesCatalog;
|
||||
using System.Web.Routing;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using System.Web.Http;
|
||||
using System.Net.Http;
|
||||
using System.Web;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Yavsc;
|
||||
using System.Web.Security;
|
||||
using Yavsc.Model.WorkFlow;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using Yavsc.Model.RolesAndMembers;
|
||||
using Yavsc.Controllers;
|
||||
using Yavsc.Formatters;
|
||||
using System.Text;
|
||||
using System.Web.Profile;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
|
||||
interface IValueProvider<T>
|
||||
{
|
||||
T GetValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,36 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Yavsc.Model;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Module controller.
|
||||
/// </summary>
|
||||
public class ModuleController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialize the specified requestContext.
|
||||
/// </summary>
|
||||
/// <param name="requestContext">Request context.</param>
|
||||
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
|
||||
{
|
||||
base.Initialize (requestContext);
|
||||
ConfigurationManager.GetSection ("ymodules");
|
||||
|
||||
}
|
||||
|
||||
// List<IModule> modules = new List<IModule> ();
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Yavsc.Model;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Module controller.
|
||||
/// </summary>
|
||||
public class ModuleController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialize the specified requestContext.
|
||||
/// </summary>
|
||||
/// <param name="requestContext">Request context.</param>
|
||||
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
|
||||
{
|
||||
base.Initialize (requestContext);
|
||||
ConfigurationManager.GetSection ("ymodules");
|
||||
|
||||
}
|
||||
|
||||
// List<IModule> modules = new List<IModule> ();
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
//
|
||||
// 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
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
using System;
|
||||
using Yavsc;
|
||||
using SalesCatalog;
|
||||
using System.Web.Routing;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using System.Web.Http;
|
||||
using System.Net.Http;
|
||||
using System.Web;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Yavsc;
|
||||
using System.Web.Security;
|
||||
using Yavsc.Model.WorkFlow;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using Yavsc.Model.RolesAndMembers;
|
||||
using Yavsc.Controllers;
|
||||
using Yavsc.Formatters;
|
||||
using System.Text;
|
||||
using System.Web.Profile;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
class TemplateException : Exception
|
||||
{
|
||||
public TemplateException(string message):base(message)
|
||||
{
|
||||
}
|
||||
public TemplateException(string message,Exception innerException):base(message,innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
//
|
||||
// WebApiConfig.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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Yavsc.Formatters;
|
||||
using Yavsc.Model.FrontOffice;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace Yavsc
|
||||
{
|
||||
/// <summary>
|
||||
/// Web API config.
|
||||
/// </summary>
|
||||
public static class WebApiConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the URL prefix.
|
||||
/// </summary>
|
||||
/// <value>The URL prefix.</value>
|
||||
public static string UrlPrefix { get { return "api"; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL prefix relative.
|
||||
/// </summary>
|
||||
/// <value>The URL prefix relative.</value>
|
||||
public static string UrlPrefixRelative { get { return "~/api"; } }
|
||||
|
||||
/// <summary>
|
||||
/// Register the specified config.
|
||||
/// </summary>
|
||||
/// <param name="config">Config.</param>
|
||||
public static void Register(HttpConfiguration config)
|
||||
{
|
||||
config.Routes.MapHttpRoute(
|
||||
name: "DefaultApi",
|
||||
routeTemplate: WebApiConfig.UrlPrefix + "/{controller}/{action}/{id}",
|
||||
defaults: new { action="Index", id = RouteParameter.Optional }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,151 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using Yavsc;
|
||||
using Yavsc.Model.WorkFlow;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.ModelBinding;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Work flow controller.
|
||||
/// </summary>
|
||||
public class WorkFlowController : ApiController
|
||||
{
|
||||
string adminRoleName="Admin";
|
||||
/// <summary>
|
||||
/// The wfmgr.
|
||||
/// </summary>
|
||||
protected WorkFlowManager wfmgr = null;
|
||||
/// <summary>
|
||||
/// Initialize the specified controllerContext.
|
||||
/// </summary>
|
||||
/// <param name="controllerContext">Controller context.</param>
|
||||
protected override void Initialize (HttpControllerContext controllerContext)
|
||||
{
|
||||
// TODO move it in a module initialization
|
||||
base.Initialize (controllerContext);
|
||||
if (!Roles.RoleExists (adminRoleName)) {
|
||||
Roles.CreateRole (adminRoleName);
|
||||
}
|
||||
wfmgr = new WorkFlowManager ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the estimate.
|
||||
/// </summary>
|
||||
/// <returns>The estimate.</returns>
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="client">Client.</param>
|
||||
/// <param name="description">Description.</param>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public Estimate CreateEstimate (string title,string client,string description)
|
||||
{
|
||||
return wfmgr.CreateEstimate (
|
||||
Membership.GetUser().UserName,client,title,description);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops the writting.
|
||||
/// </summary>
|
||||
/// <param name="wrid">Wrid.</param>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public void DropWritting(long wrid)
|
||||
{
|
||||
wfmgr.DropWritting (wrid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops the estimate.
|
||||
/// </summary>
|
||||
/// <param name="estid">Estid.</param>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public void DropEstimate(long estid)
|
||||
{
|
||||
string username = Membership.GetUser().UserName;
|
||||
Estimate e = wfmgr.GetEstimate (estid);
|
||||
if (e == null)
|
||||
throw new InvalidOperationException("not an estimate id:"+estid);
|
||||
if (username != e.Responsible
|
||||
&& !Roles.IsUserInRole ("FrontOffice"))
|
||||
throw new UnauthorizedAccessException ("You're not allowed to drop this estimate");
|
||||
|
||||
wfmgr.DropEstimate (estid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public object Index()
|
||||
{
|
||||
// TODO inform user on its roles and alerts
|
||||
string username = Membership.GetUser ().UserName;
|
||||
return new { test=string.Format("Hello {0}!",username) };
|
||||
}
|
||||
|
||||
private HttpResponseMessage CreateModelStateErrorResponse () {
|
||||
// strip exceptions
|
||||
Dictionary<string,string[]> errs = new Dictionary<string, string[]> ();
|
||||
|
||||
foreach (KeyValuePair<string,ModelState> st
|
||||
in ModelState.Where (x => x.Value.Errors.Count > 0))
|
||||
errs.Add(st.Key, st.Value.Errors.Select(x=>x.ErrorMessage).ToArray());
|
||||
|
||||
return Request.CreateResponse(System.Net.HttpStatusCode.BadRequest,
|
||||
errs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the writting.
|
||||
/// </summary>
|
||||
/// <returns>The writting.</returns>
|
||||
/// <param name="wr">Wr.</param>
|
||||
[Authorize]
|
||||
[AcceptVerbs("POST")]
|
||||
[ValidateAjax]
|
||||
public HttpResponseMessage UpdateWritting([FromBody] Writting wr)
|
||||
{
|
||||
wfmgr.UpdateWritting (wr);
|
||||
return Request.CreateResponse<string> (System.Net.HttpStatusCode.OK,"WrittingUpdated:"+wr.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified imputation to the given estimation by estimation id.
|
||||
/// </summary>
|
||||
/// <param name="estid">Estimation identifier</param>
|
||||
/// <param name="wr">Imputation to add</param>
|
||||
[AcceptVerbs("POST")]
|
||||
[Authorize]
|
||||
[ValidateAjax]
|
||||
public HttpResponseMessage Write ([FromUri] long estid, [FromBody] Writting wr) {
|
||||
if (estid <= 0) {
|
||||
ModelState.AddModelError ("EstimationId", "Spécifier un identifiant d'estimation valide");
|
||||
return Request.CreateResponse (System.Net.HttpStatusCode.BadRequest,
|
||||
ValidateAjaxAttribute.GetErrorModelObject (ModelState));
|
||||
}
|
||||
try {
|
||||
return Request.CreateResponse(System.Net.HttpStatusCode.OK,
|
||||
wfmgr.Write(estid, wr.Description,
|
||||
wr.UnitaryCost, wr.Count, wr.ProductReference));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return Request.CreateResponse (
|
||||
System.Net.HttpStatusCode.InternalServerError,
|
||||
"Internal server error:" + ex.Message + "\n" + ex.StackTrace);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue