public async Task <IActionResult> Edit(RoomEditViewModel model) { if (!ModelState.IsValid) { //Redefine the roomtypes to prevent crashing model.RoomTypes = WebConstants.RoomTypes.Select(item => new TypePair() { Id = WebConstants.RoomTypes.IndexOf(item), Type = item }).ToList(); return(View(model)); } string roomType; try { roomType = WebConstants.RoomTypes[model.SelectedRoomType]; } catch (ArgumentOutOfRangeException) { //If an unexisting index was passed, prompt the user to re-enter the form model.RoomTypes = WebConstants.RoomTypes.Select(item => new TypePair() { Id = WebConstants.RoomTypes.IndexOf(item), Type = item }).ToList(); return(View(model)); } await _roomRepository.AddOrUpdate(new Room() { Id = model.Id, Capacity = model.Capacity, Type = roomType, AdultBedPrice = model.AdultBedPrice, ChildBedPrice = model.ChildBedPrice, RoomNumber = model.RoomNumber, IsAvailable = model.IsAvailable }); return(RedirectToAction("Index")); }