public async Task <IActionResult> Update(RoomUpdateInputModel input) { if (!this.ModelState.IsValid) { var roomTypes = this.roomTypesService.GetAll <RoomTypeDropDownViewModel>(); input.RoomTypes = roomTypes; return(this.View(input)); } var userId = this.userManager.GetUserId(this.User); var user = await this.userManager .Users .Include(u => u.Hotel) .ThenInclude(h => h.Rooms) .FirstOrDefaultAsync(u => u.Id == userId); if (!user.Hotel.Rooms.Any(r => r.Id == input.Id)) { return(this.RedirectToAction("AllRooms")); } await this.roomsService.UpdateAsync( input.Id, input.Floor, input.Number, input.RoomTypeId, input.Price, input.MaxAdultCount, input.MaxChildCount, input.Description); return(this.RedirectToAction("AllRooms")); }
public async Task <IActionResult> Update(int roomId) { var user = await this.userManager.GetUserAsync(this.User); var room = await this.roomsService.GetByIdAsync <RoomUpdateViewModel>(roomId); if (room.HotelId != user.HotelId) { return(this.RedirectToAction("AllRooms")); } var roomTypes = this.roomTypesService.GetAll <RoomTypeDropDownViewModel>(); var viewModel = new RoomUpdateInputModel { Floor = room.Floor, Id = room.Id, MaxAdultCount = room.MaxAdultCount, MaxChildCount = room.MaxChildCount, Number = room.Number, Price = room.Price, Description = room.Description, RoomTypeId = room.RoomTypeId, RoomTypes = roomTypes, }; return(this.View(viewModel)); }