private ViewBasketData GetViewBasketData(Basket basket, List<BasketLine> lines) { var result = new ViewBasketData { Basket = basket, Lines = new List<CustomBasketLine>() }; foreach (var basketLine in lines) { result.Lines.Add(new CustomBasketLine { Line = basketLine, Product = _productRepository.GetFirstOrDefault(z => z.Id == basketLine.ProductId) }); } return result; }
partial void DeleteBasket(Basket instance);
partial void UpdateBasket(Basket instance);
partial void InsertBasket(Basket instance);
private List<BasketLine> ChangeProductCountAndSave(Basket basket, Guid productId, int count) { var line = _basketLineRepository.GetFirstOrDefault(z => z.BasketId == basket.Id && z.ProductId == productId); line.Count = count; _basketLineRepository.UpdateBasketLine(line); var allLines = _basketLineRepository.FindAll(z => z.BasketId == basket.Id); basket.Total = 0; foreach (var basketLine in allLines) { var product = _productRepository.GetFirstOrDefault(z => z.Id == basketLine.ProductId); basket.Total += basketLine.Count * product.Price; } _basketRepository.UpdateBasket(basket); return allLines; }
public HttpResponseMessage RemoveBasket(Basket basket) { var lines = _basketLineRepository.FindAll(z => z.BasketId == basket.Id); _basketLineRepository.DeleteLines(lines); _basketRepository.DeleteItem(z=>z.Id == basket.Id); return SuccessResult(); }
private void RemoveProductFromBasketByProductId(Basket basket, Guid productId, decimal productPrice) { var line = _basketLineRepository.GetFirstOrDefault(z => z.BasketId == basket.Id && z.ProductId == productId); _basketLineRepository.DeleteItem(z => z.Id == line.Id); basket.Total = basket.Total - line.Count * productPrice; _basketRepository.UpdateBasket(basket); var allLines = _basketLineRepository.FindAll(z => z.BasketId == basket.Id); if (allLines.Count == 0) _basketRepository.DeleteItem(z => z.Id == basket.Id); }