yavsc/web/ApiControllers/WorkFlowController.cs

182 lines
4.9 KiB
C#

10 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
10 years ago
using System.Web;
using System.Web.Security;
using Yavsc;
10 years ago
using Yavsc.Model.WorkFlow;
using System.Web.Http;
using Yavsc.Model.RolesAndMembers;
using Yavsc.Helpers;
using Yavsc.Model;
using System.Web.Http.Controllers;
10 years ago
namespace Yavsc.ApiControllers
{
/// <summary>
/// Work flow controller.
/// </summary>
9 years ago
public class WorkFlowController : ApiController
10 years ago
{
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)
{
10 years ago
// 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>
/// Register the specified userModel.
/// </summary>
/// <param name="userModel">User model.</param>
[HttpGet]
[ValidateAjax]
[Authorize(Roles="Admin,FrontOffice")]
public void Register([FromBody] RegisterModel userModel)
{
if (ModelState.IsValid) {
MembershipCreateStatus mcs;
var user = Membership.CreateUser (
userModel.UserName,
userModel.Password,
userModel.Email,
null,
null,
userModel.IsApprouved,
out mcs);
switch (mcs) {
case MembershipCreateStatus.DuplicateEmail:
ModelState.AddModelError ("Email",
string.Format(LocalizedText.DuplicateEmail,userModel.UserName) );
return ;
case MembershipCreateStatus.DuplicateUserName:
* font-awesome.css: an awesome css * hallo.js: Use a forked Hallo.js * showdown.js: * to-markdown.js: * mdd_gripper.png: * mdd_toolbar.png: * mdd_modal_background.png: The client side Markdown is now implemented using Hallo.js * FontAwesome.otf: * fontawesome-webfont.eot: * fontawesome-webfont.svg: * fontawesome-webfont.ttf: * fontawesome-webfont.woff: * fontawesome-webfont.woff2: awesome * MarkdownDeep.dll: a modified version to render video and audio tags * NpgsqlBlogProvider.cs: * CalendarController.cs: * WorkFlowController.cs: refactoring: The `UserName` property from the `BlogEntry` class is renamed to `Author` * InputUserName.cs: formatting * BlogsController.cs: * refactoring: The `UserName` property from the `BlogEntry` class is renamed to `Author` * Fixes pandoc process on file named with some spaces * BlogsController.cs: UserName became Author on BlogEntry objects * Global.asax.cs: route /fonts is now ignored. * MarkdownHelper.cs: transform Markdown using a given base url * App.master: jquery was not needed on all pages. * Edit.aspx: using Hallo.js * BlogEntry.cs: * UserPost.aspx: * UserPosts.aspx: * BlogManager.cs: * RemoveTitle.aspx: * BlogEntryCollection.cs: * UUBlogEntryCollection.cs: * UUTBlogEntryCollection.cs: refactoring * Web.config: ? * Web.csproj: * use my local assembly for MarkdownDeep.dll * fontawesome integration * Hallo.js, to-markdown.js, showdowwn.js integration * packages.config: Now use forked MarkdownDeep * MarkdownDeepLib.min.js: * MarkdownDeep License.txt: * MarkdownDeep Quick Reference.txt: using my local revision * mdd_ajax_loader.gif: The client side Markdown is now implemented using Hallo.js
9 years ago
ModelState.AddModelError ("Author",
string.Format(LocalizedText.DuplicateUserName,userModel.Email));
return ;
case MembershipCreateStatus.Success:
if (!userModel.IsApprouved)
* AccountController.cs: Register and reset passord from Web API * GCMController.cs: initial creation, will host GCM calls and related procedures. * ResetPassword.aspx: Html view to reset the password * LocalizedText.resx: * LocalizedText.fr.resx: new String form circles * Web.config: * Web.csproj: * YavscModel.csproj: * LocalizedText.Designer.cs: * Profile.cs: * Profile.cs: * LocalizedText.fr.Designer.cs: * LoginModel.cs: * Publishing.cs: * CalendarController.cs: * LoginModel.cs: * GCMRegister.cs: * Publishing.cs: * GCMRegister.cs: * NewRoleModel.cs: * NewRoleModel.cs: * RegisterModel.cs: * NewAdminModel.cs: * RegisterModel.cs: * NewAdminModel.cs: * LostPasswordModel.cs: * RegisterViewModel.cs: * RegisterViewModel.cs: * ProviderPublicInfo.cs: * RegisterClientModel.cs: * ChangePasswordModel.cs: * ProviderPublicInfo.cs: * RegisterClientModel.cs: * ChangePasswordModel.cs: Fixes a typo (in the namespace :-/) * NpgsqlCircleProvider.cs: Fixes the Circle creation * Global.asax.cs: * AdminController.cs: * NpgsqlContentProvider.cs: code formatting * BlogsController.cs: * CircleController.cs: * WorkFlowController.cs: * PaypalApiController.cs: * FrontOfficeController.cs: refactoring * AccountController.cs: Adds the way to reset the password * FrontOfficeController.cs: xml doc * T.cs: Make this class an helper to translation * YavscHelpers.cs: Implements the e-mail sending * style.css: style uniformization * Circles.aspx: Implements the Html interface to Circle creation (modifications and deletions are still to implement) * Register.ascx: Allows the error display in case of lack of power of the user at registering another user. * Estimate.aspx: use the partial view to register from the Account folder. Cleans the useless reference to ~/Theme/dark/style.css, that was for using the "tablesorter.js", no used anymore. * Web.config: Trying to have all the Index pages to work...
9 years ago
YavscHelpers.SendActivationMessage (user);
return;
default:
throw new InvalidOperationException (string.Format("Unexpected user creation code :{0}",mcs));
}
}
}
/// <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);
}
10 years ago
/// <summary>
/// Index this instance.
/// </summary>
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
}
/// <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);
}
}
10 years ago
}
10 years ago
}