public ActionResult Edit(int id) { RoomTypeDto type = _roomTypeCrudService.Get(id); RoomTypeDetailsVm model = _mapper.Map <RoomTypeDetailsVm>(type); model.AvailableConveniences = new MultiSelectList(_convenienceCrudService.GetAll(), "Id", "Name", type.Conveniences); return(View("Details", model)); }
public ActionResult Create() { RoomTypeDetailsVm model = new RoomTypeDetailsVm(); model.AvailableConveniences = new SelectList(_convenienceCrudService.GetAll(), "Id", "Name"); return(View("Details", model)); }
public ActionResult Create(RoomTypeDetailsVm model, HttpPostedFileBase image) { if (!ModelState.IsValid) { model.AvailableConveniences = new SelectList(_convenienceCrudService.GetAll(), "Id", "Name"); return(View("Details", model)); } RoomTypeDto type = _mapper.Map <RoomTypeDto>(model); type.PathToImage = "/Content/img/" + image.FileName; image.SaveAs(Server.MapPath(type.PathToImage)); _roomTypeCrudService.Create(type); return(RedirectToAction("List")); }
public ActionResult Edit(RoomTypeDetailsVm model) { if (!ModelState.IsValid) { model.AvailableConveniences = new SelectList(_convenienceCrudService.GetAll(), "Id", "Name"); return(View("Details", model)); } RoomTypeDto type = _mapper.Map <RoomTypeDto>(model); if (model.Image != null) { type.PathToImage = "/Content/img/" + model.Image.FileName; var directory = Directory.CreateDirectory(Server.MapPath("/Content/img")); directory.Create(); model.Image.SaveAs(Server.MapPath(type.PathToImage)); FileInfo file = directory.EnumerateFiles().FirstOrDefault(x => x.Name == model.Name); } _roomTypeCrudService.Update(type); return(RedirectToAction("List")); }