command forms :-)

This commit is contained in:
2017-01-24 10:43:42 +01:00
parent a169f38baf
commit 89c548d9e2
17 changed files with 214 additions and 48 deletions

View File

@ -4,6 +4,7 @@ using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Yavsc.Models; using Yavsc.Models;
using Yavsc.Models.Forms;
using Yavsc.Models.Workflow; using Yavsc.Models.Workflow;
namespace Yavsc.Controllers namespace Yavsc.Controllers
@ -25,7 +26,7 @@ namespace Yavsc.Controllers
} }
// GET: CommandForms/Details/5 // GET: CommandForms/Details/5
public async Task<IActionResult> Details(string id) public async Task<IActionResult> Details(long? id)
{ {
if (id == null) if (id == null)
{ {
@ -44,7 +45,8 @@ namespace Yavsc.Controllers
// GET: CommandForms/Create // GET: CommandForms/Create
public IActionResult Create() public IActionResult Create()
{ {
ViewData["ActivityCode"] = new SelectList(_context.Activities, "Code", "Context"); ViewBag.ActivityCode = new SelectList(_context.Activities, "Code", "Name");
ViewBag.ViewName = YavscLib.YavscConstants.Forms.Select( c => new SelectListItem { Text = c } );
return View(); return View();
} }
@ -60,11 +62,12 @@ namespace Yavsc.Controllers
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
ViewData["ActivityCode"] = new SelectList(_context.Activities, "Code", "Context", commandForm.ActivityCode); ViewData["ActivityCode"] = new SelectList(_context.Activities, "Code", "Context", commandForm.ActivityCode);
ViewData["FormId"] = new SelectList(_context.Set<Form>(), "Id", "Form", commandForm.ViewName);
return View(commandForm); return View(commandForm);
} }
// GET: CommandForms/Edit/5 // GET: CommandForms/Edit/5
public async Task<IActionResult> Edit(string id) public async Task<IActionResult> Edit(long? id)
{ {
if (id == null) if (id == null)
{ {
@ -77,6 +80,7 @@ namespace Yavsc.Controllers
return HttpNotFound(); return HttpNotFound();
} }
ViewData["ActivityCode"] = new SelectList(_context.Activities, "Code", "Context", commandForm.ActivityCode); ViewData["ActivityCode"] = new SelectList(_context.Activities, "Code", "Context", commandForm.ActivityCode);
ViewData["FormId"] = new SelectList(_context.Set<Form>(), "Id", "Form", commandForm.ViewName);
return View(commandForm); return View(commandForm);
} }
@ -91,13 +95,14 @@ namespace Yavsc.Controllers
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
ViewData["ActivityCode"] = new SelectList(_context.Activities, "Code", "Context", commandForm.ActivityCode); ViewBag.ActivityCode = new SelectList(_context.Activities, "Code", "Context", commandForm.ActivityCode);
ViewBag.ViewName = YavscLib.YavscConstants.Forms.Select( c => new SelectListItem { Text = c } );
return View(commandForm); return View(commandForm);
} }
// GET: CommandForms/Delete/5 // GET: CommandForms/Delete/5
[ActionName("Delete")] [ActionName("Delete")]
public async Task<IActionResult> Delete(string id) public async Task<IActionResult> Delete(long? id)
{ {
if (id == null) if (id == null)
{ {
@ -116,7 +121,7 @@ namespace Yavsc.Controllers
// POST: CommandForms/Delete/5 // POST: CommandForms/Delete/5
[HttpPost, ActionName("Delete")] [HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id) public async Task<IActionResult> DeleteConfirmed(long id)
{ {
CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id); CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id);
_context.CommandForm.Remove(commandForm); _context.CommandForm.Remove(commandForm);

View File

@ -0,0 +1,122 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Data.Entity;
using Yavsc.Models;
using Yavsc.Models.Forms;
namespace Yavsc.Controllers
{
public class FormsController : Controller
{
private ApplicationDbContext _context;
public FormsController(ApplicationDbContext context)
{
_context = context;
}
// GET: Forms
public async Task<IActionResult> Index()
{
return View(await _context.Form.ToListAsync());
}
// GET: Forms/Details/5
public async Task<IActionResult> Details(string id)
{
if (id == null)
{
return HttpNotFound();
}
Form form = await _context.Form.SingleAsync(m => m.Id == id);
if (form == null)
{
return HttpNotFound();
}
return View(form);
}
// GET: Forms/Create
public IActionResult Create()
{
return View();
}
// POST: Forms/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Form form)
{
if (ModelState.IsValid)
{
_context.Form.Add(form);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(form);
}
// GET: Forms/Edit/5
public async Task<IActionResult> Edit(string id)
{
if (id == null)
{
return HttpNotFound();
}
Form form = await _context.Form.SingleAsync(m => m.Id == id);
if (form == null)
{
return HttpNotFound();
}
return View(form);
}
// POST: Forms/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Form form)
{
if (ModelState.IsValid)
{
_context.Update(form);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(form);
}
// GET: Forms/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(string id)
{
if (id == null)
{
return HttpNotFound();
}
Form form = await _context.Form.SingleAsync(m => m.Id == id);
if (form == null)
{
return HttpNotFound();
}
return View(form);
}
// POST: Forms/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id)
{
Form form = await _context.Form.SingleAsync(m => m.Id == id);
_context.Form.Remove(form);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}

View File

@ -89,7 +89,7 @@ namespace Yavsc.Controllers
return View("Index"); return View("Index");
} }
ViewBag.Activities = _context.ActivityItems(null); ViewBag.Activities = _context.ActivityItems(null);
return View(_context.Performers.Include(p => p.Performer).Where return View("Book",_context.Performers.Include(p => p.Performer).Where
(p => p.Active).OrderBy( (p => p.Active).OrderBy(
x => x.MinDailyCost x => x.MinDailyCost
)); ));

View File

@ -8,6 +8,7 @@ using Yavsc.Models;
using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.Data.Entity;
namespace Yavsc.Controllers namespace Yavsc.Controllers
{ {
@ -30,7 +31,7 @@ namespace Yavsc.Controllers
public IActionResult Index() public IActionResult Index()
{ {
return View(DbContext.Activities.OrderByDescending(a=>a.Rate)); return View(DbContext.Activities.Include(a=>a.Forms).OrderByDescending(a=>a.Rate));
} }
public IActionResult About() public IActionResult About()

View File

@ -8,8 +8,8 @@ using Yavsc.Models;
namespace Yavsc.Migrations namespace Yavsc.Migrations
{ {
[DbContext(typeof(ApplicationDbContext))] [DbContext(typeof(ApplicationDbContext))]
[Migration("20170123085316_commandForm")] [Migration("20170124090324_commandForms")]
partial class commandForm partial class commandForms
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {
@ -531,6 +531,15 @@ namespace Yavsc.Migrations
b.HasKey("ConnectionId"); b.HasKey("ConnectionId");
}); });
modelBuilder.Entity("Yavsc.Models.Forms.Form", b =>
{
b.Property<string>("Id");
b.Property<string>("Summary");
b.HasKey("Id");
});
modelBuilder.Entity("Yavsc.Models.Identity.GoogleCloudMobileDeclaration", b => modelBuilder.Entity("Yavsc.Models.Identity.GoogleCloudMobileDeclaration", b =>
{ {
b.Property<string>("DeviceId"); b.Property<string>("DeviceId");
@ -718,15 +727,16 @@ namespace Yavsc.Migrations
modelBuilder.Entity("Yavsc.Models.Workflow.CommandForm", b => modelBuilder.Entity("Yavsc.Models.Workflow.CommandForm", b =>
{ {
b.Property<string>("Id"); b.Property<long>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ActivityCode") b.Property<string>("ActivityCode")
.IsRequired(); .IsRequired();
b.Property<string>("Summary");
b.Property<string>("Title"); b.Property<string>("Title");
b.Property<string>("ViewName");
b.HasKey("Id"); b.HasKey("Id");
}); });

View File

@ -4,7 +4,7 @@ using Microsoft.Data.Entity.Migrations;
namespace Yavsc.Migrations namespace Yavsc.Migrations
{ {
public partial class commandForm : Migration public partial class commandForms : Migration
{ {
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
@ -32,13 +32,25 @@ namespace Yavsc.Migrations
migrationBuilder.DropForeignKey(name: "FK_UserActivity_Activity_DoesCode", table: "UserActivity"); migrationBuilder.DropForeignKey(name: "FK_UserActivity_Activity_DoesCode", table: "UserActivity");
migrationBuilder.DropForeignKey(name: "FK_UserActivity_PerformerProfile_UserId", table: "UserActivity"); migrationBuilder.DropForeignKey(name: "FK_UserActivity_PerformerProfile_UserId", table: "UserActivity");
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "CommandForm", name: "Form",
columns: table => new columns: table => new
{ {
Id = table.Column<string>(nullable: false), Id = table.Column<string>(nullable: false),
Summary = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Form", x => x.Id);
});
migrationBuilder.CreateTable(
name: "CommandForm",
columns: table => new
{
Id = table.Column<long>(nullable: false)
.Annotation("Npgsql:Serial", true),
ActivityCode = table.Column<string>(nullable: false), ActivityCode = table.Column<string>(nullable: false),
Summary = table.Column<string>(nullable: true), Title = table.Column<string>(nullable: true),
Title = table.Column<string>(nullable: true) ViewName = table.Column<string>(nullable: true)
}, },
constraints: table => constraints: table =>
{ {
@ -238,6 +250,7 @@ namespace Yavsc.Migrations
migrationBuilder.DropForeignKey(name: "FK_PerformerProfile_ApplicationUser_PerformerId", table: "PerformerProfile"); migrationBuilder.DropForeignKey(name: "FK_PerformerProfile_ApplicationUser_PerformerId", table: "PerformerProfile");
migrationBuilder.DropForeignKey(name: "FK_UserActivity_Activity_DoesCode", table: "UserActivity"); migrationBuilder.DropForeignKey(name: "FK_UserActivity_Activity_DoesCode", table: "UserActivity");
migrationBuilder.DropForeignKey(name: "FK_UserActivity_PerformerProfile_UserId", table: "UserActivity"); migrationBuilder.DropForeignKey(name: "FK_UserActivity_PerformerProfile_UserId", table: "UserActivity");
migrationBuilder.DropTable("Form");
migrationBuilder.DropTable("CommandForm"); migrationBuilder.DropTable("CommandForm");
migrationBuilder.AddForeignKey( migrationBuilder.AddForeignKey(
name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId", name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId",

View File

@ -1,6 +1,8 @@
using System; using System;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Infrastructure; using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations;
using Yavsc.Models; using Yavsc.Models;
namespace Yavsc.Migrations namespace Yavsc.Migrations
@ -528,6 +530,15 @@ namespace Yavsc.Migrations
b.HasKey("ConnectionId"); b.HasKey("ConnectionId");
}); });
modelBuilder.Entity("Yavsc.Models.Forms.Form", b =>
{
b.Property<string>("Id");
b.Property<string>("Summary");
b.HasKey("Id");
});
modelBuilder.Entity("Yavsc.Models.Identity.GoogleCloudMobileDeclaration", b => modelBuilder.Entity("Yavsc.Models.Identity.GoogleCloudMobileDeclaration", b =>
{ {
b.Property<string>("DeviceId"); b.Property<string>("DeviceId");
@ -715,15 +726,16 @@ namespace Yavsc.Migrations
modelBuilder.Entity("Yavsc.Models.Workflow.CommandForm", b => modelBuilder.Entity("Yavsc.Models.Workflow.CommandForm", b =>
{ {
b.Property<string>("Id"); b.Property<long>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ActivityCode") b.Property<string>("ActivityCode")
.IsRequired(); .IsRequired();
b.Property<string>("Summary");
b.Property<string>("Title"); b.Property<string>("Title");
b.Property<string>("ViewName");
b.HasKey("Id"); b.HasKey("Id");
}); });

View File

@ -6,6 +6,7 @@ using Microsoft.AspNet.Authentication.OAuth;
using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Yavsc.Models.Relationship; using Yavsc.Models.Relationship;
using Yavsc.Models.Forms;
namespace Yavsc.Models namespace Yavsc.Models
{ {
@ -255,5 +256,7 @@ namespace Yavsc.Models
public DbSet<CommandForm> CommandForm { get; set; } public DbSet<CommandForm> CommandForm { get; set; }
public DbSet<Form> Form { get; set; }
} }
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Models.Market; using Yavsc.Models.Market;
using Yavsc.Models.Workflow;
namespace Yavsc.Models namespace Yavsc.Models
{ {
@ -55,5 +56,8 @@ namespace Yavsc.Models
public int Rate { get; set; } public int Rate { get; set; }
[DisplayAttribute(Name="SettingsClass")] [DisplayAttribute(Name="SettingsClass")]
public string SettingsClassName { get; set; } public string SettingsClassName { get; set; }
[InverseProperty("Context")]
public virtual List<CommandForm> Forms { get; set; }
} }
} }

View File

@ -3,8 +3,13 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Yavsc.Models.Workflow namespace Yavsc.Models.Workflow
{ {
public class CommandForm : Forms.Form public class CommandForm
{ {
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
public string ViewName { get; set; }
public string Title { get; set; } public string Title { get; set; }
[Required] [Required]

View File

@ -14,14 +14,13 @@
<div class="form-group"> <div class="form-group">
<label asp-for="ActivityCode" class="col-md-2 control-label"></label> <label asp-for="ActivityCode" class="col-md-2 control-label"></label>
<div class="col-md-10"> <div class="col-md-10">
<select asp-for="ActivityCode" class ="form-control"></select> <select asp-for="ActivityCode" asp-items="@ViewBag.ActivityCode" class ="form-control"></select>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="Summary" class="col-md-2 control-label"></label> <label asp-for="ViewName" class="col-md-2 control-label"></label>
<div class="col-md-10"> <div class="col-md-10">
<input asp-for="Summary" class="form-control" /> <select asp-for="ViewName" asp-items="@ViewBag.ViewName" class ="form-control"></select>
<span asp-validation-for="Summary" class="text-danger" />
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@ -11,12 +11,6 @@
<h4>CommandForm</h4> <h4>CommandForm</h4>
<hr /> <hr />
<dl class="dl-horizontal"> <dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Summary)
</dt>
<dd>
@Html.DisplayFor(model => model.Summary)
</dd>
<dt> <dt>
@Html.DisplayNameFor(model => model.Title) @Html.DisplayNameFor(model => model.Title)
</dt> </dt>

View File

@ -10,12 +10,6 @@
<h4>CommandForm</h4> <h4>CommandForm</h4>
<hr /> <hr />
<dl class="dl-horizontal"> <dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Summary)
</dt>
<dd>
@Html.DisplayFor(model => model.Summary)
</dd>
<dt> <dt>
@Html.DisplayNameFor(model => model.Title) @Html.DisplayNameFor(model => model.Title)
</dt> </dt>

View File

@ -20,10 +20,10 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="Summary" class="col-md-2 control-label"></label> <label asp-for="FormId" class="control-label col-md-2">FormId</label>
<div class="col-md-10"> <div class="col-md-10">
<input asp-for="Summary" class="form-control" /> <select asp-for="FormId" class="form-control" />
<span asp-validation-for="Summary" class="text-danger" /> <span asp-validation-for="FormId" class="text-danger" />
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@ -11,9 +11,6 @@
</p> </p>
<table class="table"> <table class="table">
<tr> <tr>
<th>
@Html.DisplayNameFor(model => model.Summary)
</th>
<th> <th>
@Html.DisplayNameFor(model => model.Title) @Html.DisplayNameFor(model => model.Title)
</th> </th>
@ -22,9 +19,6 @@
@foreach (var item in Model) { @foreach (var item in Model) {
<tr> <tr>
<td>
@Html.DisplayFor(modelItem => item.Summary)
</td>
<td> <td>
@Html.DisplayFor(modelItem => item.Title) @Html.DisplayFor(modelItem => item.Title)
</td> </td>

View File

@ -29,9 +29,11 @@
<p><em>@act.Name</em><br/> <p><em>@act.Name</em><br/>
@act.Description </p> @act.Description </p>
<p> <p>
<a class="btn btn-default" asp-controller="FrontOffice" asp-action="Book" asp-route-id="@act.Code"> @foreach (var form in act.Forms) {
En savoir plus <a class="btn btn-default" asp-controller="FrontOffice" asp-action="@form.ViewName" asp-route-id="@act.Code">
@form.Title
</a> </a>
}
</p> </p>
</div> </div>
</div> </div>

View File

@ -0,0 +1,8 @@
namespace YavscLib
{
public static class YavscConstants
{
public static readonly string [] Forms = new string [] { "Book" };
}
}