Ejemplo n.º 1
0
        public void Add(int knifeId, int userId)
        {
            var knife = _unitOfWork.KnifeRepository.Get(x => x.Id == knifeId);

            if (GetAll().Count == 0)
            {
                var check = new Check()
                {
                    Date   = DateTime.Now,
                    Id     = CartId,
                    Status = CheckStatus.InBasket,
                    Sum    = knife.Price,
                    UserId = userId
                };
                var sell = new Sell()
                {
                    Check    = check,
                    CheckId  = check.Id,
                    KnifeId  = knifeId,
                    Quantity = 1,
                    Knife    = knife
                };
                _unitOfWork.CheckRepository.Insert(check);
                _unitOfWork.SellRepository.Insert(sell);
                _unitOfWork.Save();
            }
            var mapped = _mapper.Map <Knife, KnifeDTO>(knife);

            _cart.Add(mapped);
            BasketChanged?.Invoke(this, new EventArgs());
        }
Ejemplo n.º 2
0
        public void Remove(int knifeId)
        {
            var knife  = _unitOfWork.KnifeRepository.Get(x => x.Id == knifeId);
            var mapped = _mapper.Map <Knife, KnifeDTO>(knife);

            _cart.Remove(mapped);
            BasketChanged?.Invoke(this, new EventArgs());
        }
Ejemplo n.º 3
0
 public void UseDiscount(IDiscount discount)
 {
     _cart.UseDiscount(discount);
     BasketChanged?.Invoke(this, new EventArgs());
 }
Ejemplo n.º 4
0
 public void Clear()
 {
     _cart.Clear();
     BasketChanged?.Invoke(this, new EventArgs());
 }