public async Task <bool> Update(int id, ProductRental productRental) { if (id != productRental.Id) { return(false); } _context.Entry(productRental).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductRentalExists(id)) { return(false); } else { throw; } } return(true); }
public async Task <IActionResult> PutProductRental(int id, ProductRental productRental) { bool outcome = await _rentalService.Update(id, productRental); if (!outcome) { return(BadRequest()); } return(NoContent()); }
public async Task <List <ProductRental> > CreateRange(List <RentalDto> rentalDto) { List <ProductRental> productRental = new List <ProductRental>(); foreach (var dto in rentalDto) { var product = new ProductRental(); product.ProductId = dto.ProductId; product.UserId = dto.UserId; product.StartTime = dto.StartDate; product.EndTime = dto.EndDate; product.RentalTime = DateTime.Now; productRental.Add(product); } await _context.ProductRental.AddRangeAsync(productRental); await _context.SaveChangesAsync(); return(productRental); }