* Estimates as Tex or Pdf

* Estimate edition [mix Mvc&Ajax]
* Billable&Bankable properties on profiles
This commit is contained in:
Paul Schneider 2014-10-25 23:54:19 +02:00
commit b39a444cf0
31 changed files with 1101 additions and 218 deletions

View file

@ -43,13 +43,7 @@ namespace Yavsc.Controllers
return new Profile (ProfileBase.Create (user));
}
[Authorize]
public ActionResult Profile(Profile model)
{
ViewData ["UserName"] = Membership.GetUser ().UserName;
model = GetProfile ((string)ViewData ["UserName"]);
return View (model);
}
// TODO [ValidateAntiForgeryToken]
public ActionResult DoLogin (LoginModel model, string returnUrl)
{
@ -200,14 +194,22 @@ namespace Yavsc.Controllers
}
[Authorize]
[HttpGet]
public ActionResult Profile(Profile model)
{
ViewData ["UserName"] = Membership.GetUser ().UserName;
model = GetProfile ((string) ViewData ["UserName"]);
return View (model);
}
[Authorize]
[HttpPost]
//public ActionResult UpdateProfile(HttpPostedFileBase Avatar, string Address, string CityAndState, string ZipCode, string Country, string WebSite)
public ActionResult UpdateProfile(Profile model, HttpPostedFileBase AvatarFile)
public ActionResult Profile(Profile model, HttpPostedFileBase AvatarFile)
{
string username = Membership.GetUser ().UserName;
ViewData ["UserName"] = username;
if (AvatarFile != null) {
if (AvatarFile.ContentType == "image/png") {
@ -233,14 +235,36 @@ namespace Yavsc.Controllers
"BlogVisible", model.BlogVisible);
HttpContext.Profile.SetPropertyValue (
"CityAndState", model.CityAndState);
HttpContext.Profile.SetPropertyValue (
"ZipCode", model.ZipCode);
HttpContext.Profile.SetPropertyValue (
"Country", model.Country);
HttpContext.Profile.SetPropertyValue (
"WebSite", model.WebSite);
HttpContext.Profile.SetPropertyValue (
"Name", model.Name);
HttpContext.Profile.SetPropertyValue (
"Phone", model.Phone);
HttpContext.Profile.SetPropertyValue (
"Mobile", model.Mobile);
HttpContext.Profile.SetPropertyValue (
"BankCode", model.BankCode);
HttpContext.Profile.SetPropertyValue (
"WicketCode", model.WicketCode);
HttpContext.Profile.SetPropertyValue (
"AccountNumber", model.AccountNumber);
HttpContext.Profile.SetPropertyValue (
"BankedKey", model.BankedKey);
HttpContext.Profile.SetPropertyValue (
"BIC", model.BIC);
HttpContext.Profile.SetPropertyValue (
"IBAN", model.IBAN);
HttpContext.Profile.Save ();
ViewData ["Message"] = "Profile enregistré.";
}
// HttpContext.Profile.SetPropertyValue("Avatar",Avatar);
return RedirectToAction ("Profile");
return View (model);
}
[Authorize]

View file

@ -225,7 +225,7 @@ namespace Yavsc.Controllers
return UserPost (model.PostId);
}
}
return View (model);
return UserPost (model.PostId);
}
string defaultAvatar;

View file

