Last active
August 29, 2015 14:08
-
-
Save codescribler/9902e4373c8596a7b7ac to your computer and use it in GitHub Desktop.
MVC Event Sourcing Example with CRUD
This file contains hidden or 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
[HttpPost] | |
public ActionResult CreateCustomer(Customer customer) | |
{ | |
// Check business logic here (but no persistance) | |
if (DB.Customers.Values.ToList().Any(c => c.Name == customer.Name)) | |
{ | |
ModelState.AddModelError(string.Empty, "Duplicate Name Detected"); | |
} | |
if (!ModelState.IsValid) | |
{ | |
return View(customer); | |
} | |
// assuming all is good create and save event message | |
var createdEventMessdage = new CustomerCreated { Id = Guid.NewGuid(), Name = customer.Name }; | |
DB.SaveEvent(createdEventMessdage); | |
// Send it off to be routed arround the system | |
_router.Handle(createdEventMessdage); // This could be handling multiple tasks if needed - all de-coupled and simple | |
return RedirectToAction("Index"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
s/createdEventMessdage/createdEventMessage