From 07be6f2928dc635f315ad8b3132214dc0aec0857 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 24 Sep 2014 16:19:23 +0200 Subject: [PATCH] * Tags and files for posts and writtings * TryAssert(Title ~ H1) --- WorkFlowProvider/NpgsqlContentProvider.cs | 49 +++++++++++++++++++---- WorkFlowProvider/WFManager.cs | 9 +++++ web/Controllers/BlogsApiController.cs | 13 ++++++ web/Controllers/WorkFlowController.cs | 18 ++++++++- web/Views/Blogs/Edit.aspx | 37 ++++++++--------- yavscModel/WorkFlow/Estimate.cs | 2 +- yavscModel/WorkFlow/IContentProvider.cs | 3 ++ yavscModel/WorkFlow/Writting.cs | 1 + 8 files changed, 102 insertions(+), 30 deletions(-) diff --git a/WorkFlowProvider/NpgsqlContentProvider.cs b/WorkFlowProvider/NpgsqlContentProvider.cs index 54238e22..aeb46154 100644 --- a/WorkFlowProvider/NpgsqlContentProvider.cs +++ b/WorkFlowProvider/NpgsqlContentProvider.cs @@ -12,9 +12,14 @@ namespace WorkFlowProvider { public class NpgsqlContentProvider: ProviderBase, IContentProvider { + public void TagWritting (long wrid, string tag) + { + throw new NotImplementedException (); + } + public bool[] FinalStatuses { get { - throw new NotImplementedException (); + return new bool[] { false, true, true }; } } @@ -35,23 +40,45 @@ namespace WorkFlowProvider public string[] StatusLabels { get { - throw new NotImplementedException (); + return new string[] { "Created", "Success", "Error" }; } } - #region IDisposable implementation - public void Dispose () + public void DropWritting (long wrid) { + using (NpgsqlConnection cnx = CreateConnection ()) { + using (NpgsqlCommand cmd = cnx.CreateCommand ()) { + cmd.CommandText = + "delete from writtings where _id = @wrid"; + + cmd.Parameters.Add ("@wrid", wrid); + cnx.Open (); + cmd.ExecuteNonQuery (); + } + } + } + + public void DropEstimate (long estid) + { + using (NpgsqlConnection cnx = CreateConnection ()) { + using (NpgsqlCommand cmd = cnx.CreateCommand ()) { + cmd.CommandText = + "delete from estimate where _id = @estid"; + + cmd.Parameters.Add ("@estid", estid); + cnx.Open (); + cmd.ExecuteNonQuery (); + } + } } - #endregion public Estimate GetEstimate (long estimid) { using (NpgsqlConnection cnx = CreateConnection ()) { using (NpgsqlCommand cmd = cnx.CreateCommand ()) { cmd.CommandText = - "select title,username from estimate where _id = @estid"; + "select _id,title,username from estimate where _id = @estid"; cmd.Parameters.Add ("@estid", estimid); cnx.Open (); @@ -66,6 +93,7 @@ namespace WorkFlowProvider rdr.GetOrdinal("title")); est.Owner = rdr.GetString( rdr.GetOrdinal("username")); + using (NpgsqlCommand cmdw = new NpgsqlCommand ("select _id, productid, ucost, count, description from writtings where _id = @estid", cnx)) { cmdw.Parameters.Add("@estid", estimid); using (NpgsqlDataReader rdrw = cmdw.ExecuteReader ()) { @@ -83,7 +111,7 @@ namespace WorkFlowProvider int ouc = rdrw.GetOrdinal ("ucost"); if (!rdrw.IsDBNull(ouc)) w.UnitaryCost = rdrw.GetDecimal (ouc); - // TODO get w.id + w.Id = rdrw.GetInt64 (rdrw.GetOrdinal("_id")); lw.Add (w); } est.Lines = lw.ToArray (); @@ -193,6 +221,13 @@ namespace WorkFlowProvider { return new NpgsqlConnection (cnxstr); } + #region IDisposable implementation + public void Dispose () + { + + } + #endregion + } } diff --git a/WorkFlowProvider/WFManager.cs b/WorkFlowProvider/WFManager.cs index 00dc5f6b..9bd5f482 100644 --- a/WorkFlowProvider/WFManager.cs +++ b/WorkFlowProvider/WFManager.cs @@ -8,6 +8,14 @@ namespace WorkFlowProvider { public static class WFManager { + public static void DropWritting (long wrid) + { + ContentProvider.DropWritting (wrid); + } + public static void DropEstimate (long estid) + { + ContentProvider.DropEstimate(estid); + } static IContentProvider contentProvider; public static IContentProvider ContentProvider { @@ -61,6 +69,7 @@ namespace WorkFlowProvider return ContentProvider.CreateEstimate (client, title); } + public static long Write(long estid, string desc, decimal ucost, int count, long productid) { return ContentProvider.Write(estid, desc, ucost, count, productid); diff --git a/web/Controllers/BlogsApiController.cs b/web/Controllers/BlogsApiController.cs index a9dab21a..e9c07f4e 100644 --- a/web/Controllers/BlogsApiController.cs +++ b/web/Controllers/BlogsApiController.cs @@ -12,6 +12,19 @@ namespace Yavsc.Controllers { public class BlogsApiController : Controller { + public void Tag (long postid,string tag) { + BlogEntry e = BlogManager.GetPost (postid); + if (!Roles.IsUserInRole ("Admin")) { + string rguser = Membership.GetUser ().UserName; + if (rguser != e.UserName) { + throw new AccessViolationException ( + string.Format ( + "Vous n'avez pas le droit de tagger des billets du Blog de {0}", + e.UserName)); + } + } + } + public static HttpStatusCodeResult RemovePost(string user, string title) { if (!Roles.IsUserInRole ("Admin")) { string rguser = Membership.GetUser ().UserName; diff --git a/web/Controllers/WorkFlowController.cs b/web/Controllers/WorkFlowController.cs index 780f8372..ee8cf240 100644 --- a/web/Controllers/WorkFlowController.cs +++ b/web/Controllers/WorkFlowController.cs @@ -21,13 +21,27 @@ namespace Yavsc.ApiControllers return WFManager.CreateEstimate ( Membership.GetUser().UserName,title); } + [HttpGet] + [Authorize] + public void DropWritting(long wrid) + { + WFManager.DropWritting (wrid); + } + + [HttpGet] + [Authorize] + public void DropEstimate(long estid) + { + WFManager.DropEstimate (estid); + } [HttpGet] [Authorize] public object Index() { - - return new { test="Hello World" }; + // TODO inform user on its roles and alerts + string username = Membership.GetUser ().UserName; + return new { test=string.Format("Hello {0}!",username) }; } [HttpGet] diff --git a/web/Views/Blogs/Edit.aspx b/web/Views/Blogs/Edit.aspx index da110bf5..4d4514d5 100644 --- a/web/Views/Blogs/Edit.aspx +++ b/web/Views/Blogs/Edit.aspx @@ -1,28 +1,25 @@ <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master"%> - - <%= Html.Encode(ViewData["BlogTitle"]) %> edition - - <%=Html.Encode(YavscHelpers.SiteName) %> - + +<% Title = Model.Title+" (édition) - "+ViewData["BlogTitle"]; %> - - -

- "> - " alt="from <%=ViewData["UserName"]%>"/> - <%= Html.Encode(ViewData["BlogTitle"]) %> - - <%= Html.Encode(Model.Title) %> - - Édition

- - + +

<%= Html.ActionLink(Model.Title,"UserPost",new{user=Model.UserName,title=Model.Title}) %> (édition) - + <%=ViewData["BlogTitle"]%> + + <%= YavscHelpers.SiteName %>

-
- <%= Html.Encode(ViewData["Message"]) %> -
+
(Id:<%=Model.Id%>, <%= Model.Posted.ToString("yyyy/MM/dd") %> + - <%= Model.Modified.ToString("yyyy/MM/dd") %> <%= Model.Visible? "":", Invisible!" %>) +<% if (Membership.GetUser()!=null) + if (Membership.GetUser().UserName==Model.UserName) + { %> + <%= Html.ActionLink("Editer","Edit", new { user=Model.UserName, title = Model.Title }, new { @class="actionlink" }) %> + <%= Html.ActionLink("Supprimer","RemovePost", new { user=Model.UserName, title = Model.Title }, new { @class="actionlink" } ) %> + <% } %> +
- - -<% if (Model != null ) if (Model.Content != null ) { + <% if (Model != null ) if (Model.Content != null ) { BBCodeHelper.Init (); %> <%= Html.ActionLink(Model.Title,"UserPost",new{user=Model.UserName,title=Model.Title}) %>
diff --git a/yavscModel/WorkFlow/Estimate.cs b/yavscModel/WorkFlow/Estimate.cs index c6402934..c437a9ca 100644 --- a/yavscModel/WorkFlow/Estimate.cs +++ b/yavscModel/WorkFlow/Estimate.cs @@ -9,7 +9,7 @@ namespace yavscModel.WorkFlow } public string Title { get; set; } public string Owner { get; set; } - + public long Id { get; set; } public decimal Ciffer { get { decimal total = 0; diff --git a/yavscModel/WorkFlow/IContentProvider.cs b/yavscModel/WorkFlow/IContentProvider.cs index ad51ebd8..c881304f 100644 --- a/yavscModel/WorkFlow/IContentProvider.cs +++ b/yavscModel/WorkFlow/IContentProvider.cs @@ -6,6 +6,9 @@ namespace yavscModel.WorkFlow { public interface IContentProvider : IProvider, IDisposable { + void DropWritting (long wrid); + void DropEstimate (long estid); + void TagWritting (long wrid,string tag); int GetStatus (string estimId); /// /// Gets the status labels. diff --git a/yavscModel/WorkFlow/Writting.cs b/yavscModel/WorkFlow/Writting.cs index 2321a138..ac5a7864 100644 --- a/yavscModel/WorkFlow/Writting.cs +++ b/yavscModel/WorkFlow/Writting.cs @@ -4,6 +4,7 @@ namespace yavscModel.WorkFlow { public class Writting { + public long Id { get; set; } public decimal UnitaryCost { get; set; } public int Count { get; set; } public long ProductReference { get; set; }