diff --git a/Yavsc/Controllers/CommandFormsController.cs b/Yavsc/Controllers/CommandFormsController.cs index 9a6614d0..f8da212e 100644 --- a/Yavsc/Controllers/CommandFormsController.cs +++ b/Yavsc/Controllers/CommandFormsController.cs @@ -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 Details(string id) + public async Task 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
(), "Id", "Form", commandForm.ViewName); return View(commandForm); } // GET: CommandForms/Edit/5 - public async Task Edit(string id) + public async Task 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(), "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 Delete(string id) + public async Task Delete(long? id) { if (id == null) { @@ -116,7 +121,7 @@ namespace Yavsc.Controllers // POST: CommandForms/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(string id) + public async Task DeleteConfirmed(long id) { CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id); _context.CommandForm.Remove(commandForm); diff --git a/Yavsc/Controllers/FormsController.cs b/Yavsc/Controllers/FormsController.cs new file mode 100644 index 00000000..40a8d992 --- /dev/null +++ b/Yavsc/Controllers/FormsController.cs @@ -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 Index() + { + return View(await _context.Form.ToListAsync()); + } + + // GET: Forms/Details/5 + public async Task 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 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 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 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 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 DeleteConfirmed(string id) + { + Form form = await _context.Form.SingleAsync(m => m.Id == id); + _context.Form.Remove(form); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/FrontOfficeController.cs b/Yavsc/Controllers/FrontOfficeController.cs index f87edaba..828c794f 100644 --- a/Yavsc/Controllers/FrontOfficeController.cs +++ b/Yavsc/Controllers/FrontOfficeController.cs @@ -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 )); diff --git a/Yavsc/Controllers/HomeController.cs b/Yavsc/Controllers/HomeController.cs index 1b2d3e85..4bfef96a 100644 --- a/Yavsc/Controllers/HomeController.cs +++ b/Yavsc/Controllers/HomeController.cs @@ -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() diff --git a/Yavsc/Migrations/20170123085316_commandForm.Designer.cs b/Yavsc/Migrations/20170124090324_commandForms.Designer.cs similarity index 98% rename from Yavsc/Migrations/20170123085316_commandForm.Designer.cs rename to Yavsc/Migrations/20170124090324_commandForms.Designer.cs index 825494e4..af4b6349 100644 --- a/Yavsc/Migrations/20170123085316_commandForm.Designer.cs +++ b/Yavsc/Migrations/20170124090324_commandForms.Designer.cs @@ -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("Id"); + + b.Property("Summary"); + + b.HasKey("Id"); + }); + modelBuilder.Entity("Yavsc.Models.Identity.GoogleCloudMobileDeclaration", b => { b.Property("DeviceId"); @@ -718,15 +727,16 @@ namespace Yavsc.Migrations modelBuilder.Entity("Yavsc.Models.Workflow.CommandForm", b => { - b.Property("Id"); + b.Property("Id") + .ValueGeneratedOnAdd(); b.Property("ActivityCode") .IsRequired(); - b.Property("Summary"); - b.Property("Title"); + b.Property("ViewName"); + b.HasKey("Id"); }); diff --git a/Yavsc/Migrations/20170123085316_commandForm.cs b/Yavsc/Migrations/20170124090324_commandForms.cs similarity index 97% rename from Yavsc/Migrations/20170123085316_commandForm.cs rename to Yavsc/Migrations/20170124090324_commandForms.cs index 7a6b0420..17994287 100644 --- a/Yavsc/Migrations/20170123085316_commandForm.cs +++ b/Yavsc/Migrations/20170124090324_commandForms.cs @@ -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(nullable: false), + Summary = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Form", x => x.Id); + }); + migrationBuilder.CreateTable( + name: "CommandForm", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Npgsql:Serial", true), ActivityCode = table.Column(nullable: false), - Summary = table.Column(nullable: true), - Title = table.Column(nullable: true) + Title = table.Column(nullable: true), + ViewName = table.Column(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_IdentityRole_RoleId", diff --git a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs index 01df740d..1c029a49 100644 --- a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs @@ -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("Id"); + + b.Property("Summary"); + + b.HasKey("Id"); + }); + modelBuilder.Entity("Yavsc.Models.Identity.GoogleCloudMobileDeclaration", b => { b.Property("DeviceId"); @@ -715,15 +726,16 @@ namespace Yavsc.Migrations modelBuilder.Entity("Yavsc.Models.Workflow.CommandForm", b => { - b.Property("Id"); + b.Property("Id") + .ValueGeneratedOnAdd(); b.Property("ActivityCode") .IsRequired(); - b.Property("Summary"); - b.Property("Title"); + b.Property("ViewName"); + b.HasKey("Id"); }); diff --git a/Yavsc/Models/ApplicationDbContext.cs b/Yavsc/Models/ApplicationDbContext.cs index ce5aeb1d..40581461 100644 --- a/Yavsc/Models/ApplicationDbContext.cs +++ b/Yavsc/Models/ApplicationDbContext.cs @@ -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 { get; set; } + public DbSet Form { get; set; } + } } diff --git a/Yavsc/Models/Workflow/Activity.cs b/Yavsc/Models/Workflow/Activity.cs index 35d1bdc4..58f5c62a 100644 --- a/Yavsc/Models/Workflow/Activity.cs +++ b/Yavsc/Models/Workflow/Activity.cs @@ -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 Forms { get; set; } } } diff --git a/Yavsc/Models/Workflow/CommandForm.cs b/Yavsc/Models/Workflow/CommandForm.cs index ddbaf4f5..c3156f5b 100644 --- a/Yavsc/Models/Workflow/CommandForm.cs +++ b/Yavsc/Models/Workflow/CommandForm.cs @@ -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] diff --git a/Yavsc/Views/CommandForms/Create.cshtml b/Yavsc/Views/CommandForms/Create.cshtml index de6380a4..84e3ccc0 100644 --- a/Yavsc/Views/CommandForms/Create.cshtml +++ b/Yavsc/Views/CommandForms/Create.cshtml @@ -14,14 +14,13 @@
- +
- +
- - +
diff --git a/Yavsc/Views/CommandForms/Delete.cshtml b/Yavsc/Views/CommandForms/Delete.cshtml index f0a2c507..f0c65ba8 100644 --- a/Yavsc/Views/CommandForms/Delete.cshtml +++ b/Yavsc/Views/CommandForms/Delete.cshtml @@ -11,12 +11,6 @@

CommandForm


-
- @Html.DisplayNameFor(model => model.Summary) -
-
- @Html.DisplayFor(model => model.Summary) -
@Html.DisplayNameFor(model => model.Title)
diff --git a/Yavsc/Views/CommandForms/Details.cshtml b/Yavsc/Views/CommandForms/Details.cshtml index dc3ba2ba..066471a0 100644 --- a/Yavsc/Views/CommandForms/Details.cshtml +++ b/Yavsc/Views/CommandForms/Details.cshtml @@ -10,12 +10,6 @@

CommandForm


-
- @Html.DisplayNameFor(model => model.Summary) -
-
- @Html.DisplayFor(model => model.Summary) -
@Html.DisplayNameFor(model => model.Title)
diff --git a/Yavsc/Views/CommandForms/Edit.cshtml b/Yavsc/Views/CommandForms/Edit.cshtml index 15e6c5fc..489981e2 100644 --- a/Yavsc/Views/CommandForms/Edit.cshtml +++ b/Yavsc/Views/CommandForms/Edit.cshtml @@ -20,10 +20,10 @@
- +
- - +