/// <summary> /// Gets an instance of a view model based on the model type passed. /// </summary> /// <param name="modelType">A view model type to be crated by the DI container. Can include nested generics.</param> /// <returns></returns> public object GetViewModel(Type viewType, Type modelType, object modelInstance = null) { var args = new StructureMap.Pipeline.ExplicitArguments(); args.Set(modelType, modelInstance); var viewModel = Container.GetInstance(viewType, args); return(viewModel); }
public JsonResult Checkout() { return CatchPosibleExeption(() => { orderNumber = this.orderUow.ShoppingCarts.GetOrderNumber(OrderSession.Branch.BranchCode); orderNumber.Next(); this.orderUow.ShoppingCarts.SaveOrderNumber(orderNumber); using (var porderServiceChannel = OrderSession.OrderServiceChannelFactory.CreateChannel()) { ShoppingCart sc = this.orderUow.ShoppingCarts.Get(this.User.Identity.Name); if (sc == null) throw new ApplicationException("Shopping cart not found"); ShoppingCartSnapshot snapshot = sc.CreateSnapshot(); List<porder.model.OrderItem> porderItems = new List<porder.model.OrderItem>(); int orderItemSequence = 0; foreach (ShoppingCartItemSnapshot itemSnapshot in snapshot.Items) { porderItems.Add(new porder.model.OrderItem { SOSeq = ++orderItemSequence, ItemID = itemSnapshot.ItemId, UnitCode = itemSnapshot.UnitCode, Price = itemSnapshot.Price, Quantity = itemSnapshot.Qty, GrossAmt = itemSnapshot.AmountAfterDiscount, SubTotal = itemSnapshot.AmountAfterDiscount }); } po = new porder.model.Order { Items = porderItems, BranchID = OrderSession.Branch.BranchCode, SOCode = orderNumber.OrderNumberString(), CurrencyId = "IDR", SODate = DateTime.Today, Username = this.User.Identity.Name, VendorID = this.OrderSession.Branch.BranchCode, SOGrossAmt = snapshot.TotalAmountAfterDiscount, SONetAmt = snapshot.TotalAmountAfterDiscount }; porder.model.CreateOrderResponse response = porderServiceChannel.CreateOrder(po); if (response.Error) throw new ApplicationException(response.ErrorMessage); }; order.model.ShoppingCart.CheckoutCommand cmd = new ShoppingCart.CheckoutCommand { BranchId = OrderSession.Branch.Id, OrderDate = po.SODate, OrderNumber = this.orderNumber.OrderNumberString(), BranchCode = OrderSession.Branch.BranchCode, Username = this.User.Identity.Name }; var explicitArgs = new StructureMap.Pipeline.ExplicitArguments(); explicitArgs.SetArg("orderUow", this.orderUow); order.service.contract.IOrderService orderService = ObjectFactory.GetInstance<order.service.contract.IOrderService>(explicitArgs); orderService.CheckoutOut(cmd, () => { this.orderUow.ShoppingCarts.SaveOrderNumber(orderNumber); }); return Json(new { success = true }); }); }