public ActionResult <IEnumerable <ProductModel> > Post([FromBody] ProductRequestModel product) { var user = _context.Users.FirstOrDefault((u) => product.Id == u.Id); if (user == null) { return(new BadRequestResult()); } var productModel = new ProductModel() { Name = product.Name, Description = product.Description, BorrowingPrice = product.BorrowingPrice, Id = Guid.NewGuid(), IsActive = (product.IsActive != null ? product.IsActive : true), Owner = user, IsAvailable = true }; _context.Products.Add(productModel); _context.SaveChanges(); return(_context.Products); }
public ActionResult <IEnumerable <ProductModel> > Put(string productId, [FromBody] ProductRequestModel product) { var dbProduct = _context.Products.FirstOrDefault((u) => u.Id.ToString().Equals(productId)); if (dbProduct == null) { return(new NotFoundResult()); } dbProduct.Description = product.Description; dbProduct.Name = product.Name; dbProduct.IsActive = product.IsActive; dbProduct.BorrowingPrice = product.BorrowingPrice; dbProduct.IsAvailable = true; _context.SaveChanges(); return(_context.Products); }