From 6dfe83308e65cb5b6bc0eb49ac71e83baaaa23e2 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 18 Feb 2015 16:32:22 +0100 Subject: [PATCH] * Basket.aspx: refactoring * NpgsqlContentProvider.cs: fixing the command parameters deserialisation * NpgsqlWorkflow.csproj: prehaps not needed new references * FrontOfficeController.cs: code formatting * Command.aspx: a link to the basket * Commande.cs: In order the deserialize from Json --- WorkFlowProvider/NpgsqlContentProvider.cs | 19 ++++++++++++++----- WorkFlowProvider/NpgsqlWorkflow.csproj | 2 ++ web/Controllers/FrontOfficeController.cs | 3 +-- web/Views/FrontOffice/Basket.aspx | 22 +++++++++++++++++----- web/Views/FrontOffice/Command.aspx | 1 + yavscModel/FrontOffice/Commande.cs | 3 ++- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/WorkFlowProvider/NpgsqlContentProvider.cs b/WorkFlowProvider/NpgsqlContentProvider.cs index 92e4f6c5..16427d33 100644 --- a/WorkFlowProvider/NpgsqlContentProvider.cs +++ b/WorkFlowProvider/NpgsqlContentProvider.cs @@ -7,8 +7,11 @@ using Yavsc.Model.WorkFlow; using System.Configuration.Provider; using System.Collections.Generic; using Yavsc.Model.FrontOffice; -using Newtonsoft.Json; using System.Web.Security; +using System.Runtime.Serialization.Json; +using System.IO; +using System.Text; +using Newtonsoft.Json; namespace WorkFlowProvider { @@ -25,13 +28,16 @@ namespace WorkFlowProvider public long RegisterCommand (Command com) { long id; + using (NpgsqlConnection cnx = CreateConnection ()) { using (NpgsqlCommand cmd = cnx.CreateCommand ()) { cmd.CommandText = - "insert into commandes (prdref,creation,params) values (@pref,@creat,@prs) returning id"; + "insert into commandes (prdref,creation,params,clientname,applicationname) values (@pref,@creat,@prms,@cli,@app) returning id"; cmd.Parameters.Add ("@pref", com.ProductRef); cmd.Parameters.Add ("@creat", com.CreationDate); - cmd.Parameters.Add ("@prs", JsonConvert.SerializeObject(com.Parameters)); + cmd.Parameters.Add ("@prms", JsonConvert.SerializeObject(com.Parameters)); + cmd.Parameters.Add ("@cli", Membership.GetUser().UserName); + cmd.Parameters.Add ("@app", ApplicationName); cnx.Open (); com.Id = id = (long)cmd.ExecuteScalar (); } @@ -57,7 +63,7 @@ namespace WorkFlowProvider using (NpgsqlConnection cnx = CreateConnection ()) { using (NpgsqlCommand cmd = cnx.CreateCommand ()) { cmd.CommandText = - "select id,prdref,creation,params from commandes where @user = clientname and applicationname = @app"; + "select id,creation,prdref,params from commandes where @user = clientname and applicationname = @app"; cmd.Parameters.Add ("@user", username); cmd.Parameters.Add ("@app", this.ApplicationName); cnx.Open (); @@ -67,7 +73,10 @@ namespace WorkFlowProvider ycmd.Id = rdr.GetInt64(0); ycmd.CreationDate = rdr.GetDateTime(1); ycmd.ProductRef = rdr.GetString(2); - ycmd.Parameters = JsonConvert.DeserializeObject(rdr.GetString(3)) as StringDictionary; + + object prms = JsonConvert.DeserializeObject>(rdr.GetString (3)); + ycmd.Parameters = prms as Dictionary ; + cmds.Add (ycmd); } } diff --git a/WorkFlowProvider/NpgsqlWorkflow.csproj b/WorkFlowProvider/NpgsqlWorkflow.csproj index 4cf2301a..e3109a37 100644 --- a/WorkFlowProvider/NpgsqlWorkflow.csproj +++ b/WorkFlowProvider/NpgsqlWorkflow.csproj @@ -42,6 +42,8 @@ + + diff --git a/web/Controllers/FrontOfficeController.cs b/web/Controllers/FrontOfficeController.cs index 1e04bf22..a780bb46 100644 --- a/web/Controllers/FrontOfficeController.cs +++ b/web/Controllers/FrontOfficeController.cs @@ -186,10 +186,9 @@ namespace Yavsc.Controllers [Authorize] public ActionResult Basket () { - return View (wfmgr.GetCommands(Membership.GetUser().UserName)); + return View (wfmgr.GetCommands (Membership.GetUser ().UserName)); } - /// /// Command the specified collection. /// diff --git a/web/Views/FrontOffice/Basket.aspx b/web/Views/FrontOffice/Basket.aspx index ff7dd704..72841343 100644 --- a/web/Views/FrontOffice/Basket.aspx +++ b/web/Views/FrontOffice/Basket.aspx @@ -1,14 +1,15 @@ -<%@ Page Title="Basket" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %> +<%@ Page Title="Basket" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage" %> + <% Title = Title +" "+ Model.Count+" article(s)"; %> + - - +<% if (Model.Count>0) { %>
    -<% foreach (Commande cmd in Model.Values) { %> +<% foreach (Command cmd in Model.Values) { %>
  • <%= cmd.Id %> <%= cmd.CreationDate %> @@ -16,11 +17,22 @@ <%= cmd.Status %> <%= cmd.ProductRef %>
      - <% foreach (string key in cmd.Parameters.Keys) { %> + <% if (cmd.Parameters!=null) + foreach (string key in cmd.Parameters.Keys) { %>
    • <%=key%>: <%=cmd.Parameters[key]%>
    • <% } %>
  • <% } %>
+<% } %> +
+ + +
  • + <%= Html.ActionLink("Catalog","Catalog" ) %> +
  • + <%= Html.ActionLink("Estimates","Estimates" ) %> +
+
\ No newline at end of file diff --git a/web/Views/FrontOffice/Command.aspx b/web/Views/FrontOffice/Command.aspx index 57569e5e..9f7cae32 100644 --- a/web/Views/FrontOffice/Command.aspx +++ b/web/Views/FrontOffice/Command.aspx @@ -1,6 +1,7 @@ <%@ Page Title="Commande" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage" %> + <%= Html.ActionLink("Votre panier","Basket","FrontOffice" ) %> diff --git a/yavscModel/FrontOffice/Commande.cs b/yavscModel/FrontOffice/Commande.cs index 15eebc42..a1c1c524 100644 --- a/yavscModel/FrontOffice/Commande.cs +++ b/yavscModel/FrontOffice/Commande.cs @@ -4,6 +4,7 @@ using System.Collections.Specialized; using Yavsc.Model.WorkFlow; using Yavsc.Model.FileSystem; using System.Web; +using System.Collections.Generic; namespace Yavsc.Model.FrontOffice @@ -40,7 +41,7 @@ namespace Yavsc.Model.FrontOffice /// /// The parameters. /// - public StringDictionary Parameters = new StringDictionary(); + public Dictionary Parameters = new Dictionary (); FileInfoCollection Files { get {