yavsc/web/Controllers/WorkFlowController.cs

77 lines
1.7 KiB
C#

10 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using WorkFlowProvider;
10 years ago
using Yavsc.Model.WorkFlow;
using System.Web.Http.Controllers;
using System.Web.Security;
10 years ago
namespace Yavsc.ApiControllers
{
public class WorkFlowController : ApiController
{
string adminRoleName="Admin";
protected override void Initialize (HttpControllerContext controllerContext)
{
10 years ago
// TODO move it in a module initialization
base.Initialize (controllerContext);
if (!Roles.RoleExists (adminRoleName)) {
Roles.CreateRole (adminRoleName);
}
}
[HttpGet]
[Authorize]
public Estimate CreateEstimate (string title,string client,string description)
{
10 years ago
return WorkFlowManager.CreateEstimate (
Membership.GetUser().UserName,client,title,description);
}
[HttpGet]
[Authorize]
public void DropWritting(long wrid)
{
10 years ago
WorkFlowManager.DropWritting (wrid);
}
[Authorize]
[AcceptVerbs("POST")]
public void UpdateWritting([FromBody] Writting wr)
{
if (!ModelState.IsValid)
throw new Exception ("Modèle invalide");
10 years ago
WorkFlowManager.UpdateWritting (wr);
}
[HttpGet]
[Authorize]
public void DropEstimate(long estid)
{
10 years ago
WorkFlowManager.DropEstimate (estid);
}
10 years ago
10 years ago
[HttpGet]
[Authorize]
10 years ago
public object Index()
{
// TODO inform user on its roles and alerts
string username = Membership.GetUser ().UserName;
return new { test=string.Format("Hello {0}!",username) };
10 years ago
}
[AcceptVerbs("POST")]
[Authorize]
public long Write ([FromUri] long estid, [FromBody] Writting wr) {
// TODO ensure estid owner matches the current one
return WorkFlowManager.Write(estid, wr.Description,
wr.UnitaryCost, wr.Count, wr.ProductReference);
}
10 years ago
}
}