コード例 #1
0
        public static ShoppingCartModel ConvertToShoppingCartModel(ShoppingCart shoppingCart)
        {
            var storeItem = StoreItemProcessor.GetStoreItemModelbyId(shoppingCart.StoreItemId);

            if (storeItem == null)
            {
                return(null);
            }

            ShoppingCartModel shoppingCartModel = new ShoppingCartModel
            {
                Id             = shoppingCart.Id,
                Name           = storeItem.Name,
                Discription    = storeItem.Discription,
                Brand          = storeItem.Brand,
                Price          = storeItem.Price,
                Discount       = storeItem.Discount,
                Images         = storeItem.Images,
                Specifications = storeItem.Specifications,
                Comments       = storeItem.Comments,

                Amount      = shoppingCart.Amount,
                DataCreated = shoppingCart.DataCreated,
                StoreItemId = shoppingCart.StoreItemId,
            };

            return(shoppingCartModel);
        }
コード例 #2
0
        public static void RemoveFromShoppingCart(Guid id, ShoppingCartModel shoppingCartModel)
        {
            UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository();

            var storeItem = StoreItemProcessor.GetStoreItembyId(shoppingCartModel.StoreItemId);

            if (storeItem == null)
            {
                return;
            }

            ChangeStoreItemStock(storeItem, shoppingCartModel.Amount);

            unitOfWork.CustomerRepository.RemoveFromShoppingCart(id, storeItem);
        }
コード例 #3
0
        public static void AddToShoppingCart(Guid id, StoreItemModel storeItemModel)
        {
            UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository();

            var StoreItem = StoreItemProcessor.ConvertModelToStoreItem(storeItemModel);
            var user      = UserProcessor.GetUser(id);

            if (!(user is Customer))
            {
                return;
            }

            var customer = (Customer)user;

            if (StoreItem == null)
            {
                return;
            }

            ChangeStoreItemStock(StoreItem, -1);

            int amount = 0;

            for (int i = 0; i < customer.ShoppingCart.Count(); i++)
            {
                if (customer.ShoppingCart[i].StoreItemId == storeItemModel.Id)
                {
                    amount++;
                }
            }
            if (amount == 0)
            {
                var shoppingCart = ConvertStoreItemToShoppingCart(StoreItem);
                unitOfWork.CustomerRepository.AddToShoppingCart(id, shoppingCart);
            }
            else // there are multible items equal to storeItemModel
            {
                //update storeItem amount
                var currenthoppingCart = customer.ShoppingCart.Where(x => x.StoreItemId == storeItemModel.Id).FirstOrDefault();
                int newAmount          = currenthoppingCart.Amount + 1;

                unitOfWork.CustomerRepository.UpdateShoppingCart(id, currenthoppingCart.Id, newAmount);
            }
        }
コード例 #4
0
        public static void UpdateShoppingCart(ShoppingCartModel oldModel, ShoppingCartModel newModel)
        {
            var shoppingCart = ConvertToShoppingCart(newModel);

            if (shoppingCart == null)
            {
                return;
            }

            UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository();

            unitOfWork.ShoppingCartRepository.Update(shoppingCart);

            var storeItem = StoreItemProcessor.GetStoreItembyId(oldModel.StoreItemId);

            int newAmount = oldModel.Amount - newModel.Amount;

            ChangeStoreItemStock(storeItem, newAmount);
        }
コード例 #5
0
 public static void ChangeStoreItemStock(StoreItem storeItem, int amount)
 {
     storeItem.InStock += amount;
     StoreItemProcessor.UpdateStoreItem(storeItem);
 }