public void Enqueue <T>(T command) where T : class, ICommand { var envelope = new CommandEnvelope { Command = command }; _bus.Send(envelope); }
public ActionResult Checkout(string customerCartId, CheckoutViewModel model) { var cart = _session.QueryOver <ShoppingCart>().Where(x => x.CartId == customerCartId).List(); var account = _session.Get <Account>(_identity.Identity()); ViewBag.Cart = cart; ViewBag.Total = cart.Sum(x => x.Product.Price * x.Quantity); ViewBag.ShippingRegions = _session.QueryOver <ShippingRegion>().List().Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString(), Selected = x.Id == account.Details.ShippingRegion }).ToList(); ViewBag.ShippingTypes = _session.QueryOver <Shipping>().List(); if (!ModelState.IsValid) { return(View()); } int taxId; switch (model.AccountDetails.ShippingRegion) { case 2: taxId = 1; break; default: taxId = 2; break; } var order = new Order(account.Id, "", account.Email, cart.Select(item => new OrderDetail() { ProductId = item.Product.Id, ProductName = item.Product.Name, Quantity = item.Quantity, UnitCost = item.Product.Price }).ToList(), _session.Get <Tax>(taxId), _session.Get <Shipping>(model.ShippingType)); foreach (var item in cart) { _session.Delete(item); } _session.Save(order); _bus.Send(new InitialNotificationMessage() { OrderId = order.Id, CorrelationId = order.SagaCorrelationId }); return(RedirectToAction("Placed", "Order")); }
public ActionResult Process(int id) { var order = _session.Get <Order>(id); var status = order.Status; if (messages.ContainsKey(status)) { _bus.Send(messages[status](order.SagaCorrelationId)); } return(RedirectToAction("Edit", "Order", new { id = id })); }