yavsc/web/Controllers/WorkFlowController.cs

76 lines
1.7 KiB
C#
Raw Normal View History

2014-07-16 20:35:03 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using WorkFlowProvider;
2014-10-06 04:58:47 +02:00
using Yavsc.Model.WorkFlow;
using System.Web.Http.Controllers;
using System.Web.Security;
2014-07-16 20:35:03 +02:00
namespace Yavsc.ApiControllers
{
public class WorkFlowController : ApiController
{
string adminRoleName="Admin";
protected override void Initialize (HttpControllerContext controllerContext)
{
2014-10-06 04:58:47 +02:00
// TODO move it in a module initialization
base.Initialize (controllerContext);
if (!Roles.RoleExists (adminRoleName)) {
Roles.CreateRole (adminRoleName);
}
}
[HttpGet]
[Authorize]
public long CreateEstimate (string title)
{
2014-10-08 10:47:40 +02:00
return WorkFlowManager.CreateEstimate (
Membership.GetUser().UserName,title);
}
[HttpGet]
[Authorize]
public void DropWritting(long wrid)
{
2014-10-08 10:47:40 +02:00
WorkFlowManager.DropWritting (wrid);
}
2014-10-20 07:23:44 +02:00
2014-09-25 12:42:43 +02:00
[Authorize]
2014-10-20 07:23:44 +02:00
[AcceptVerbs("POST")]
public void UpdateWritting([FromBody] Writting wr)
2014-09-25 12:42:43 +02:00
{
2014-10-20 07:23:44 +02:00
if (!ModelState.IsValid)
throw new Exception ("Modèle invalide");
2014-10-08 10:47:40 +02:00
WorkFlowManager.UpdateWritting (wr);
2014-09-25 12:42:43 +02:00
}
[HttpGet]
[Authorize]
public void DropEstimate(long estid)
{
2014-10-08 10:47:40 +02:00
WorkFlowManager.DropEstimate (estid);
}
2014-10-12 15:22:45 +02:00
2014-07-16 20:35:03 +02:00
[HttpGet]
[Authorize]
2014-07-16 20:35:03 +02:00
public object Index()
{
// TODO inform user on its roles and alerts
string username = Membership.GetUser ().UserName;
return new { test=string.Format("Hello {0}!",username) };
2014-07-16 20:35:03 +02:00
}
2014-10-20 07:23:44 +02:00
[AcceptVerbs("POST")]
[Authorize]
2014-10-20 07:23:44 +02:00
public long Write ([FromUri] long estid, [FromBody] Writting wr) {
// TODO ensure estid owner matches the current one
2014-10-20 07:23:44 +02:00
return WorkFlowManager.Write(estid, wr.Description,
wr.UnitaryCost, wr.Count, wr.ProductReference);
}
2014-07-16 20:35:03 +02:00
}
}