public ActionResult Edit(ServiceDTO model) { try { var entity = _dtoToEntityMapping.Map(model); var vri = _serviceRepository.Validate(entity); if (vri.IsValid) { _serviceRepository.Save(entity, true); } else { int i = 1; foreach (ValidationResult error in vri.Results) { TempData["msg"] = string.Format("\n({0}).{1}", i, error.ErrorMessage); ModelState.AddModelError("", error.ErrorMessage); i++; } return View(model); } TempData["msg"] = "Commodity Producer Service Added successfully"; return RedirectToAction("Index"); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return View(model); } }
public CommodityProducerService Map(ServiceDTO dto) { if (dto == null) return null; var s = Mapper.Map<ServiceDTO, CommodityProducerService>(dto); return s; }
public ActionResult Edit(Guid? id) { var model = new ServiceDTO(); if (id.HasValue) { var p = _serviceRepository.GetById(id.Value); if (p != null) model = _masterDataToDtoMapping.Map(p); model.MasterId = id.Value; } if (model.MasterId == Guid.Empty) model.MasterId = Guid.NewGuid(); return View(model); }