Exemplo n.º 1
0
 public void AddItemToOrder(ShoppingCart.AddItemCommand cmd)
 {
     cmdExecutor.Execute(uow => {
         ShoppingCart sc = uow.ShoppingCarts.Get(cmd.Username);
         sc.AddItem(cmd);
         uow.ShoppingCarts.Save(sc);
     });
 }
Exemplo n.º 2
0
 public void ChangeQty(ShoppingCart.ChangeQtyCommand cmd)
 {
     cmdExecutor.Execute(uow =>
     {
         ShoppingCart sc = uow.ShoppingCarts.Get(cmd.Username);
         sc.ChangeQty(cmd);
         uow.ShoppingCarts.Save(sc);
     });
 }
Exemplo n.º 3
0
        public JsonResult AddItemToOrder(ShoppingCart.AddItemCommand cmd)
        {
            return CatchPosibleExeption(() =>
            {
                cmd.Username = this.User.Identity.Name;
                order.service.contract.IOrderService orderService = ObjectFactory.GetInstance<order.service.contract.IOrderService>();
                orderService.AddItemToOrder(cmd);

                return Json(new { success = true });
            });
        }
Exemplo n.º 4
0
        public void CheckoutOut(ShoppingCart.CheckoutCommand cmd, Action beforeAction)
        {
            cmdExecutor.Execute(uow => {
                if (beforeAction != null)
                {
                    beforeAction();
                }

                ShoppingCart sc = uow.ShoppingCarts.Get(cmd.Username);
                if (sc == null) return;

                ShoppingCartSnapshot snapshot = sc.CreateSnapshot();

                List<OrderItem> items = new List<OrderItem>();
                Order order = new Order
                {
                    BranchId = cmd.BranchId,
                    OrderDate = cmd.OrderDate,
                    OrderDateString = cmd.OrderDate.ToString("dd-MM-yyyy"),
                    OrderNumber = cmd.OrderNumber,
                    UserId = cmd.Username,
                    TotalAmountAfterDiscount = snapshot.TotalAmountAfterDiscount,
                    Items = items
                };

                snapshot.Items.ForEach(itemSnapshot => {
                    items.Add(new OrderItem
                    {
                        Order = order,
                        ItemId = itemSnapshot.ItemId,
                        ItemCode = itemSnapshot.ItemCode,
                        ItemName = itemSnapshot.ItemName,
                        UnitCode = itemSnapshot.UnitCode,
                        Price = itemSnapshot.Price,
                        Qty = itemSnapshot.Qty,
                        AmountAfterDiscount = itemSnapshot.AmountAfterDiscount
                    });
                });

                sc.Clear();

                uow.Orders.Add(order);
                uow.ShoppingCarts.Save(sc);
            });
        }
Exemplo n.º 5
0
        public void Save(ShoppingCart sc)
        {
            ShoppingCartSnapshot snapshot = sc.CreateSnapshot();

            ShoppingCartStore store = scStoreRepo.Where(s => s.UserId == snapshot.UserId).FirstOrDefault();
            if (store == null)
            {
                store = new ShoppingCartStore
                {
                    UserId = snapshot.UserId,
                    Payload = JsonConvert.SerializeObject(snapshot)
                };
                scStoreRepo.Add(store);
            }
            else
            {
                store.Payload = JsonConvert.SerializeObject(snapshot);
                scStoreRepo.Update(store);
            }
        }
Exemplo n.º 6
0
 public void RemoveItem(ShoppingCart.RemoveItemCommand cmd)
 {
     cmdExecutor.Execute(uow => {
         ShoppingCart sc = uow.ShoppingCarts.Get(cmd.Username);
         sc.RemoveItem(cmd);
         uow.ShoppingCarts.Save(sc);
     });
 }