@ -14,12 +14,20 @@ using System.Net;
using WorkFlowProvider;
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
{
public class FrontOfficeController : ApiController
{
[AcceptVerbs("GET")]
public Catalog Catalog ()
{
@ -77,6 +85,52 @@ namespace Yavsc.ApiControllers
return est;
}
[AcceptVerbs("GET")]
public HttpResponseMessage GetTexEstim(long estimid)
{
return new HttpResponseMessage () {
Content = new ObjectContent (typeof(string),
getTexEstim (estimid),
new TexFormatter ())
};
}
private string getTexEstim(long estimid)
{
Yavsc.templates.Estim tmpe = new Yavsc.templates.Estim();
Estimate e = WorkFlowManager.GetEstimate (estimid);
tmpe.Session = new Dictionary<string,object>();
tmpe.Session.Add ("estim", e);
Profile pr = AccountController.GetProfile (e.Responsible);
tmpe.Session.Add ("from", pr);
tmpe.Session.Add ("to", pr);
tmpe.Init ();
return tmpe.TransformText ();
}
/// <summary>
/// Gets the estimate in pdf format from tex generation.
/// </summary>
/// <returns>The estim pdf.</returns>
/// <param name="estimid">Estimid.</param>
public HttpResponseMessage GetEstimPdf(long estimid)
{
Estimate estim = WorkFlowManager.GetEstimate (estimid);
Profile prpro = new Profile(ProfileBase.Create(estim.Responsible));
if (!prpro.IsBankable)
throw new Exception ("NotBankable:"+estim.Responsible);
Profile prcli = new Profile(ProfileBase.Create(estim.Client));
if (!prcli.IsBillable)
throw new Exception ("NotBillable:"+estim.Client);
return new HttpResponseMessage () {
Content = new ObjectContent (
typeof(Estimate),
estim,
new EstimToPdfFormatter ())
};
}
}
}

View file

@ -20,39 +20,54 @@ namespace Yavsc.Controllers
/// </summary>
public class FrontOfficeController : Controller
{
[Authorize]
public ActionResult Estimates ()
{
string username = Membership.GetUser ().UserName;
return View(WorkFlowManager.GetEstimates (username));
}
[Authorize]
public ActionResult Estimate(Estimate model,string submit)
{
if (ModelState.IsValid) {
ViewData ["WebApiUrl"] = "http://"+ Request.Url.Authority + "/api/WorkFlow";
string username = HttpContext.User.Identity.Name;
if (submit == null) {
if (model.Id > 0) {
Estimate f = WorkFlowManager.GetEstimate (model.Id);
if (f == null) {
ModelState.AddModelError ("Id", "Wrong Id");
return View (model);
}
if (username != f.Owner)
if (!Roles.IsUserInRole ("FrontOffice"))
throw new UnauthorizedAccessException ("You're not allowed to view/modify this estimate");
if (submit == "Update") {
if (model != f) {
WorkFlowManager.SetTitle (model.Id, model.Title);
}
} else if (submit == null) {
model = f;
}
model = f;
ModelState.Clear ();
string username = HttpContext.User.Identity.Name;
if (username != model.Responsible
&& username != model.Client
&& !Roles.IsUserInRole ("FrontOffice"))
throw new UnauthorizedAccessException ("You're not allowed to view this estimate");
}
} else if (ModelState.IsValid) {
ViewData ["WebApiUrl"] = "http://" + Request.Url.Authority + "/api/WorkFlow";
string username = HttpContext.User.Identity.Name;
if (username != model.Responsible
&& username != model.Client
&& !Roles.IsUserInRole ("FrontOffice"))
throw new UnauthorizedAccessException ("You're not allowed to modify this estimate");
if (model.Id == 0)
model = WorkFlowManager.CreateEstimate (
username,
model.Client, model.Title, model.Description);
else
WorkFlowManager.UpdateEstimate (model);
} else if (model.Id == 0 && submit=="Create") {
// Create the estimate
model.Id=WorkFlowManager.CreateEstimate (username,
model.Title);
model.Owner = username;
}
}
return View(model);
}
[AcceptVerbs("GET")]
public ActionResult Catalog ()
{

View file

@ -26,10 +26,10 @@ namespace Yavsc.ApiControllers
[HttpGet]
[Authorize]
public long CreateEstimate (string title)
public Estimate CreateEstimate (string title,string client,string description)
{
return WorkFlowManager.CreateEstimate (
Membership.GetUser().UserName,title);
Membership.GetUser().UserName,client,title,description);
}
[HttpGet]