public static Boolean AddItem(ShoppingCartItemVM shoppingCartItemVm) { ProductMapper productMapper = new ProductMapper(); Product product = productMapper.GetProduct(shoppingCartItemVm.IdProduct); if (product.Stock >= shoppingCartItemVm.Quantity) { ShoppingCartMapper shoppingCartMapper = new ShoppingCartMapper(); ShoppingCartItem shoppingCartItem = new ShoppingCartItem(shoppingCartItemVm.IdProduct, shoppingCartItemVm.Quantity); shoppingCartMapper.AddShoppingCartItem(shoppingCartItem); return true; } else { return false; } }
public static ShoppingCartVM GetShoppingCart() { ShoppingCartMapper shoppingCartMapper = new ShoppingCartMapper(); ShoppingCart shoppingCart = shoppingCartMapper.GetShoppingCart(); shoppingCart.TotalPrice = TotalPrice(shoppingCart); LoginVM loginVm = new LoginVM(shoppingCart.User.EmailAddress, shoppingCart.User.Password); List<ShoppingCartItemVM> shoppingCartItemVmList = new List<ShoppingCartItemVM>(); foreach (var shoppingCartItem in shoppingCart.ShoppingCartItemsList) { var shoppingCartItemVM=new ShoppingCartItemVM(shoppingCartItem.IdProduct, shoppingCartItem.Quantity); shoppingCartItemVmList.Add(shoppingCartItemVM); } ShoppingCartVM shoppingCartVM = new ShoppingCartVM(shoppingCart.Id, loginVm, shoppingCart.TotalPrice,shoppingCartItemVmList); return shoppingCartVM; }
public static void UpdateItem(ShoppingCartItemVM shoppingCartItemVm) { ShoppingCartMapper shoppingCartMapper = new ShoppingCartMapper(); ShoppingCartItem shoppingCartItem = new ShoppingCartItem(shoppingCartItemVm.IdProduct, shoppingCartItemVm.Quantity); shoppingCartMapper.UpdateShoppingCartItem(shoppingCartItem); }
public static void SetUserToCart(UserVM userVm) { ShoppingCartMapper shoppingCartMapper = new ShoppingCartMapper(); User user = new User(userVm.EmailAddress, userVm.Password); shoppingCartMapper.SetUserToShoppingCart(user); }
public static void RemoveItem(int idProduct) { ShoppingCartMapper shoppingCartMapper = new ShoppingCartMapper(); shoppingCartMapper.RemoveShoppingCartItem(idProduct); }
public static void PayOrder() { ShoppingCartMapper shoppingCartMapper = new ShoppingCartMapper(); shoppingCartMapper.AddOrder(); shoppingCartMapper.ClearShoppingCart(); }