From c22be7f6b50386fc51477a503811105e73a30651 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Fri, 10 Oct 2014 11:54:18 +0200 Subject: [PATCH] * Estimate.aspx: from backoffice * CatalogManager.cs: Uses GetDefaultProvider * Catalog.cs: the Catalog object now should support a unique id in the system : UID, exposed as one of its properties. * AccountController.cs: new static method te get an user profile by its name. * AdminController.cs: Uses the Yavsc.Admin namespace (refactoring) * Web.csproj: * BlogManager.cs: * BackOfficeController.cs: refactoring * BlogsController.cs: Fixes the Blog title * FrontOfficeController.cs: Changes on the go for the Command object * AddRole.aspx: minor syntax change * UserPosts.aspx: show the blog title * style.css: black transparent for the background of posts * Profile.cs: Method FromProfileBase became a constructor * Commande.cs: nothing * Estimate.aspx: moved to the frontoffice views * CatalogHelper.cs: Writting GetDefaultProvider --- SalesCatalog/CatalogHelper.cs | 29 ++++++++++++++++++------ SalesCatalog/CatalogManager.cs | 2 +- SalesCatalog/Model/Catalog.cs | 7 ++++++ web/Controllers/AccountController.cs | 7 +++++- web/Controllers/AdminController.cs | 6 +++++ web/Controllers/BackOfficeController.cs | 8 +++---- web/Controllers/BlogsController.cs | 26 +++++++++++++-------- web/Controllers/FrontOfficeController.cs | 6 ++++- web/Views/Admin/AddRole.aspx | 4 ++-- web/Views/BackOffice/Estimate.aspx | 12 ---------- web/Views/Blogs/UserPosts.aspx | 2 +- web/Views/FrontOffice/Estimate.aspx | 19 ++++++++++++++++ web/Web.csproj | 2 +- web/style.css | 2 +- yavscModel/Blogs/BlogManager.cs | 2 ++ yavscModel/RolesAndMemebers/Profile.cs | 8 ++++--- yavscModel/WorkFlow/Commande.cs | 8 +++++-- 17 files changed, 104 insertions(+), 46 deletions(-) delete mode 100644 web/Views/BackOffice/Estimate.aspx create mode 100644 web/Views/FrontOffice/Estimate.aspx diff --git a/SalesCatalog/CatalogHelper.cs b/SalesCatalog/CatalogHelper.cs index b6a859f0..de5d1327 100644 --- a/SalesCatalog/CatalogHelper.cs +++ b/SalesCatalog/CatalogHelper.cs @@ -12,13 +12,20 @@ namespace SalesCatalog /// public static class CatalogHelper { - public static CatalogProvider GetProvider () - { - CatalogProvidersConfigurationSection config = ConfigurationManager.GetSection ("system.web/catalog") as CatalogProvidersConfigurationSection; - if (config == null) + + public static CatalogProvidersConfigurationSection Config {get; set; } + + public static void Load () { + if (Config != null) + return ; + Config = ConfigurationManager.GetSection ("system.web/catalog") as CatalogProvidersConfigurationSection; + if (Config == null) throw new ConfigurationErrorsException("The configuration bloc for the catalog provider was not found"); - CatalogProviderConfigurationElement celt = - config.Providers.GetElement (config.DefaultProvider); + foreach (CatalogProviderConfigurationElement e in Config.Providers) { + CreateProvider (e); + } + } + private static CatalogProvider CreateProvider(CatalogProviderConfigurationElement celt) { if (celt == null) throw new ConfigurationErrorsException("The default catalog provider was not found"); Type catprtype = Type.GetType (celt.Type); @@ -28,7 +35,7 @@ namespace SalesCatalog ConstructorInfo ci = catprtype.GetConstructor (Type.EmptyTypes); if (ci==null) throw new Exception ( - string.Format("The catalog provider type ({0}) doesn't contain public constructor with empty parameter list",celt.Type)); + string.Format("The catalog provider type ({0}) doesn't contain public constructor with empty parameter list",celt.Type)); CatalogProvider cp = ci.Invoke (Type.EmptyTypes) as CatalogProvider; NameValueCollection c = new NameValueCollection (); @@ -40,6 +47,14 @@ namespace SalesCatalog cp.Initialize (celt.Name, c); return cp; } + + public static CatalogProvider GetDefaultProvider () + { + CatalogProviderConfigurationElement celt = + Config.Providers.GetElement (Config.DefaultProvider); + + return CreateProvider (celt); + } } } diff --git a/SalesCatalog/CatalogManager.cs b/SalesCatalog/CatalogManager.cs index d1e77809..080860b2 100644 --- a/SalesCatalog/CatalogManager.cs +++ b/SalesCatalog/CatalogManager.cs @@ -11,7 +11,7 @@ namespace SalesCatalog { public static Catalog GetCatalog () { - CatalogProvider p = CatalogHelper.GetProvider (); + CatalogProvider p = CatalogHelper.GetDefaultProvider (); return p.GetCatalog (); } } diff --git a/SalesCatalog/Model/Catalog.cs b/SalesCatalog/Model/Catalog.cs index 93dad93a..ad53d8cb 100644 --- a/SalesCatalog/Model/Catalog.cs +++ b/SalesCatalog/Model/Catalog.cs @@ -7,6 +7,13 @@ namespace SalesCatalog.Model /// Catalog. /// public class Catalog { + + /// + /// Gets or sets the catalog unique identifier in the system. + /// + /// The unique identifier. + string UID { get; set; } + /// /// Gets or sets the brands. /// diff --git a/web/Controllers/AccountController.cs b/web/Controllers/AccountController.cs index e0c50fda..13d44811 100644 --- a/web/Controllers/AccountController.cs +++ b/web/Controllers/AccountController.cs @@ -38,11 +38,16 @@ namespace Yavsc.Controllers return View (); } + public static Profile GetProfile (string user) + { + return new Profile (ProfileBase.Create (user)); + } + [Authorize] public ActionResult Profile(Profile model) { ViewData ["UserName"] = Membership.GetUser ().UserName; - model.FromProfileBase(HttpContext.Profile); + model = GetProfile ((string)ViewData ["UserName"]); return View (model); } // TODO [ValidateAntiForgeryToken] diff --git a/web/Controllers/AdminController.cs b/web/Controllers/AdminController.cs index 985f1fcc..c08080e5 100644 --- a/web/Controllers/AdminController.cs +++ b/web/Controllers/AdminController.cs @@ -7,9 +7,15 @@ using System.Web.Mvc.Ajax; using System.Web.Security; using Yavsc.Model.RolesAndMembers; using Yavsc.Model.Admin; +using Yavsc.Admin; + namespace Yavsc.Controllers { + /// + /// Admin controller. + /// Only Admin members should be allowed to use it. + /// public class AdminController : Controller { [Authorize(Roles="Admin")] diff --git a/web/Controllers/BackOfficeController.cs b/web/Controllers/BackOfficeController.cs index 85ba60ee..c005838a 100644 --- a/web/Controllers/BackOfficeController.cs +++ b/web/Controllers/BackOfficeController.cs @@ -10,12 +10,10 @@ namespace Yavsc.Controllers { public class BackOfficeController : Controller { - public ActionResult Estimate() - { - } - - public ActionResult Index () + [Authorize(Roles="Admin,Providers")] + public ActionResult Index() { + return View (); } } } diff --git a/web/Controllers/BlogsController.cs b/web/Controllers/BlogsController.cs index c32822fe..5cae3751 100644 --- a/web/Controllers/BlogsController.cs +++ b/web/Controllers/BlogsController.cs @@ -17,6 +17,7 @@ using Yavsc; using Yavsc.Model; using Yavsc.Model.Blogs; using Yavsc.ApiControllers; +using Yavsc.Model.RolesAndMembers; namespace Yavsc.Controllers { @@ -82,7 +83,9 @@ namespace Yavsc.Controllers if (u.UserName == user) sf |= FindBlogEntryFlags.MatchInvisible; BlogEntryCollection c = BlogManager.FindPost (user, sf, pageIndex, pageSize, out tr); - ViewData ["BlogTitle"] = BlogTitle (user); + Profile bupr = AccountController.GetProfile (user); + ViewData ["BlogUserProfile"] = bupr; + ViewData ["BlogTitle"] = bupr.BlogTitle; ViewData ["PageIndex"] = pageIndex; ViewData ["PageSize"] = pageSize; ViewData ["RecordCount"] = tr; @@ -109,16 +112,23 @@ namespace Yavsc.Controllers { if (e == null) return View ("TitleNotFound"); + Profile pr = AccountController.GetProfile (e.UserName); + if (pr==null) + return View ("TitleNotFound"); + ViewData ["BlogUserProfile"] = pr; + ViewData ["BlogTitle"] = pr.BlogTitle; MembershipUser u = Membership.GetUser (); if (u != null) ViewData ["UserName"] = u.UserName; - if (!e.Visible) { + if (!e.Visible || !pr.BlogVisible) { if (u==null) return View ("TitleNotFound"); - else if (u.UserName!=e.UserName) + else { + if (u.UserName!=e.UserName) + if (!Roles.IsUserInRole(u.UserName,"Admin")) return View ("TitleNotFound"); + } } - ViewData ["BlogTitle"] = BlogTitle (e.UserName); ViewData ["Comments"] = BlogManager.GetComments (e.Id); return View ("UserPost", e); } @@ -183,7 +193,9 @@ namespace Yavsc.Controllers { if (model != null) { string user = Membership.GetUser ().UserName; - ViewData ["BlogTitle"] = this.BlogTitle (user); + Profile pr = new Profile (HttpContext.Profile); + + ViewData ["BlogTitle"] = pr.BlogTitle; ViewData ["UserName"] = user; if (model.UserName == null) { model.UserName = user; @@ -202,10 +214,6 @@ namespace Yavsc.Controllers return View (model); } - private string BlogTitle (string user) - { - return string.Format ("{0}'s blog", user); - } [Authorize] public ActionResult Comment (BlogEditCommentModel model) { diff --git a/web/Controllers/FrontOfficeController.cs b/web/Controllers/FrontOfficeController.cs index 43b011d4..18f80182 100644 --- a/web/Controllers/FrontOfficeController.cs +++ b/web/Controllers/FrontOfficeController.cs @@ -14,6 +14,10 @@ using System.Web.Security; namespace Yavsc.Controllers { + /// + /// Front office controller. + /// Access granted to all + /// public class FrontOfficeController : Controller { [HttpGet] @@ -133,7 +137,7 @@ namespace Yavsc.Controllers Session["Basket"]=new List(); List basket = Session["Basket"] as List; // Add specified product command to the basket, - basket.Add(new Commande(collection)); + basket.Add(new Commande(0,0,collection)); return View (collection); } catch (Exception e) { ViewData ["Message"] = "Exception:"+e.Message; diff --git a/web/Views/Admin/AddRole.aspx b/web/Views/Admin/AddRole.aspx index a4a0003c..116deaab 100644 --- a/web/Views/Admin/AddRole.aspx +++ b/web/Views/Admin/AddRole.aspx @@ -2,8 +2,8 @@ <%= Html.ValidationSummary() %> -<% using(Html.BeginForm("DoAddRole")) %> -<% { %> +<% using(Html.BeginForm("DoAddRole")) + { %> Nom du rôle : <%= Html.TextBox( "RoleName" ) %> <%= Html.ValidationMessage("RoleName", "*") %>
diff --git a/web/Views/BackOffice/Estimate.aspx b/web/Views/BackOffice/Estimate.aspx deleted file mode 100644 index 611d7303..00000000 --- a/web/Views/BackOffice/Estimate.aspx +++ /dev/null @@ -1,12 +0,0 @@ -<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %> - - - - - - -
- -
- - diff --git a/web/Views/Blogs/UserPosts.aspx b/web/Views/Blogs/UserPosts.aspx index e0baa842..b090830e 100644 --- a/web/Views/Blogs/UserPosts.aspx +++ b/web/Views/Blogs/UserPosts.aspx @@ -1,7 +1,7 @@ <%@ Page Title="Billets utilisateurs" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master"%> <%@ Register Assembly="Yavsc.WebControls" TagPrefix="yavsc" Namespace="Yavsc.WebControls" %> -<% Title = ((string) ViewData["BlogTitle"])+" - "+YavscHelpers.SiteName ; %> +<% Title = ((string) ((Profile)ViewData["BlogUserProfile"]).BlogTitle)+" - "+YavscHelpers.SiteName ; %>

