* Web.csproj:

* YavscModel.csproj:
* Basket.cs:
* Basket.aspx:
* Commande.cs:
* BasketController.cs:
* CommandSet.cs:
* NpgsqlWorkflow.csproj:
* FileSystemController.cs:
* FrontOfficeController.cs:
* NpgsqlContentProvider.cs: implementing a basket

* ProjectInfo.cs:
* ITCPNpgsqlProvider.cs:
* CommandStatus.cs:
* NpgsqlBlogProvider.cs: xml doc

* CalendarApi.cs: document formatting

* FileSystemManager.cs: refactoring

* WorkFlowManager.cs:
* IContentProvider.cs: provides a basket

* WebFileInfoCollection.cs: not used
This commit is contained in:
Paul Schneider 2015-02-18 13:32:25 +01:00
commit 75fe032822
19 changed files with 388 additions and 127 deletions

View file

@ -7,7 +7,6 @@ using System.Web.Http;
using Yavsc.Model.WorkFlow;
using System.Collections.Specialized;
using Yavsc.Model.FrontOffice;
using System.Web.SessionState;
namespace Yavsc.ApiControllers
{
@ -37,12 +36,10 @@ namespace Yavsc.ApiControllers
/// Gets the current basket, creates a new one, if it doesn't exist.
/// </summary>
/// <value>The current basket.</value>
protected Basket CurrentBasket {
protected CommandSet CurrentBasket {
get {
HttpSessionState session = HttpContext.Current.Session;
Basket b = (Basket) session ["Basket"];
if (b == null)
session ["Basket"] = b = new Basket ();
CommandSet b = wfmgr.GetCommands (Membership.GetUser ().UserName);
if (b == null) b = new CommandSet ();
return b;
}
}
@ -55,7 +52,7 @@ namespace Yavsc.ApiControllers
public long Create(NameValueCollection cmdParams)
{
// HttpContext.Current.Request.Files
Commande cmd = new Commande(cmdParams, HttpContext.Current.Request.Files);
Command cmd = new Command(cmdParams, HttpContext.Current.Request.Files);
CurrentBasket.Add (cmd);
return cmd.Id;
}
@ -65,7 +62,7 @@ namespace Yavsc.ApiControllers
/// </summary>
/// <param name="itemid">Itemid.</param>
[Authorize]
Commande Read(long itemid){
Command Read(long itemid){
return CurrentBasket[itemid];
}

View file

@ -15,15 +15,13 @@ namespace Yavsc.Controllers
/// </summary>
public class FileSystemController : Controller
{
private string usersDir = "~/users";
/// <summary>
/// Gets the users base directory.
/// </summary>
/// <value>The users dir.</value>
public string UsersDir {
public string RootDir {
get {
return usersDir;
return mgr.Prefix;
}
}
@ -36,7 +34,8 @@ namespace Yavsc.Controllers
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
{
base.Initialize (requestContext);
mgr = new FileSystemManager (UsersDir);
mgr = new FileSystemManager (
string.Format("~/users/{0}",Membership.GetUser().UserName));
}
/// <summary>
@ -45,7 +44,7 @@ namespace Yavsc.Controllers
[Authorize]
public ActionResult Index (string id)
{
return View (mgr.GetFiles (Membership.GetUser().UserName+"/"+id));
return View (mgr.GetFiles (id));
}
/// <summary>
@ -63,9 +62,9 @@ namespace Yavsc.Controllers
return RedirectToAction ("Index");
}
}
string fpath = Path.Combine (UserBaseDir, id);
ViewData ["Content"] = Url.Content (fpath);
FileInfo fi = new FileInfo (fpath);
FileInfo fi = mgr.FileInfo (id);
ViewData ["Content"] = Url.Content (fi.FullName);
return View (fi);
}
@ -78,16 +77,15 @@ namespace Yavsc.Controllers
[Authorize]
public ActionResult Create (string id)
{
string path=Membership.GetUser().UserName+"/"+id;
mgr.Put ( path, Request.Files);
return View ("Index",mgr.GetFiles(path));
mgr.Put ( id, Request.Files);
return View ("Index",mgr.GetFiles(id));
}
/// <summary>
/// Gets the user's base dir.
/// </summary>
/// <value>The base dir.</value>
public string UserBaseDir { get { return Path.Combine (UsersDir, Membership.GetUser ().UserName); } }
public string UserBaseDir { get { return Path.Combine (RootDir, Membership.GetUser ().UserName); } }
/// <summary>
/// Edit the specified id.

View file

@ -181,19 +181,14 @@ namespace Yavsc.Controllers
}
/// <summary>
/// Command this instance.
/// Basket this instance.
/// </summary>
public ActionResult Command ()
[Authorize]
public ActionResult Basket ()
{
return View ();
return View (wfmgr.GetCommands(Membership.GetUser().UserName));
}
private Basket GetBasket ()
{
if (Session ["Basket"] == null)
Session ["Basket"] = new Basket();
return Session ["Basket"] as Basket;
}
/// <summary>
/// Command the specified collection.
@ -204,29 +199,9 @@ namespace Yavsc.Controllers
public ActionResult Command (FormCollection collection)
{
try {
// get files from the request
string fnre = "[A-Za-z0-9~\\-.]+";
HttpFileCollectionBase hfc = Request.Files;
// TODO mime-magic on content, and file name filter
foreach (String h in hfc.AllKeys) {
if (!Regex.Match (hfc [h].FileName, fnre).Success) {
ViewData ["Message"] = "File name refused";
ModelState.AddModelError (
h,
string.Format (
"The file name {0} dosn't match an acceptable file name {1}",
hfc [h].FileName, fnre));
return View (collection);
}
}
string usersdir = Server.MapPath("~/users");
FileSystemManager fsmgr = new FileSystemManager(usersdir);
foreach (String h in hfc.AllKeys) {
// TODO Limit with hfc[h].ContentLength
hfc [h].SaveAs (Path.Combine (usersdir, hfc [h].FileName));
}
// Add specified product command to the basket,
GetBasket().Add (new Commande(collection,HttpContext.Request.Files));
// saves it in db
new Command(collection,HttpContext.Request.Files);
ViewData ["Message"] = LocalizedText.Item_added_to_basket;
return View (collection);
} catch (Exception e) {

View file

@ -103,13 +103,13 @@ namespace Yavsc.Helpers.Google
try {
using (WebResponse resp = webreq.GetResponse ()) {
using (Stream respstream = resp.GetResponseStream ()) {
try {
try {
res = (CalendarEntryList) new DataContractJsonSerializer(typeof(CalendarEntryList)).ReadObject (respstream);
} catch (Exception ex) {
respstream.Close ();
resp.Close ();
} catch (Exception ex) {
respstream.Close ();
resp.Close ();
webreq.Abort ();
throw new GoogleErrorException(ex);
throw ex;
}
}
resp.Close ();

View file

@ -0,0 +1,26 @@
<%@ Page Title="Basket" Language="C#" Inherits="System.Web.Mvc.ViewPage<Basket>" MasterPageFile="~/Models/App.master" %>
<asp:Content ContentPlaceHolderID="init" ID="init1" runat="server">
<% Title = Title +" "+ Model.Count+" article(s)"; %>
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" ID="mainContent" runat="server">
<ul>
<% foreach (Commande cmd in Model.Values) { %>
<li>
<%= cmd.Id %>
<%= cmd.CreationDate %>
<%= cmd.Status %>
<%= cmd.ProductRef %>
<ul>
<% foreach (string key in cmd.Parameters.Keys) { %>
<li><%=key%>: <%=cmd.Parameters[key]%></li>
<% } %>
</ul>
</li>
<% } %>
</ul>
</asp:Content>

View file

@ -673,6 +673,7 @@
<Content Include="Scripts\jquery.googlemaps.js" />
<Content Include="Scripts\jquery.googlemaps.min.js" />
<Content Include="Views\Account\MyProfile.aspx" />
<Content Include="Views\FrontOffice\Basket.aspx" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />