vnext
Paul Schneider 10 years ago
parent 83ac08cfd4
commit 1606fd0871
17 changed files with 136 additions and 90 deletions

@ -138,22 +138,21 @@ namespace WorkFlowProvider
using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText =
"select _id,title,username from estimate where _id = @estid";
"select title,username from estimate where _id = @estid";
cmd.Parameters.Add ("@estid", estimid);
cnx.Open ();
Estimate est = null;
using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) {
if (!rdr.Read ()) {
throw new Exception (
string.Format("Estimate not found : {0}", estimid));
return null;
}
est = new Estimate ();
est.Title = rdr.GetString(
rdr.GetOrdinal("title"));
est.Owner = rdr.GetString(
rdr.GetOrdinal("username"));
est.Id = estimid;
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 ()) {

@ -18,11 +18,16 @@ namespace Yavsc.Admin
{
Environment.SetEnvironmentVariable("PGPASSWORD", da.Password);
Export e = new Export ();
string fileName = da.BackupPrefix + "-" + DateTime.Now.ToString ("yyyyMMdd");
string fileName = da.BackupPrefix + "-" + DateTime.Now.ToString ("yyyyMMddhhmmss")+".tar";
FileInfo ofi = new FileInfo (fileName);
e.FileName = ofi.FullName;
/*
Exec ("pg_dump", string.Format (
"-wb -Z3 -f {0} -Fd -h {1} -U {2} -p {3} {4}",
"-wb -Z3 -f {0} -Ft -h {1} -U {2} -p {3} {4}",
fileName, da.Host, da.Dbuser, da.Port, da.Dbname ),e);
*/
Exec ("pg_dump", string.Format (
"-f {0} -Ft -h {1} -U {2} -p {3} {4}",
fileName, da.Host, da.Dbuser, da.Port, da.Dbname ),e);
return e;
}
@ -50,9 +55,14 @@ namespace Yavsc.Admin
{
Environment.SetEnvironmentVariable("PGPASSWORD", da.Password);
var t = new TaskOutput ();
Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format (
"-1 -Ft -O -h {0} -U {1} -p {2} -d {3} {4}",
da.Host, da.Dbuser, da.Port, da.Dbname, fileName ),t);
/*
Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format (
"-1 -w -Fd -O -h {0} -U {1} -p {2} -d {3} {4}",
da.Host, da.Dbuser, da.Port, da.Dbname, fileName ),t);
*/
return t;
}
public TaskOutput CreateDb ()

@ -8,6 +8,7 @@ using System.Web.Security;
using Yavsc.Model.RolesAndMembers;
using Yavsc.Model.Admin;
using Yavsc.Admin;
using System.IO;
namespace Yavsc.Controllers
@ -27,6 +28,7 @@ namespace Yavsc.Controllers
[Authorize(Roles="Admin")]
public ActionResult Backups(DataAccess model)
{
return View (model);
}
@ -37,6 +39,7 @@ namespace Yavsc.Controllers
if (ModelState.IsValid) {
if (string.IsNullOrEmpty (datac.Password))
ModelState.AddModelError ("Password", "Invalid passord");
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
DataManager ex = new DataManager (datac);
Export e = ex.CreateBackup ();
if (e.ExitCode > 0)
@ -65,14 +68,30 @@ namespace Yavsc.Controllers
{
ViewData ["BackupName"] = backupName;
if (ModelState.IsValid) {
// TODO BETTER
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
DataManager mgr = new DataManager (datac);
ViewData ["BackupName"] = backupName;
ViewData ["DataOnly"] = dataOnly;
TaskOutput t = mgr.Restore (backupName,dataOnly);
TaskOutput t = mgr.Restore (
Path.Combine(new FileInfo(datac.BackupPrefix).DirectoryName,
backupName),dataOnly);
return View ("Restored", t);
}
BuildBackupList (datac);
return View (datac);
}
private void BuildBackupList(DataAccess datac)
{
// build ViewData ["Backups"];
string bckd=Server.MapPath (datac.BackupPrefix);
DirectoryInfo di = new DirectoryInfo (new FileInfo(bckd).DirectoryName);
List<string> bks = new List<string> ();
foreach (FileInfo ti in di.GetFiles("*.tar"))
bks.Add (ti.Name);
ViewData ["Backups"] = bks.ToArray ();
}
[Authorize(Roles="Admin")]
public ActionResult RemoveFromRole(string username, string rolename, string returnUrl)

@ -20,19 +20,37 @@ namespace Yavsc.Controllers
/// </summary>
public class FrontOfficeController : Controller
{
[HttpGet]
[HttpPost]
public ActionResult Estimate(Estimate e)
[Authorize]
public ActionResult Estimate(Estimate model,string submit)
{
if (ModelState.IsValid) {
if (e.Id > 0) {
Estimate f = WorkFlowManager.GetEstimate (e.Id);
if (e.Owner != f.Owner)
string username = HttpContext.User.Identity.Name;
if (model.Id > 0) {
Estimate f = WorkFlowManager.GetEstimate (model.Id);
if (f == null) {
ModelState.AddModelError ("Id", "Wrong Id");
return View (model);
}
if (username != f.Owner)
if (!Roles.IsUserInRole ("FrontOffice"))
throw new UnauthorizedAccessException ("You're not allowed to modify this estimate");
throw new UnauthorizedAccessException ("You're not allowed to view/modify this estimate");
if (submit == "Update") {
if (model != f) {
WorkFlowManager.SetTitle (model.Id, model.Title);
}
} else if (submit == null) {
model = f;
}
} else if (model.Id == 0 && submit=="Create") {
// Create the estimate
model.Id=WorkFlowManager.CreateEstimate (username,
model.Title);
model.Owner = username;
}
}
return View (e);
return View(model);
}
[AcceptVerbs("GET")]

@ -52,6 +52,7 @@ namespace Yavsc.ApiControllers
{
WorkFlowManager.DropEstimate (estid);
}
[HttpGet]
[Authorize]
public object Index()
@ -60,48 +61,12 @@ namespace Yavsc.ApiControllers
string username = Membership.GetUser ().UserName;
return new { test=string.Format("Hello {0}!",username) };
}
[HttpGet]
[Authorize]
public long Write (long estid, string desc, decimal ucost, int count, long productid=0) {
// TODO ensure estid owner matches the current one
return WorkFlowManager.Write(estid, desc, ucost, count, productid);
}
/*
public object Details(int id)
{
throw new NotImplementedException ();
}
public object Create()
{
throw new NotImplementedException ();
}
public object Edit(int id)
{
throw new NotImplementedException ();
}
public object Delete(int id)
{
throw new NotImplementedException ();
}
IContentProvider contentProvider = null;
IContentProvider ContentProvider {
get {
if (contentProvider == null )
contentProvider = WFManager.GetContentProviderFWC ();
return contentProvider;
}
}
*/
}
}

