From 721b11eba316ad52b173c7e9ce54c4a51324390c Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 4 Mar 2015 14:41:35 +0100 Subject: [PATCH] Google date quey, refactiring, docpage * Yavsc.sln: * Web.csproj: * YavscModel.csproj: * OtherWebException.cs: * ProjectInfo.cs: * IValueProvider.cs: * CalendarApi.cs: * HomeController.cs: * TemplateException.cs: * WorkFlowController.cs: * NpgsqlWorkflow.csproj: * GoogleErrorMessage.cs: * ITCPNpgsqlProvider.cs: * NpgsqlContentProvider.cs: * ITContentProvider.csproj: * FrontOfficeApiController.cs: * NpgsqlContentProvider.csproj: refactoring * App.master: * WebApiConfig.cs: New Web api configuration architecture * SalesCatalog.csproj: * XmlCatalogProvider.cs: using MVC to get the catalog xml filename * WorkFlowManager.cs: * FrontOfficeController.cs: * CatalogManager.cs: No more extra argument to get the catalog * DateQuery.aspx: * AskForADate.cs: * GoogleController.cs: Google Date new query model * style.css: * BBCodeHelper.cs: Doc page responsive design * Service.cs: * SetPrice.cs: xml doc * WebApiConfig.cs: refactioring --- ITContentProvider/ITCPNpgsqlProvider.cs | 2 +- ITContentProvider/ITContentProvider.csproj | 4 +-- ITContentProvider/ProjectInfo.cs | 2 +- SalesCatalog/SalesCatalog.csproj | 1 + .../XmlImplementation/XmlCatalogProvider.cs | 9 ++--- WorkFlowProvider/NpgsqlContentProvider.cs | 2 +- ...ow.csproj => NpgsqlContentProvider.csproj} | 0 Yavsc.sln | 2 +- web/Controllers/FrontOfficeApiController.cs | 20 +++++------ web/Controllers/FrontOfficeController.cs | 13 +++---- web/Controllers/GoogleController.cs | 23 +++++-------- web/Controllers/HomeController.cs | 2 +- web/Controllers/IValueProvider.cs | 2 +- web/Controllers/TemplateException.cs | 2 +- web/{ => Controllers}/WebApiConfig.cs | 4 +-- web/Controllers/WorkFlowController.cs | 2 +- web/Helpers/BBCodeHelper.cs | 22 ++++++++++-- web/Helpers/Google/CalendarApi.cs | 3 +- web/Models/App.master | 8 ++++- web/Theme/style.css | 29 +++++++++++----- web/Views/Google/DateQuery.aspx | 8 ----- web/Web.csproj | 6 ++-- .../FrontOffice/Catalog/Billing/SetPrice.cs | 2 +- .../FrontOffice/Catalog/CatalogManager.cs | 7 ++-- yavscModel/FrontOffice/Catalog/Service.cs | 5 +++ yavscModel/Google/AskForADate.cs | 34 +++++++------------ ...leErrorMessage.cs => OtherWebException.cs} | 10 +++--- yavscModel/WorkFlow/WorkFlowManager.cs | 2 +- yavscModel/YavscModel.csproj | 2 +- 29 files changed, 124 insertions(+), 104 deletions(-) rename WorkFlowProvider/{NpgsqlWorkflow.csproj => NpgsqlContentProvider.csproj} (100%) rename web/{ => Controllers}/WebApiConfig.cs (92%) rename yavscModel/{Google/GoogleErrorMessage.cs => OtherWebException.cs} (90%) diff --git a/ITContentProvider/ITCPNpgsqlProvider.cs b/ITContentProvider/ITCPNpgsqlProvider.cs index b17a8f0c..4c3dd948 100644 --- a/ITContentProvider/ITCPNpgsqlProvider.cs +++ b/ITContentProvider/ITCPNpgsqlProvider.cs @@ -1,5 +1,5 @@ using System; -using WorkFlowProvider; +using Yavsc; using Npgsql; namespace ITContentProvider diff --git a/ITContentProvider/ITContentProvider.csproj b/ITContentProvider/ITContentProvider.csproj index 8bdb3ff1..58f769dd 100644 --- a/ITContentProvider/ITContentProvider.csproj +++ b/ITContentProvider/ITContentProvider.csproj @@ -49,9 +49,9 @@ {68F5B80A-616E-4C3C-91A0-828AA40000BD} YavscModel - + {821FF72D-9F4B-4A2C-B95C-7B965291F119} - NpgsqlWorkflow + NpgsqlContentProvider diff --git a/ITContentProvider/ProjectInfo.cs b/ITContentProvider/ProjectInfo.cs index 63a3c23c..18b9f0d5 100644 --- a/ITContentProvider/ProjectInfo.cs +++ b/ITContentProvider/ProjectInfo.cs @@ -1,5 +1,5 @@ using System; -using WorkFlowProvider; +using Yavsc; namespace ITContentProvider { diff --git a/SalesCatalog/SalesCatalog.csproj b/SalesCatalog/SalesCatalog.csproj index fd0803e2..7301987f 100644 --- a/SalesCatalog/SalesCatalog.csproj +++ b/SalesCatalog/SalesCatalog.csproj @@ -36,6 +36,7 @@ + diff --git a/SalesCatalog/XmlImplementation/XmlCatalogProvider.cs b/SalesCatalog/XmlImplementation/XmlCatalogProvider.cs index 989a7c58..99cc3531 100644 --- a/SalesCatalog/XmlImplementation/XmlCatalogProvider.cs +++ b/SalesCatalog/XmlImplementation/XmlCatalogProvider.cs @@ -15,6 +15,7 @@ namespace SalesCatalog.XmlImplementation /// public class XmlCatalogProvider: CatalogProvider { + #region implemented abstract members of SalesCatalog.CatalogProvider /// /// Gets the catalog, loading it from @@ -60,12 +61,8 @@ namespace SalesCatalog.XmlImplementation if (config ["connection"] == null) throw new Exception ("the 'connection' parameter is null " + "(it should be the absolute path to the xml catalog)"); - // config ["connection"] starts with "~/" - fileName = (string) config ["connection"]; - if (fileName.StartsWith ("~/")) { - fileName = HttpContext.Current.Server.MapPath( - config ["connection"]); - } + string cnx = (string) config ["connection"]; + fileName = HttpContext.Current.Server.MapPath(cnx); LoadCatalog (); } diff --git a/WorkFlowProvider/NpgsqlContentProvider.cs b/WorkFlowProvider/NpgsqlContentProvider.cs index 16427d33..c091ef3e 100644 --- a/WorkFlowProvider/NpgsqlContentProvider.cs +++ b/WorkFlowProvider/NpgsqlContentProvider.cs @@ -13,7 +13,7 @@ using System.IO; using System.Text; using Newtonsoft.Json; -namespace WorkFlowProvider +namespace Yavsc { /// /// Npgsql content provider. diff --git a/WorkFlowProvider/NpgsqlWorkflow.csproj b/WorkFlowProvider/NpgsqlContentProvider.csproj similarity index 100% rename from WorkFlowProvider/NpgsqlWorkflow.csproj rename to WorkFlowProvider/NpgsqlContentProvider.csproj diff --git a/Yavsc.sln b/Yavsc.sln index 1947183f..29f6a00c 100644 --- a/Yavsc.sln +++ b/Yavsc.sln @@ -11,7 +11,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SalesCatalog", "SalesCatalo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YavscModel", "yavscModel\YavscModel.csproj", "{68F5B80A-616E-4C3C-91A0-828AA40000BD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NpgsqlWorkflow", "WorkFlowProvider\NpgsqlWorkflow.csproj", "{821FF72D-9F4B-4A2C-B95C-7B965291F119}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NpgsqlContentProvider", "WorkFlowProvider\NpgsqlContentProvider.csproj", "{821FF72D-9F4B-4A2C-B95C-7B965291F119}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YavscClient", "yavscclient\YavscClient.csproj", "{EEFCECE6-3B7F-4BBE-B7AF-69377AF3CF39}" EndProject diff --git a/web/Controllers/FrontOfficeApiController.cs b/web/Controllers/FrontOfficeApiController.cs index 72b78246..ef4d6673 100644 --- a/web/Controllers/FrontOfficeApiController.cs +++ b/web/Controllers/FrontOfficeApiController.cs @@ -10,7 +10,7 @@ using System.Web; using System.Linq; using System.IO; using System.Net; -using WorkFlowProvider; +using Yavsc; using System.Web.Security; using Yavsc.Model.WorkFlow; using System.Reflection; @@ -52,7 +52,7 @@ namespace Yavsc.ApiControllers [AcceptVerbs ("GET")] public Catalog Catalog () { - Catalog c = CatalogManager.GetCatalog (Request.RequestUri.AbsolutePath); + Catalog c = CatalogManager.GetCatalog (); return c; } @@ -65,19 +65,19 @@ namespace Yavsc.ApiControllers [AcceptVerbs ("GET")] public ProductCategory GetProductCategorie (string brandName, string prodCategorie) { - return CatalogManager.GetCatalog (Request.RequestUri.AbsolutePath).GetBrand (brandName).GetProductCategory (prodCategorie); + return CatalogManager.GetCatalog ().GetBrand (brandName).GetProductCategory (prodCategorie); } /// /// Gets the estimate. /// /// The estimate. - /// Estimate Id. + /// Estimate Id. [Authorize] [HttpGet] - public Estimate GetEstimate (long Id) + public Estimate GetEstimate (long id) { - Estimate est = wfmgr.ContentProvider.GetEstimate (Id); + Estimate est = wfmgr.ContentProvider.GetEstimate (id); return est; } @@ -87,13 +87,13 @@ namespace Yavsc.ApiControllers /// Gets the estim tex. /// /// The estim tex. - /// Estimid. + /// Estimate id. [AcceptVerbs ("GET")] - public HttpResponseMessage EstimateToTex (long estimid) + public HttpResponseMessage EstimateToTex (long id) { string texest = null; try { - texest = estimateToTex (estimid); + texest = estimateToTex (id); } catch (TemplateException ex) { return new HttpResponseMessage (HttpStatusCode.OK) { Content = new ObjectContent (typeof(string), @@ -110,7 +110,7 @@ namespace Yavsc.ApiControllers } if (texest == null) return new HttpResponseMessage (HttpStatusCode.OK) { Content = - new ObjectContent (typeof(string), "Not an estimation id:" + estimid, + new ObjectContent (typeof(string), "Not an estimation id:" + id, new ErrorHtmlFormatter (HttpStatusCode.NotFound, LocalizedText.Estimate_not_found)) }; diff --git a/web/Controllers/FrontOfficeController.cs b/web/Controllers/FrontOfficeController.cs index a780bb46..e84ecb09 100644 --- a/web/Controllers/FrontOfficeController.cs +++ b/web/Controllers/FrontOfficeController.cs @@ -8,7 +8,7 @@ using Yavsc.Controllers; using System.Collections.Generic; using Yavsc.Model; using Yavsc.Model.WorkFlow; -using WorkFlowProvider; +using Yavsc; using System.Web.Security; using System.Threading; using Yavsc.Model.FrontOffice; @@ -64,7 +64,8 @@ namespace Yavsc.Controllers [Authorize] public ActionResult Estimate (Estimate model, string submit) { - ViewData ["WebApiBase"] = "http://" + Request.Url.Authority + "/api"; + // Obsolete, set in master page + ViewData ["WebApiBase"] = "http://" + Request.Url.Authority + "/api"; ViewData ["WABASEWF"] = ViewData ["WebApiBase"] + "/WorkFlow"; if (submit == null) { if (model.Id > 0) { @@ -112,7 +113,7 @@ namespace Yavsc.Controllers public ActionResult Catalog () { return View ( - CatalogManager.GetCatalog (Request.Url.AbsolutePath) + CatalogManager.GetCatalog () ); } @@ -122,7 +123,7 @@ namespace Yavsc.Controllers [AcceptVerbs ("GET")] public ActionResult Brand (string id) { - Catalog c = CatalogManager.GetCatalog (Request.Url.AbsolutePath); + Catalog c = CatalogManager.GetCatalog (); ViewData ["BrandName"] = id; return View (c.GetBrand (id)); } @@ -139,7 +140,7 @@ namespace Yavsc.Controllers ViewData ["BrandId"] = brandid; ViewData ["ProductCategoryId"] = pcid; return View ( - CatalogManager.GetCatalog (Request.Url.AbsolutePath).GetBrand (brandid).GetProductCategory (pcid) + CatalogManager.GetCatalog ().GetBrand (brandid).GetProductCategory (pcid) ); } @@ -156,7 +157,7 @@ namespace Yavsc.Controllers ViewData ["BrandName"] = id; ViewData ["ProdCatRef"] = pc; ViewData ["ProdRef"] = pref; - Catalog cat = CatalogManager.GetCatalog (Request.Url.AbsolutePath); + Catalog cat = CatalogManager.GetCatalog (); if (cat == null) { ViewData ["Message"] = "Catalog introuvable"; ViewData ["RefType"] = "Catalog"; diff --git a/web/Controllers/GoogleController.cs b/web/Controllers/GoogleController.cs index c1969777..9ce50c5b 100644 --- a/web/Controllers/GoogleController.cs +++ b/web/Controllers/GoogleController.cs @@ -288,14 +288,13 @@ namespace Yavsc.Controllers public ActionResult DateQuery (AskForADate model) { if (ModelState.IsValid) { - if (model.MinDate < DateTime.Now) { - ModelState.AddModelError ("MinTime", "This first date must be in the future."); - return View (model); - } - if (model.MinDate > model.MaxDate) { - ModelState.AddModelError ("MinTime", "This first date must be lower than the second one."); - return View (model); - } + + DateTime mindate = DateTime.Now; + if (model.PreferedDate < mindate) + model.PreferedDate = mindate; + if (model.MaxDate < mindate) + model.MaxDate = mindate.AddYears (1); + var muc = Membership.FindUsersByName (model.UserName); if (muc.Count == 0) { ModelState.AddModelError ("UserName", "Non existent user"); @@ -309,22 +308,18 @@ namespace Yavsc.Controllers return View (model); } - DateTime mindate = model.MinDate; - mindate = mindate.AddHours (int.Parse (model.MinTime.Substring (0, 2))); - mindate = mindate.AddMinutes (int.Parse (model.MinTime.Substring (3, 2))); DateTime maxdate = model.MaxDate; - maxdate = maxdate.AddHours (int.Parse (model.MaxTime.Substring (0, 2))); - maxdate = maxdate.AddMinutes (int.Parse (model.MaxTime.Substring (3, 2))); CalendarApi c = new CalendarApi (); CalendarEntryList res; try { res = c.GetCalendar (calid, mindate, maxdate, upr); - } catch (GoogleErrorException ex) { + } catch (OtherWebException ex) { ViewData ["Title"] = ex.Title; ViewData ["Content"] = ex.Content; return View ("GoogleErrorMessage", ex); } + return View (res); } return View (model); diff --git a/web/Controllers/HomeController.cs b/web/Controllers/HomeController.cs index 2a2c7f58..4fdc85ca 100644 --- a/web/Controllers/HomeController.cs +++ b/web/Controllers/HomeController.cs @@ -13,7 +13,7 @@ using System.Resources; using Yavsc.Model; using Npgsql.Web; using ITContentProvider; -using WorkFlowProvider; +using Yavsc; using Npgsql.Web.Blog; namespace Yavsc.Controllers diff --git a/web/Controllers/IValueProvider.cs b/web/Controllers/IValueProvider.cs index accea934..99a58d8d 100644 --- a/web/Controllers/IValueProvider.cs +++ b/web/Controllers/IValueProvider.cs @@ -10,7 +10,7 @@ using System.Web; using System.Linq; using System.IO; using System.Net; -using WorkFlowProvider; +using Yavsc; using System.Web.Security; using Yavsc.Model.WorkFlow; using System.Reflection; diff --git a/web/Controllers/TemplateException.cs b/web/Controllers/TemplateException.cs index 2d6b530d..61152d43 100644 --- a/web/Controllers/TemplateException.cs +++ b/web/Controllers/TemplateException.cs @@ -10,7 +10,7 @@ using System.Web; using System.Linq; using System.IO; using System.Net; -using WorkFlowProvider; +using Yavsc; using System.Web.Security; using Yavsc.Model.WorkFlow; using System.Reflection; diff --git a/web/WebApiConfig.cs b/web/Controllers/WebApiConfig.cs similarity index 92% rename from web/WebApiConfig.cs rename to web/Controllers/WebApiConfig.cs index 0cef4818..1f01b584 100644 --- a/web/WebApiConfig.cs +++ b/web/Controllers/WebApiConfig.cs @@ -57,8 +57,8 @@ namespace Yavsc { config.Routes.MapHttpRoute( name: "DefaultApi", - routeTemplate: WebApiConfig.UrlPrefix + "/{controller}/{id}", - defaults: new { id = RouteParameter.Optional } + routeTemplate: WebApiConfig.UrlPrefix + "/{controller}/{action}/{id}", + defaults: new { action="Index", id = RouteParameter.Optional } ); } } diff --git a/web/Controllers/WorkFlowController.cs b/web/Controllers/WorkFlowController.cs index ed26a126..87e3e5bf 100644 --- a/web/Controllers/WorkFlowController.cs +++ b/web/Controllers/WorkFlowController.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Net.Http; using System.Web; using System.Web.Security; -using WorkFlowProvider; +using Yavsc; using Yavsc.Model.WorkFlow; using System.Web.Http; using System.Web.Http.Controllers; diff --git a/web/Helpers/BBCodeHelper.cs b/web/Helpers/BBCodeHelper.cs index 585b5df8..85dc2d6b 100644 --- a/web/Helpers/BBCodeHelper.cs +++ b/web/Helpers/BBCodeHelper.cs @@ -55,8 +55,13 @@ namespace Yavsc.Helpers tib.AddCssClass (BBCodeCaseClass); string temp = tagUsage (t); - tib.InnerHtml = temp; - u.Add (string.Format ("{0}
{1}
", tib.ToString (), Parser.ToHtml (temp),BBCodeViewClass)); + tib.InnerHtml = string.Format("[{0}]",t.Name); + u.Add (string.Format ( + "{0}
{3}{1}
", + tib.ToString (), + Parser.ToHtml (temp), + BBCodeViewClass, + temp)); } @@ -65,6 +70,7 @@ namespace Yavsc.Helpers } + static string tagUsage(BBTag t,string content=null) { StringBuilder sb = new StringBuilder (); @@ -200,6 +206,13 @@ namespace Yavsc.Helpers static string TocContentTransformer (string instr) { + + StringBuilder header = new StringBuilder (); + TagBuilder bshd = new TagBuilder("div"); + bshd.AddCssClass ("bshd"); + + header.AppendFormat ("\"[Show/Hide\n", + "/Theme/dark/rect.png"); StringBuilder ttb = new StringBuilder (); int m1=0, m2=0, m3=0; foreach (string key in d.Keys) { @@ -254,7 +267,10 @@ namespace Yavsc.Helpers } TagBuilder aside = new TagBuilder ("aside"); aside.InnerHtml = ttb.ToString (); - return aside.ToString(); + aside.AddCssClass ("bshpanel"); + bshd.InnerHtml = header.ToString()+aside.ToString(); + + return bshd.ToString (); } static string DocPageContentTransformer (string instr) diff --git a/web/Helpers/Google/CalendarApi.cs b/web/Helpers/Google/CalendarApi.cs index b0fea70e..7566ae99 100644 --- a/web/Helpers/Google/CalendarApi.cs +++ b/web/Helpers/Google/CalendarApi.cs @@ -29,6 +29,7 @@ using System.Text; using Newtonsoft.Json; using System.Web; using System.Runtime.Serialization.Json; +using Yavsc.Model; namespace Yavsc.Helpers.Google { @@ -116,7 +117,7 @@ namespace Yavsc.Helpers.Google } } catch (WebException ex) { webreq.Abort (); - throw new GoogleErrorException (ex); + throw new OtherWebException (ex); } webreq.Abort (); return res; diff --git a/web/Models/App.master b/web/Models/App.master index 71e73312..afb1863f 100644 --- a/web/Models/App.master +++ b/web/Models/App.master @@ -23,6 +23,7 @@ "><%= YavscHelpers.SiteName %> + <% if (ViewData["Error"]!=null) { %>
@@ -34,6 +35,7 @@ <%= Html.Encode(ViewData["Message"]) %>
<% } %> +
@@ -43,9 +45,13 @@
+ + +