public ActionResult NewAccessory(int id) { var viewModel = new NewAccessoryViewModel(); viewModel.Room = _unitOfWork.RoomRepository.Find(id); return(View(viewModel)); }
public ActionResult NewAccessory(NewAccessoryViewModel viewModel) { try { var accessory = new Accessory { Name = viewModel.Name, Description = viewModel.Description }; var room = _unitOfWork.RoomRepository.Find(viewModel.Room.ID); room.Accessories.Add(accessory); _unitOfWork.SaveChanges(); } catch (Exception ex) { logger.Error(ex, ex.Message); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("~/Views/PartialViews/Error.cshtml", ex.Message)); } return(RedirectToAction("Index", "Room")); }