-
Notifications
You must be signed in to change notification settings - Fork 78
Tutorial 0: Step 4: Replacing the save operations
If you missed it, this is the fourth step, following on from step 3.
Check out the code and navigate to the /NorthwindDemo/step-3
folder.
Locate the EventStoreTable-SqlServer.sql
sql script in the tools
folder of \aspnet-mvc\Northwind\tools
. Execute this script on the Northwind database to add the event store.
Next, as the CS-CQRS framework has moved on from the 1990's and integer base identifiers to using Guids/Uuids, change the primary key/index from the OrderID
field to the Rsn
field.
Open the OrdersController.cs
file in the Northwind.Web.Dashboard\Controllers\OrdersController.cs
folder. Locate the Orders_Create
method and replace the body of the method with the following content:
if (ModelState.IsValid)
{
order.OrderID = new Random(Guid.NewGuid().GetHashCode()).Next();
var orderServiceFactory = new HttpOrderServiceChannelFactory();
IOrderService service = orderServiceFactory.CreateChannel();
var request2 = new ServiceRequestWithData<ISingleSignOnToken, OrderEntity>
{
AuthenticationToken = new SingleSignOnToken(),
CorrelationId = Guid.NewGuid(),
Data = new OrderEntity
{
OrderId = order.OrderID,
CustomerId = order.CustomerID,
EmployeeId = order.EmployeeID,
OrderDate = order.OrderDate,
ShipCountry = order.ShipCountry,
ShipViaId = order.ShipVia,
ShippedDate = order.ShippedDate,
ShipName = order.ShipName,
ShipAddress = order.ShipAddress,
ShipCity = order.ShipCity,
ShipPostalCode = order.ShipPostalCode
}
};
service.CreateOrder(request2);
}
return Json(new[] { order }.ToDataSourceResult(request, ModelState));
Once compiled, you should now be able to start up the Northwind Dashboard Application. Once running, visit the url /Home/ProductsAndOrders
of the Northwind Dashboard Application. At the top of the orders grid is a button Create new order
, clicking on that will activate the new order
widget, which, when the Update
button is clicked, the above new code will be executed, adding a new order.
For anyone interested in a more advanced way to process the WCF API, there is an advanced enhancement article
You have now completed the fourth step of this tutorial. Your code is now ready for step 5.