public OrderNumber GetOrderNumber(string branchId) { DateTime today = DateTime.Today; OrderNumber orderNumber = orderNumberRepo.Where(order => order.Year == today.Year && order.Month == today.Month && order.Branch == branchId).FirstOrDefault(); if (orderNumber == null) { orderNumber = new OrderNumber(branchId, today.Year, today.Month); } return orderNumber; }
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 }); }); }
public void SaveOrderNumber(OrderNumber orderNumber) { if (orderNumber.Id == 0) { orderNumberRepo.Add(orderNumber); } else { orderNumberRepo.Update(orderNumber); } }