public void AddProductToBasket(int productId, int userId) { var basketItems = new List <BasketItem>(); basketItems.Add(new BasketItem() { ProductId = productId, AmountOfProducts = 1 }); var basket = basketRepo.GetAll().Where(b => (b.IsClosed == false && b.UserId == userId)).FirstOrDefault(); if (basket == null) { basketRepo.Insert(new Basket() { IsClosed = false, UserId = userId, BasketItems = basketItems }); } else { var editBasketItem = basket.BasketItems.Where(b => b.ProductId == productId).FirstOrDefault(); if (editBasketItem == null) { basket.BasketItems.Add(new BasketItem() { ProductId = productId, AmountOfProducts = 1 }); } else { editBasketItem.AmountOfProducts++; } basketRepo.Update(basket); } }
public Basket Insert(Basket entity) { return(_repo.Insert(entity)); }