Files
yavsc/web/ApiControllers/FrontOfficeController.cs
Paul Schneider fe97f14831 Réorganisations.
La page de reservation par défaut est maintenant la reservation dite simple.

Fonctionnalités en cours de développement:

1) la reservation dite simple
2) la notification à la reservation
3) l'activité principale exercée
4) l'integration d'un premier thème clair

* MEA.sql: définit la valeur MEA du profile (Main Exerted Activity)
  dans la base de donnée

* Booking.aspx: Imlémente la vue du formulaire de reservation simple,
c'etait avant la reservation classique, sur une période plutôt qu'un
  jour.
La reservation classique est renomée `EavyBooking`.

* SimpleBookingQuery.cs: Implémente une simple commande de
  rendez-vous,
en tant que commande du workflow.

* .gitignore: ignorer les configuration des pré et prod totem.

* SkillEntity.cs:
* SkillManager.cs:
* Skills.aspx:
* SkillProvider.cs:
* SkillController.cs:
* UserSkills.aspx:
* NpgsqlSkillProvider.cs: refactorisation (-Skill+SkillEntity)

* NpgsqlProfileProvider.cs: Fixe un bug introduit avec
  l'implementation des profiles anonymes.

* FrontOfficeController.cs: definit l'interface de cotation des
  compétences attendues

* UserCard.ascx: Imlémente une carte utilisateur.

* Web.config: déclare le code activité principale exercée parmis les
  valeurs du profile authentifié.

* Web.csproj: ajoute les nouveaux formulaire de reservation au projet.

* PerformerProfile.cs: S'assure d'avoir une valeur pour le nom
  d'utilisateur à la création.

* LocalizedText.resx:
* LocalizedText.Designer.cs: "date préférée" en anglais

* LocalizedText.fr.resx:
* LocalizedText.fr.Designer.cs: "date préférée" en français

* Profile.cs: à la creation d'un profile, on doit avoir un nom
  d'utilisateur,
même dans le cas où le profile est anonyme (dans ce cas,
on l'appelle identifiant anonyme).
Sinon, on lève une exception.

* YavscModel.csproj: * refactorisation: le nom `Skill` est celui de
  l'espace,
celui de la classe devient `SkillEntity`.
* Creation de la requête dite simple d'un rendez-vous (pour
  prestation)
à une date donnée (sans heure), concernant simplement une activité.

* EavyBooking.aspx: Implémente la reservation lourde
2015-11-23 00:43:57 +01:00

192 lines
5.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http;
using System.Web.Profile;
using System.Web.Security;
using Yavsc.Formatters;
using Yavsc.Helpers;
using Yavsc.Model;
using Yavsc.Model.FrontOffice;
using Yavsc.Model.RolesAndMembers;
using Yavsc.Model.WorkFlow;
using System.IO;
using Yavsc.Model.FrontOffice.Catalog;
using Yavsc.Model.Skill;
namespace Yavsc.ApiControllers
{
/// <summary>
/// Front office controller.
/// </summary>
public class FrontOfficeController : YavscController
{
/// <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 = WorkFlowManager.ContentProvider.Get (id);
string username = Membership.GetUser ().UserName;
if (est.Client != username)
if (!Roles.IsUserInRole("Admin"))
if (!Roles.IsUserInRole("FrontOffice"))
throw new AuthorizationDenied (
string.Format (
"Auth denied to eid {1} for:{2}",
id, username));
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 = estimateToTex (id);
if (texest == null)
throw new InvalidOperationException (
"Not an estimate");
HttpResponseMessage result = new HttpResponseMessage () {
Content = new ObjectContent (typeof(string),
texest,
new SimpleFormatter ("text/x-tex"))
};
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue ("attachment") {
FileName = "estimate-" + id.ToString () + ".tex"
};
return result;
}
private string estimateToTex (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 prpro = new Profile (ProfileBase.Create (e.Responsible));
if (!prpro.HasBankAccount)
throw new TemplateException ("NotBankable:" + e.Responsible);
if (!prpro.HasPostalAddress)
throw new TemplateException ("NoPostalAddress:" + 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.Session.Add ("efrom", Membership.GetUser (e.Responsible).Email);
tmpe.Session.Add ("eto", Membership.GetUser (e.Client).Email);
tmpe.Init ();
return tmpe.TransformText ();
}
/// <summary>
/// Gets the estimate in pdf format from tex generation.
/// </summary>
/// <returns>The to pdf.</returns>
/// <param name="id">Estimid.</param>
[AcceptVerbs("GET")]
public HttpResponseMessage EstimateToPdf (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))
};
var memPdf = new MemoryStream ();
try {
new TexToPdfFormatter ().WriteToStream (
typeof(string), texest, memPdf,null);
}
catch (FormatterException ex) {
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
new ObjectContent (typeof(string), ex.Message+"\n\n"+ex.Output+"\n\n"+ex.Error,
new ErrorHtmlFormatter (HttpStatusCode.InternalServerError,
LocalizedText.InternalServerError))
};
}
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(memPdf.GetBuffer())
};
result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue ("attachment") {
FileName = String.Format (
"Estimation-{0}.pdf",
id)
};
return result;
}
/// <summary>
/// Rates the skill, this is a client action to profile its needs.
/// </summary>
/// <param name="rate">Skill rating.</param>
[Authorize()]
public void RateSkill (SkillRating rate) {
throw new NotImplementedException ();
}
}
}