public async Task <ActionResult> Edit(int roomId, RoomEdit model) { try { if (!ModelState.IsValid) { return(View(model)); } if (model.Id != roomId) { ModelState.AddModelError("", "Id mismatch."); return(View(model)); } var service = CreateRoomService(); if (!await service.UpdateRoomAsync(model)) { ModelState.AddModelError("", "Could not update room."); return(View(model)); } return(RedirectToAction("Index")); } catch { return(View(model)); } }
// GET: Room/Edit/5 public async Task <ActionResult> Edit(int roomId) { var service = CreateRoomService(); var room = await service.GetRoomByIdAsync(roomId); var model = new RoomEdit { Id = room.Id, HotelId = room.HotelId, RoomNumber = room.RoomNumber, NumOfBeds = room.NumOfBeds }; return(View(model)); }