public async Task <IActionResult> PutRental(int id, Rental rental) { if (id != rental.RentalID) { return(BadRequest()); } _context.Entry(rental).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RentalExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> UpdateRental(int id, [FromForm] RentalViewModel rvm) { var rental = await _context.Rental.FindAsync(id); if (id != rental.RentalID) { return(BadRequest()); } rental.Region = rvm.Region; rental.Street = rvm.Street; rental.Title = rvm.Title; rental.Rooms = rvm.Rooms; rental.Cost = rvm.Cost; rental.Floor = rvm.Floor; rental.PropertyType = rvm.PropertyType; rental.RentTime = rvm.RentTime; rental.Description = rvm.Description; rental.Latitude = rvm.Latitude; rental.Longitude = rvm.Longitude; rental.Facilities = rvm.Facilities; rental.Infrastructure = rvm.Infrastructure; rental.Bookings = rvm.Bookings; rental.Photos = new List <ImageModel> { }; if (rvm.Photos != null) { var img = _context.Photos.Where(r => r.RentalID == rental.RentalID); _context.Photos.RemoveRange(img); foreach (var uploadedFile in rvm.Photos) { ImageModel file = new ImageModel { Name = uploadedFile.FileName }; file.Path = await _cloudStorage.UploadFileAsync(uploadedFile, file.Name); rental.Photos.Add(file); } } _context.Entry(rental).State = EntityState.Modified; _context.Entry(rental.Facilities).State = EntityState.Modified; _context.Entry(rental.Infrastructure).State = EntityState.Modified; foreach (var i in rental.Bookings) { _context.Entry(i).State = EntityState.Modified; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RentalExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }