Skip to content

Instantly share code, notes, and snippets.

@codescribler
Last active August 29, 2015 14:08
Show Gist options
  • Save codescribler/9902e4373c8596a7b7ac to your computer and use it in GitHub Desktop.
Save codescribler/9902e4373c8596a7b7ac to your computer and use it in GitHub Desktop.
MVC Event Sourcing Example with CRUD
[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");
}
@IDisposable
Copy link

s/createdEventMessdage/createdEventMessage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment