* 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
vnext
Paul Schneider 10 years ago
parent 75fe032822
commit 6dfe83308e
6 changed files with 37 additions and 13 deletions

@ -7,8 +7,11 @@ using Yavsc.Model.WorkFlow;
using System.Configuration.Provider; using System.Configuration.Provider;
using System.Collections.Generic; using System.Collections.Generic;
using Yavsc.Model.FrontOffice; using Yavsc.Model.FrontOffice;
using Newtonsoft.Json;
using System.Web.Security; using System.Web.Security;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
using Newtonsoft.Json;
namespace WorkFlowProvider namespace WorkFlowProvider
{ {
@ -25,13 +28,16 @@ namespace WorkFlowProvider
public long RegisterCommand (Command com) public long RegisterCommand (Command com)
{ {
long id; long id;
using (NpgsqlConnection cnx = CreateConnection ()) { using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) { using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText = 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 ("@pref", com.ProductRef);
cmd.Parameters.Add ("@creat", com.CreationDate); 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 (); cnx.Open ();
com.Id = id = (long)cmd.ExecuteScalar (); com.Id = id = (long)cmd.ExecuteScalar ();
} }
@ -57,7 +63,7 @@ namespace WorkFlowProvider
using (NpgsqlConnection cnx = CreateConnection ()) { using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) { using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText = 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 ("@user", username);
cmd.Parameters.Add ("@app", this.ApplicationName); cmd.Parameters.Add ("@app", this.ApplicationName);
cnx.Open (); cnx.Open ();
@ -67,7 +73,10 @@ namespace WorkFlowProvider
ycmd.Id = rdr.GetInt64(0); ycmd.Id = rdr.GetInt64(0);
ycmd.CreationDate = rdr.GetDateTime(1); ycmd.CreationDate = rdr.GetDateTime(1);
ycmd.ProductRef = rdr.GetString(2); ycmd.ProductRef = rdr.GetString(2);
ycmd.Parameters = JsonConvert.DeserializeObject(rdr.GetString(3)) as StringDictionary;
object prms = JsonConvert.DeserializeObject<Dictionary<string,string>>(rdr.GetString (3));
ycmd.Parameters = prms as Dictionary<string,string> ;
cmds.Add (ycmd); cmds.Add (ycmd);
} }
} }

@ -42,6 +42,8 @@
</Reference> </Reference>
<Reference Include="System.Web" /> <Reference Include="System.Web" />
<Reference Include="System.Web.ApplicationServices" /> <Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

@ -186,10 +186,9 @@ namespace Yavsc.Controllers
[Authorize] [Authorize]
public ActionResult Basket () public ActionResult Basket ()
{ {
return View (wfmgr.GetCommands(Membership.GetUser().UserName)); return View (wfmgr.GetCommands (Membership.GetUser ().UserName));
} }
/// <summary> /// <summary>
/// Command the specified collection. /// Command the specified collection.
/// </summary> /// </summary>

@ -1,14 +1,15 @@
<%@ Page Title="Basket" Language="C#" Inherits="System.Web.Mvc.ViewPage<Basket>" MasterPageFile="~/Models/App.master" %> <%@ Page Title="Basket" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<CommandSet>" %>
<asp:Content ContentPlaceHolderID="init" ID="init1" runat="server"> <asp:Content ContentPlaceHolderID="init" ID="init1" runat="server">
<% Title = Title +" "+ Model.Count+" article(s)"; %> <% Title = Title +" "+ Model.Count+" article(s)"; %>
</asp:Content> </asp:Content>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:Content ContentPlaceHolderID="MainContent" ID="mainContent" runat="server"> <% if (Model.Count>0) { %>
<ul> <ul>
<% foreach (Commande cmd in Model.Values) { %> <% foreach (Command cmd in Model.Values) { %>
<li> <li>
<%= cmd.Id %> <%= cmd.Id %>
<%= cmd.CreationDate %> <%= cmd.CreationDate %>
@ -16,11 +17,22 @@
<%= cmd.Status %> <%= cmd.Status %>
<%= cmd.ProductRef %> <%= cmd.ProductRef %>
<ul> <ul>
<% foreach (string key in cmd.Parameters.Keys) { %> <% if (cmd.Parameters!=null)
foreach (string key in cmd.Parameters.Keys) { %>
<li><%=key%>: <%=cmd.Parameters[key]%></li> <li><%=key%>: <%=cmd.Parameters[key]%></li>
<% } %> <% } %>
</ul> </ul>
</li> </li>
<% } %> <% } %>
</ul> </ul>
<% } %>
</asp:Content>
<asp:Content ID="MASContentContent" ContentPlaceHolderID="MASContent" runat="server">
<ul><li>
<%= Html.ActionLink("Catalog","Catalog" ) %>
</li><li>
<%= Html.ActionLink("Estimates","Estimates" ) %>
</li></ul>
</asp:Content> </asp:Content>

@ -1,6 +1,7 @@
<%@ Page Title="Commande" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<FormCollection>" %> <%@ Page Title="Commande" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<FormCollection>" %>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server"> <asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
<%= Html.ActionLink("Votre panier","Basket","FrontOffice" ) %>
</asp:Content> </asp:Content>
<asp:Content ID="MASContentContent" ContentPlaceHolderID="MASContent" runat="server"> <asp:Content ID="MASContentContent" ContentPlaceHolderID="MASContent" runat="server">

@ -4,6 +4,7 @@ using System.Collections.Specialized;
using Yavsc.Model.WorkFlow; using Yavsc.Model.WorkFlow;
using Yavsc.Model.FileSystem; using Yavsc.Model.FileSystem;
using System.Web; using System.Web;
using System.Collections.Generic;
namespace Yavsc.Model.FrontOffice namespace Yavsc.Model.FrontOffice
@ -40,7 +41,7 @@ namespace Yavsc.Model.FrontOffice
/// <summary> /// <summary>
/// The parameters. /// The parameters.
/// </summary> /// </summary>
public StringDictionary Parameters = new StringDictionary(); public Dictionary<string,string> Parameters = new Dictionary<string,string> ();
FileInfoCollection Files { FileInfoCollection Files {
get { get {

Loading…