@ -305,7 +305,7 @@ namespace Yavsc.Helpers
new BBTag ("h", "<h2>", "</h2>"),
bblist,
new BBTag ("*", "<li>", "</li>", true, false),
new BBTag ("url", "<a href=\"${href}\">", "</a>", true, false, new BBAttribute ("href", ""), new BBAttribute ("href", "href")),
new BBTag ("url", "<a href=\"${href}\">", "</a>", true, true, new BBAttribute ("href", ""), new BBAttribute ("href", "href")),
new BBTag ("br", "<br/>", "", true, false),
new BBTag ("video", "<video style=\"${style}\" controls>" +
"<source src=\"${mp4}\" type=\"video/mp4\"/>" +
@ -348,4 +348,3 @@ namespace Yavsc.Helpers
}
}
}

@ -3,9 +3,9 @@
<%= Html.ValidationSummary("Restore a database backup") %>
<% using (Html.BeginForm("Restore")) { %>
<% string [] bckdirs = Model.GetBackupDirs(); %>
<% string [] bcfiles = (string[]) ViewData["Backups"]; %>
<select name="backupName">
<% foreach (string s in bckdirs)
<% foreach (string s in bcfiles)
{
%>
<option value="<%=s%>"><%=s%></option>

@ -36,7 +36,7 @@ Usage BBcodes :
<%= Html.ValidationSummary("Edition du billet") %>
<% using(Html.BeginForm("ValidateEdit", "Blogs")) { %>
<% using(Html.BeginForm("ValidateEdit")) { %>
<%= Html.LabelFor(model => model.Title) %>:<br/>
<%= Html.TextBox( "Title" ) %>
<%= Html.ValidationMessage("Title", "*") %>

@ -1,10 +1,6 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogEditEntryModel>" MasterPageFile="~/Models/App.master"%>
<asp:Content ContentPlaceHolderID="head" ID="head" runat="server">
<title><%= Html.Encode(ViewData["BlogTitle"]) %> - Nouveau billet
- <%=Html.Encode(YavscHelpers.SiteName) %>
</title>
</asp:Content>
<asp:Content ContentPlaceHolderID="header" ID="headerContent" runat="server">
<asp:Content ContentPlaceHolderID="overHeaderOne" ID="headerContent" runat="server">
<h1 class="blogtitle">
<a href="/Blog/<%=ViewData["UserName"]%>">
<img class="avatar" src="/Blogs/Avatar?user=<%=ViewData["UserName"]%>" alt="from <%=ViewData["UserName"]%>"/>

@ -1,4 +1,4 @@
<%@ Page Title="Commande" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<FormCollection collection>" %>
<%@ Page Title="Commande" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<FormCollection>" %>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
rha
</asp:Content>

@ -1,19 +1,42 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %>
<!-- <asp:Content ContentPlaceHolderID="init" ID="initContent" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderID="overHeaderOne" ID="overHeaderOneContent" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderID="header" ID="headerContent" runat="server">
</asp:Content> -->
<%@ Page Title="Devis" Language="C#" Inherits="System.Web.Mvc.ViewPage<Estimate>" MasterPageFile="~/Models/App.master" %>
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
<% using (Html.BeginForm("Estimate")) { %>
<%= Html.ValidationSummary("Devis") %>
<% using (Html.BeginForm("Estimate","FrontOffice")) { %>
<%= Html.LabelFor(model => model.Title) %>:<br/>
<%= Html.TextBox( "Title" ) %>
<%= Html.ValidationMessage("Title", "*") %>
<% if (Model.Id > 0) { %>
<br/>
<%= Html.LabelFor(model => model.Owner) %>:<%=Model.Owner%>
<%= Html.ValidationMessage("Owner", "*") %>
<br/>
<%= Html.LabelFor(model => model.Ciffer) %>:<%=Model.Ciffer%>
<br/>
<%= Html.LabelFor(model => model.Id) %>:<%=Model.Id%>
<%= Html.Hidden( "Id" ) %>
<br/>
<% if (Model.Lines ==null || Model.Lines.Length == 0) { %>
<i>Pas de ligne.</i>
<%
} else { %>
<ul>
<% foreach (Writting wr in Model.Lines) { %>
<li><%=wr.Count%>/<%=wr.Id%>/<%=wr.ProductReference%>/<%=wr.UnitaryCost%>/<%=wr.Description%></li>
<% } %>
</ul>
<% } %>
<% } %>
<% if (Model.Id==0) { %>
<input type="submit" name="submit" value="Create"/>
<% } else { %>
<input type="submit" name="submit" value="Update"/>
<% }
%>
<% } %>
</asp:Content>
<!--
<asp:Content ContentPlaceHolderID="MASContent" ID="MASContentContent" runat="server">
</asp:Content>
-->

@ -0,0 +1,17 @@
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<div>
test
</div>
</body>
</html>

@ -1,7 +1,11 @@
<%@ Page Title="Yavsc - indexe" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master"%>
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
<div>
<%= Html.ActionLink("blogs","Index","Blogs") %>
<p>
« Voir le monde comme un rêve est un bon point de vue. Quand on fait un cauchemar, on se réveille et on se dit que ce nétait quun rêve. Il est dit que le monde où nous vivons nen diffère en rien ».
<br/><a href="http://unefenetresurlemonde.over-blog.com/article-34325590.html">Ghost Dog, la Voie du samouraï</a>
</p><div>
<%= Html.ActionLink("Les blogs","Index","Blogs") %>
</div>
</asp:Content>

@ -28,6 +28,7 @@
<add namespace="Yavsc.Model.RolesAndMembers" />
<add namespace="Yavsc.Model.Admin" />
<add namespace="Yavsc.Model.Blogs" />
<add namespace="Yavsc.Model.WorkFlow" />
</namespaces>
</pages>
</system.web>

@ -98,7 +98,6 @@
<Folder Include="Views\FrontOffice\" />
<Folder Include="avatars\" />
<Folder Include="Admin\" />
<Folder Include="Views\BackOffice\" />
<Folder Include="backup\" />
<Folder Include="errors\" />
<Folder Include="Views\FileSystem\" />
@ -196,6 +195,7 @@
<Content Include="Views\Admin\Restored.aspx" />
<Content Include="Views\Admin\Index.aspx" />
<Content Include="Views\FrontOffice\Estimate.aspx" />
<Content Include="Views\FrontOffice\test.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

@ -53,7 +53,7 @@ namespace Yavsc.Model.Admin
}
private string dbpassword ;
private string backupPrefix= "backup/global.backup";
private string backupPrefix= "~/backup/global.backup";
public string BackupPrefix {
get {
@ -69,16 +69,6 @@ namespace Yavsc.Model.Admin
get { return dbpassword; }
set { dbpassword = value; }
}
public string [] GetBackupDirs()
{
List<string> res = new List<string> ();
string bkpdir = new FileInfo (backupPrefix).DirectoryName;
DirectoryInfo bkpdiri = new DirectoryInfo(bkpdir);
foreach (DirectoryInfo di in bkpdiri.EnumerateDirectories())
res.Add (Path.Combine(bkpdir,di.Name));
return res.ToArray ();
}
}
}

@ -13,6 +13,11 @@ namespace Yavsc.Model.WorkFlow
/// </summary>
public static class WorkFlowManager
{
public static void SetTitle (long id, string title)
{
ContentProvider.SetTitle (id, title);
}
public static event EventHandler NewOrder;
public static Estimate GetEstimate (long estid)

Loading…