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.Data.Entity;
using Yavsc.Models;
using Yavsc.Models.Forms;
using Yavsc.Models.Workflow;
namespace Yavsc.Controllers
@ -25,7 +26,7 @@ namespace Yavsc.Controllers
}
// GET: CommandForms/Details/5
public async Task<IActionResult> Details(string id)
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
@ -44,7 +45,8 @@ namespace Yavsc.Controllers
// GET: CommandForms/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();
}
@ -60,11 +62,12 @@ namespace Yavsc.Controllers
return RedirectToAction("Index");
}
ViewData["ActivityCode"] = new SelectList(_context.Activities, "Code", "Context", commandForm.ActivityCode);
ViewData["FormId"] = new SelectList(_context.Set<Form>(), "Id", "Form", commandForm.ViewName);
return View(commandForm);
}
// GET: CommandForms/Edit/5
public async Task<IActionResult> Edit(string id)
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
@ -77,6 +80,7 @@ namespace Yavsc.Controllers
return HttpNotFound();
}
ViewData["ActivityCode"] = new SelectList(_context.Activities, "Code", "Context", commandForm.ActivityCode);
ViewData["FormId"] = new SelectList(_context.Set<Form>(), "Id", "Form", commandForm.ViewName);
return View(commandForm);
}
@ -91,13 +95,14 @@ namespace Yavsc.Controllers
await _context.SaveChangesAsync();
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);
}
// GET: CommandForms/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(string id)
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
@ -116,7 +121,7 @@ namespace Yavsc.Controllers
// POST: CommandForms/Delete/5
[HttpPost, ActionName("Delete")]
[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);
_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");
}
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(
x => x.MinDailyCost
));

View File

@ -8,6 +8,7 @@ using Yavsc.Models;
using Microsoft.AspNet.Identity;
using System.Linq;
using System.Security.Claims;
using Microsoft.Data.Entity;
namespace Yavsc.Controllers
{
@ -30,7 +31,7 @@ namespace Yavsc.Controllers
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()

View File

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

View File

@ -4,7 +4,7 @@ using Microsoft.Data.Entity.Migrations;
namespace Yavsc.Migrations
{
public partial class commandForm : Migration
public partial class commandForms : Migration
{
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_PerformerProfile_UserId", table: "UserActivity");
migrationBuilder.CreateTable(
name: "CommandForm",
name: "Form",
columns: table => new
{
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),
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 =>
{
@ -238,6 +250,7 @@ namespace Yavsc.Migrations
migrationBuilder.DropForeignKey(name: "FK_PerformerProfile_ApplicationUser_PerformerId", table: "PerformerProfile");
migrationBuilder.DropForeignKey(name: "FK_UserActivity_Activity_DoesCode", table: "UserActivity");
migrationBuilder.DropForeignKey(name: "FK_UserActivity_PerformerProfile_UserId", table: "UserActivity");
migrationBuilder.DropTable("Form");
migrationBuilder.DropTable("CommandForm");
migrationBuilder.AddForeignKey(
name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId",

View File

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

View File

@ -6,6 +6,7 @@ using Microsoft.AspNet.Authentication.OAuth;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Yavsc.Models.Relationship;
using Yavsc.Models.Forms;
namespace Yavsc.Models
{
@ -255,5 +256,7 @@ namespace Yavsc.Models
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.Schema;
using Yavsc.Models.Market;
using Yavsc.Models.Workflow;
namespace Yavsc.Models
{
@ -55,5 +56,8 @@ namespace Yavsc.Models
public int Rate { get; set; }
[DisplayAttribute(Name="SettingsClass")]
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
{
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; }
[Required]

View File

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

View File

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

View File

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

View File

@ -20,10 +20,10 @@
</div>
</div>
<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">
<input asp-for="Summary" class="form-control" />
<span asp-validation-for="Summary" class="text-danger" />
<select asp-for="FormId" class="form-control" />
<span asp-validation-for="FormId" class="text-danger" />
</div>
</div>
<div class="form-group">

View File

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

View File

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

View File

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