-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
312 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
src/Examples/NEventLite Example MVC/Controllers/HomeController.cs
This file was deleted.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
src/Examples/NEventLite Example MVC/Controllers/NoteDtoController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
using NEventLite.Command_Bus; | ||
using NEventLite_Example.Commands; | ||
using NEventLite_Example.Read_Model; | ||
using NEventLite_Example_MVC.Models; | ||
using WebGrease.Css.Ast; | ||
|
||
namespace NEventLite_Example_MVC.Controllers | ||
{ | ||
public class NoteDtoController : Controller | ||
{ | ||
// GET: NoteDto | ||
public ActionResult Index() | ||
{ | ||
return View(GetReadRepository().GetAllNotes().OrderBy(o=> o.CreatedDate).Select(o => new NoteDto(o))); | ||
} | ||
|
||
// GET: NoteDto/Create | ||
public ActionResult Create() | ||
{ | ||
return View(); | ||
} | ||
|
||
// POST: NoteDto/Create | ||
[HttpPost] | ||
public async Task<ActionResult> Create(FormCollection collection) | ||
{ | ||
try | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
await GetCommandBus().ExecuteAsync( | ||
new CreateNoteCommand(Guid.NewGuid(), Guid.NewGuid(), -1, collection["Title"], | ||
collection["Description"], collection["Category"])); | ||
|
||
|
||
} | ||
|
||
return RedirectToAction("Index"); | ||
} | ||
catch | ||
{ | ||
return View(); | ||
} | ||
} | ||
|
||
// GET: NoteDto/Edit/5 | ||
public ActionResult Edit(Guid id) | ||
{ | ||
var note = new NoteDto(GetReadRepository().GetNote(id)); | ||
|
||
return View(note); | ||
} | ||
|
||
// POST: NoteDto/Edit/5 | ||
[HttpPost] | ||
public async Task<ActionResult> Edit(Guid id, int CurrentVersion, FormCollection collection) | ||
{ | ||
try | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
await GetCommandBus().ExecuteAsync( | ||
new EditNoteCommand(Guid.NewGuid(), id, CurrentVersion, collection["Title"], | ||
collection["Description"], collection["Category"])); | ||
|
||
|
||
} | ||
|
||
return RedirectToAction("Index"); | ||
} | ||
catch | ||
{ | ||
return View(); | ||
} | ||
} | ||
|
||
private MyReadRepository GetReadRepository() | ||
{ | ||
return ((MvcApplication)this.HttpContext.ApplicationInstance).GetDependencyResolver().Resolve<MyReadRepository>(); | ||
} | ||
|
||
private ICommandBus GetCommandBus() | ||
{ | ||
return ((MvcApplication)this.HttpContext.ApplicationInstance).GetDependencyResolver().Resolve<ICommandBus>(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using NEventLite_Example.Read_Model; | ||
|
||
namespace NEventLite_Example_MVC.Models | ||
{ | ||
public class NoteDto | ||
{ | ||
public Guid Id { get; private set; } | ||
public int CurrentVersion { get; set; } | ||
public DateTime CreatedDate { get; set; } | ||
public string Title { get; set; } | ||
public string Description { get; set; } | ||
public string Category { get; set; } | ||
|
||
public NoteDto(Guid id, DateTime createdDate, string title, string description, string category) | ||
{ | ||
Id = id; | ||
CreatedDate = createdDate; | ||
Title = title; | ||
Description = description; | ||
Category = category; | ||
CurrentVersion = 0; | ||
} | ||
|
||
public NoteDto(NoteReadModel note) : this(note.Id, note.CreatedDate, note.Title, note.Description, note.Category) | ||
{ | ||
this.CurrentVersion = note.CurrentVersion; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
src/Examples/NEventLite Example MVC/Views/Home/Contact.cshtml
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/Examples/NEventLite Example MVC/Views/Home/Index.cshtml
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
src/Examples/NEventLite Example MVC/Views/NoteDto/Create.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@model NEventLite_Example_MVC.Models.NoteDto | ||
|
||
@{ | ||
ViewBag.Title = "Create"; | ||
} | ||
|
||
<h2>Create</h2> | ||
|
||
|
||
@using (Html.BeginForm()) | ||
{ | ||
@Html.AntiForgeryToken() | ||
|
||
<div class="form-horizontal"> | ||
<h4>NoteDto</h4> | ||
<hr /> | ||
@Html.ValidationSummary(true, "", new { @class = "text-danger" }) | ||
|
||
<div class="form-group"> | ||
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" }) | ||
<div class="col-md-10"> | ||
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } }) | ||
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" }) | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" }) | ||
<div class="col-md-10"> | ||
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } }) | ||
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" }) | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
@Html.LabelFor(model => model.Category, htmlAttributes: new { @class = "control-label col-md-2" }) | ||
<div class="col-md-10"> | ||
@Html.EditorFor(model => model.Category, new { htmlAttributes = new { @class = "form-control" } }) | ||
@Html.ValidationMessageFor(model => model.Category, "", new { @class = "text-danger" }) | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-md-offset-2 col-md-10"> | ||
<input type="submit" value="Create" class="btn btn-default" /> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
|
||
<div> | ||
@Html.ActionLink("Back to List", "Index") | ||
</div> | ||
|
||
@section Scripts { | ||
@Scripts.Render("~/bundles/jqueryval") | ||
} |
60 changes: 60 additions & 0 deletions
60
src/Examples/NEventLite Example MVC/Views/NoteDto/Edit.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
@model NEventLite_Example_MVC.Models.NoteDto | ||
|
||
@{ | ||
ViewBag.Title = "View"; | ||
} | ||
|
||
<h2>View</h2> | ||
|
||
|
||
@using (Html.BeginForm()) | ||
{ | ||
@Html.AntiForgeryToken() | ||
|
||
<div class="form-horizontal"> | ||
<h4>NoteDto</h4> | ||
<hr /> | ||
@Html.ValidationSummary(true, "", new { @class = "text-danger" }) | ||
@Html.HiddenFor(model => model.Id) | ||
@Html.HiddenFor(model => model.CurrentVersion) | ||
|
||
|
||
<div class="form-group"> | ||
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" }) | ||
<div class="col-md-10"> | ||
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } }) | ||
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" }) | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" }) | ||
<div class="col-md-10"> | ||
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } }) | ||
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" }) | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
@Html.LabelFor(model => model.Category, htmlAttributes: new { @class = "control-label col-md-2" }) | ||
<div class="col-md-10"> | ||
@Html.EditorFor(model => model.Category, new { htmlAttributes = new { @class = "form-control" } }) | ||
@Html.ValidationMessageFor(model => model.Category, "", new { @class = "text-danger" }) | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-md-offset-2 col-md-10"> | ||
<input type="submit" value="Save" class="btn btn-default" /> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
|
||
<div> | ||
@Html.ActionLink("Back to List", "Index") | ||
</div> | ||
|
||
@section Scripts { | ||
@Scripts.Render("~/bundles/jqueryval") | ||
} |
Oops, something went wrong.