public ActionResult Edit(int?id) { if (id == null || id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var mapperConfig = new MapperConfiguration(cfg => { cfg.CreateMap <BoatDTO, BoatEditViewModel>(); }); try { using (var boatService = new BoatService()) { var boatList = boatService.EagerDisconnectedService.FindBy(x => x.Id == id); if (boatList == null) { return(HttpNotFound()); } var boat = new BoatEditViewModel(); var mapper = mapperConfig.CreateMapper(); mapper.Map(boatList.First(), boat); return(View(boat)); } } catch (Exception e) { TempData["ResultMessage"] = e.Message; return(View("Error")); } }
public ActionResult Edit(BoatEditViewModel boatEditViewModel) //TODO Kolla i databas om det sparas { if (ModelState.IsValid) { try { //BoatDTO boat = new BoatDTO(); //var mapperConfig = new MapperConfiguration(cfg => cfg.CreateMap<BoatEditViewModel, BoatDTO>()); //var mapper = mapperConfig.CreateMapper(); //mapper.Map(boatEditViewModel, boat); //using (var boatService = new BoatService()) //{ // boatService.EagerDisconnectedService.Update(boat); //} } catch (Exception e) { TempData["ResultMessage"] = e.Message; return(View("Error")); } } return(View("Index")); }