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)); } }
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)); } }
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); }
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); }
public int Insert(InsertCartDTO entity) { throw new NotImplementedException(); }
public void Delete(InsertCartDTO entity) { throw new NotImplementedException(); }
public void Update(InsertCartDTO entity, int id) { throw new NotImplementedException(); }