Пример #1
0
 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;
 }
Пример #2
0
 partial void DeleteBasket(Basket instance);
Пример #3
0
 partial void UpdateBasket(Basket instance);
Пример #4
0
 partial void InsertBasket(Basket instance);
Пример #5
0
        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;
        }
Пример #6
0
 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();
 }
Пример #7
0
        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);
        }