Exemplo n.º 1
0
 public IActionResult Post([FromBody] InsertCartDTO dto)
 {
     try
     {
         var id = GetTokenId.getId(User);
         _cartService.Insert(dto, id);
         return(Ok("succesfuly added to cart"));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Exemplo n.º 2
0
        public IActionResult Post([FromBody] InsertCartDTO dto)
        {
            var userId = AuthMiddleware.GetUserId(User);

            try
            {
                _service.Insert(dto, userId);
                return(Ok("Successfully added to cart!"));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 3
0
        public int Insert(InsertCartDTO dto, int id)
        {
            var dish = _unitOfWork.Dish.Get(dto.DishId);

            if (dish == null)
            {
                throw new Exception("Dish doesnt exist");
            }
            var cart = new Cart
            {
                DishId   = dto.DishId,
                UserId   = id,
                Quantity = dto.Quantity,
                Sum      = dto.Quantity * dish.Price
            };

            _unitOfWork.Cart.Add(cart);
            _unitOfWork.Save();
            return(cart.Id);
        }
Exemplo n.º 4
0
        public int Insert(InsertCartDTO entity, int id)
        {
            var book = _unitOfWork.Book.Get(entity.BookId);

            if (book == null)
            {
                throw new Exception("Book not found! Please check our book list then choose correct book id!");
            }
            var cart = new Cart()
            {
                UserId   = id,
                BookId   = entity.BookId,
                Quantity = entity.Quantity,
                Price    = book.Price,
                Sum      = entity.Quantity * book.Price
            };

            _unitOfWork.Cart.Add(cart);
            _unitOfWork.Save();
            return(cart.Id);
        }
Exemplo n.º 5
0
 public int Insert(InsertCartDTO entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
 public void Delete(InsertCartDTO entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 public void Update(InsertCartDTO entity, int id)
 {
     throw new NotImplementedException();
 }