public ActionResult Edit(Guid? id) { //var model = new ProductBrandDTO(); var model = new ProductBrandViewModel(); if (id.HasValue) { var p = _productBrandRepository.GetById(id.Value); if (p != null) { model.Code = p.Code; model.Description = p.Description; model.Name = p.Name; model.SupplierMasterId = p.Supplier.Id; } // model = _masterDataToDtoMapping.Map(p); model.MasterId = id.Value; } DropDowns(); if (model.MasterId == Guid.Empty) model.MasterId = Guid.NewGuid(); return View(model); }
public ActionResult Edit(ProductBrandViewModel model) { try { //var entity = _dtoToEntityMapping.Map(model); var entity = Map(model); var vri = _productBrandRepository.Validate(entity); if (vri.IsValid) { _productBrandRepository.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++; } DropDowns(); return View(model); } TempData["msg"] = "Product Brand Added successfully"; return RedirectToAction("Index"); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); DropDowns(); return View(model); } }
private ProductBrand Map(ProductBrandViewModel model) { var productBrand = new ProductBrand(model.MasterId); productBrand.Code = model.Code; productBrand.Name = model.Name; productBrand.Supplier = _supplierRepository.GetById(model.SupplierMasterId); productBrand.Description = model.Description; return productBrand; }