* Tags and files for posts and writtings

* TryAssert(Title ~ H1)
vnext
Paul Schneider 10 years ago
parent 4c6fbd29a5
commit 07be6f2928
8 changed files with 102 additions and 30 deletions

@ -12,9 +12,14 @@ namespace WorkFlowProvider
{ {
public class NpgsqlContentProvider: ProviderBase, IContentProvider public class NpgsqlContentProvider: ProviderBase, IContentProvider
{ {
public void TagWritting (long wrid, string tag)
{
throw new NotImplementedException ();
}
public bool[] FinalStatuses { public bool[] FinalStatuses {
get { get {
throw new NotImplementedException (); return new bool[] { false, true, true };
} }
} }
@ -35,23 +40,45 @@ namespace WorkFlowProvider
public string[] StatusLabels { public string[] StatusLabels {
get { get {
throw new NotImplementedException (); return new string[] { "Created", "Success", "Error" };
} }
} }
#region IDisposable implementation public void DropWritting (long wrid)
public void Dispose ()
{ {
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) public Estimate GetEstimate (long estimid)
{ {
using (NpgsqlConnection cnx = CreateConnection ()) { using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) { using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText = cmd.CommandText =
"select title,username from estimate where _id = @estid"; "select _id,title,username from estimate where _id = @estid";
cmd.Parameters.Add ("@estid", estimid); cmd.Parameters.Add ("@estid", estimid);
cnx.Open (); cnx.Open ();
@ -66,6 +93,7 @@ namespace WorkFlowProvider
rdr.GetOrdinal("title")); rdr.GetOrdinal("title"));
est.Owner = rdr.GetString( est.Owner = rdr.GetString(
rdr.GetOrdinal("username")); rdr.GetOrdinal("username"));
using (NpgsqlCommand cmdw = new NpgsqlCommand ("select _id, productid, ucost, count, description from writtings where _id = @estid", cnx)) { using (NpgsqlCommand cmdw = new NpgsqlCommand ("select _id, productid, ucost, count, description from writtings where _id = @estid", cnx)) {
cmdw.Parameters.Add("@estid", estimid); cmdw.Parameters.Add("@estid", estimid);
using (NpgsqlDataReader rdrw = cmdw.ExecuteReader ()) { using (NpgsqlDataReader rdrw = cmdw.ExecuteReader ()) {
@ -83,7 +111,7 @@ namespace WorkFlowProvider
int ouc = rdrw.GetOrdinal ("ucost"); int ouc = rdrw.GetOrdinal ("ucost");
if (!rdrw.IsDBNull(ouc)) if (!rdrw.IsDBNull(ouc))
w.UnitaryCost = rdrw.GetDecimal (ouc); w.UnitaryCost = rdrw.GetDecimal (ouc);
// TODO get w.id w.Id = rdrw.GetInt64 (rdrw.GetOrdinal("_id"));
lw.Add (w); lw.Add (w);
} }
est.Lines = lw.ToArray (); est.Lines = lw.ToArray ();
@ -193,6 +221,13 @@ namespace WorkFlowProvider
{ {
return new NpgsqlConnection (cnxstr); return new NpgsqlConnection (cnxstr);
} }
#region IDisposable implementation
public void Dispose ()
{
}
#endregion
} }
} }

@ -8,6 +8,14 @@ namespace WorkFlowProvider
{ {
public static class WFManager 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; static IContentProvider contentProvider;
public static IContentProvider ContentProvider { public static IContentProvider ContentProvider {
@ -61,6 +69,7 @@ namespace WorkFlowProvider
return ContentProvider.CreateEstimate (client, title); return ContentProvider.CreateEstimate (client, title);
} }
public static long Write(long estid, string desc, decimal ucost, int count, long productid) public static long Write(long estid, string desc, decimal ucost, int count, long productid)
{ {
return ContentProvider.Write(estid, desc, ucost, count, productid); return ContentProvider.Write(estid, desc, ucost, count, productid);

@ -12,6 +12,19 @@ namespace Yavsc.Controllers
{ {
public class BlogsApiController : Controller 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) { public static HttpStatusCodeResult RemovePost(string user, string title) {
if (!Roles.IsUserInRole ("Admin")) { if (!Roles.IsUserInRole ("Admin")) {
string rguser = Membership.GetUser ().UserName; string rguser = Membership.GetUser ().UserName;

@ -21,13 +21,27 @@ namespace Yavsc.ApiControllers
return WFManager.CreateEstimate ( return WFManager.CreateEstimate (
Membership.GetUser().UserName,title); 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] [HttpGet]
[Authorize] [Authorize]
public object Index() public object Index()
{ {
// TODO inform user on its roles and alerts
return new { test="Hello World" }; string username = Membership.GetUser ().UserName;
return new { test=string.Format("Hello {0}!",username) };
} }
[HttpGet] [HttpGet]

@ -1,28 +1,25 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogEditEntryModel>" MasterPageFile="~/Models/App.master"%> <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogEditEntryModel>" MasterPageFile="~/Models/App.master"%>
<asp:Content ContentPlaceHolderID="head" ID="head" runat="server"> <asp:Content ContentPlaceHolderID="init" ID="init1" runat="server">
<title><%= Html.Encode(ViewData["BlogTitle"]) %> edition <% Title = Model.Title+" (édition) - "+ViewData["BlogTitle"]; %>
- <%=Html.Encode(YavscHelpers.SiteName) %>
</title>
</asp:Content> </asp:Content>
<asp:Content ContentPlaceHolderID="header" ID="headerContent" runat="server"> <asp:Content ContentPlaceHolderID="overHeaderOne" ID="header1" runat="server">
<h1 class="blogtitle"><%= Html.ActionLink(Model.Title,"UserPost",new{user=Model.UserName,title=Model.Title}) %> (édition) -
<a href="/Blog/<%=Model.UserName%>"><img class="avatar" src="/Blogs/Avatar?user=<%=Model.UserName%>" alt=""/> <%=ViewData["BlogTitle"]%></a>
<asp:Literal runat="server" Text=" - " />
<a href="/"> <%= YavscHelpers.SiteName %> </a> </h1>
<h1 class="blogtitle"> <div class="metablog">(Id:<a href="/Blogs/UserPost/<%=Model.Id%>"><i><%=Model.Id%></i></a>, <%= Model.Posted.ToString("yyyy/MM/dd") %>
<a href="/Blog/<%=ViewData["UserName"]%>"> - <%= Model.Modified.ToString("yyyy/MM/dd") %> <%= Model.Visible? "":", Invisible!" %>)
<img class="avatar" src="/Blogs/Avatar?user=<%=ViewData["UserName"]%>" alt="from <%=ViewData["UserName"]%>"/> <% if (Membership.GetUser()!=null)
<%= Html.Encode(ViewData["BlogTitle"]) %> </a> - if (Membership.GetUser().UserName==Model.UserName)
<%= Html.Encode(Model.Title) %> - { %>
&Eacute;dition </h1> <%= 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" } ) %>
<% } %>
</div>
<div class="message">
<%= Html.Encode(ViewData["Message"]) %>
</div>
</asp:Content> </asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server"> <asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
<% if (Model != null ) if (Model.Content != null ) {
<% if (Model != null ) if (Model.Content != null ) {
BBCodeHelper.Init (); %> BBCodeHelper.Init (); %>
<%= Html.ActionLink(Model.Title,"UserPost",new{user=Model.UserName,title=Model.Title}) %> <%= Html.ActionLink(Model.Title,"UserPost",new{user=Model.UserName,title=Model.Title}) %>
<div class="blogpost"> <div class="blogpost">

@ -9,7 +9,7 @@ namespace yavscModel.WorkFlow
} }
public string Title { get; set; } public string Title { get; set; }
public string Owner { get; set; } public string Owner { get; set; }
public long Id { get; set; }
public decimal Ciffer { public decimal Ciffer {
get { get {
decimal total = 0; decimal total = 0;

@ -6,6 +6,9 @@ namespace yavscModel.WorkFlow
{ {
public interface IContentProvider : IProvider, IDisposable public interface IContentProvider : IProvider, IDisposable
{ {
void DropWritting (long wrid);
void DropEstimate (long estid);
void TagWritting (long wrid,string tag);
int GetStatus (string estimId); int GetStatus (string estimId);
/// <summary> /// <summary>
/// Gets the status labels. /// Gets the status labels.

@ -4,6 +4,7 @@ namespace yavscModel.WorkFlow
{ {
public class Writting public class Writting
{ {
public long Id { get; set; }
public decimal UnitaryCost { get; set; } public decimal UnitaryCost { get; set; }
public int Count { get; set; } public int Count { get; set; }
public long ProductReference { get; set; } public long ProductReference { get; set; }

Loading…