"> diff --git a/web/Views/FrontOffice/Estimate.aspx b/web/Views/FrontOffice/Estimate.aspx new file mode 100644 index 00000000..68ae7aec --- /dev/null +++ b/web/Views/FrontOffice/Estimate.aspx @@ -0,0 +1,19 @@ +<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %> + + +<% using (Html.BeginForm("Estimate")) { %> + +<% } %> + + + + + diff --git a/web/Web.csproj b/web/Web.csproj index 96e7d330..206c6c08 100644 --- a/web/Web.csproj +++ b/web/Web.csproj @@ -188,13 +188,13 @@ - + diff --git a/web/style.css b/web/style.css index 838b2204..3f859f05 100644 --- a/web/style.css +++ b/web/style.css @@ -78,7 +78,7 @@ label { font-size: small; } .blogpost { - background-color: rgba(32,32,32,0.3); + background-color: rgba(0,0,0,0.5); } .editblog { width: 95%; diff --git a/yavscModel/Blogs/BlogManager.cs b/yavscModel/Blogs/BlogManager.cs index 70184eb5..728ca29c 100644 --- a/yavscModel/Blogs/BlogManager.cs +++ b/yavscModel/Blogs/BlogManager.cs @@ -1,5 +1,7 @@ using System; using Yavsc.Model.Blogs; +using Yavsc.Model.RolesAndMembers; +using System.Web; namespace Yavsc.Model.Blogs diff --git a/yavscModel/RolesAndMemebers/Profile.cs b/yavscModel/RolesAndMemebers/Profile.cs index c9774ec4..9b65fa8f 100644 --- a/yavscModel/RolesAndMemebers/Profile.cs +++ b/yavscModel/RolesAndMemebers/Profile.cs @@ -33,7 +33,11 @@ namespace Yavsc.Model.RolesAndMembers [DisplayName("Titre du blog")] public string BlogTitle { get; set; } - public void FromProfileBase(ProfileBase profile) + public Profile():base() + { + } + + public Profile(ProfileBase profile) { object b = profile.GetPropertyValue ("BlogVisible"); BlogVisible = (b is DBNull) ? true : (bool)b; @@ -52,11 +56,9 @@ namespace Yavsc.Model.RolesAndMembers s = profile.GetPropertyValue("ZipCode"); ZipCode = (s is DBNull)?null:(string)s; - s = profile.GetPropertyValue ("WebSite"); WebSite = (s is DBNull) ? null : (string)s; - } } } diff --git a/yavscModel/WorkFlow/Commande.cs b/yavscModel/WorkFlow/Commande.cs index 4f6ea9bf..65bc9646 100644 --- a/yavscModel/WorkFlow/Commande.cs +++ b/yavscModel/WorkFlow/Commande.cs @@ -4,13 +4,17 @@ using SalesCatalog; using SalesCatalog.Model; using System.Collections.Specialized; + namespace Yavsc.Model.WorkFlow { public class Commande { - public Commande(NameValueCollection collection) + public DateTime CreationDate { get; set; } + long Id { get; set; } + public Commande(long catid, long pref, NameValueCollection collection) { - + CreationDate = DateTime.Now; + //TODO save it and get the id } } }