// GET: /ProductMaster/Edit/5 public ActionResult Edit(int id) { Dimension4 D1 = _Dimension4Service.Find(id); Dimension4ViewModel pt = Mapper.Map <Dimension4, Dimension4ViewModel>(D1); if (pt == null) { return(HttpNotFound()); } ViewBag.id = pt.ProductTypeId; ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName; if (pt.ProductTypeId != null) { var settings = new ProductTypeSettingsService(_unitOfWork).GetProductTypeSettingsForDocument((int)pt.ProductTypeId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "ProductTypeSettings", new { id = id }).Warning("Please create Product Type Settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } pt.ProductTypeSettings = Mapper.Map <ProductTypeSettings, ProductTypeSettingsViewModel>(settings); } return(View("Create", pt)); }
// GET: /ProductMaster/Create public ActionResult Create(int id)//ProductType Id { Dimension4ViewModel vm = new Dimension4ViewModel(); vm.IsActive = true; vm.ProductTypeId = id; ViewBag.id = id; ViewBag.Name = new ProductTypeService(_unitOfWork).Find(id).ProductTypeName; var settings = new ProductTypeSettingsService(_unitOfWork).GetProductTypeSettingsForDocument(id); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "ProductTypeSettings", new { id = id }).Warning("Please create Product Type Settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } vm.ProductTypeSettings = Mapper.Map <ProductTypeSettings, ProductTypeSettingsViewModel>(settings); return(View("Create", vm)); }
public ActionResult Post(Dimension4ViewModel vm) { Dimension4 pt = Mapper.Map <Dimension4ViewModel, Dimension4>(vm); if (ModelState.IsValid) { if (vm.Dimension4Id <= 0) { pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; _Dimension4Service.Create(pt); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); ViewBag.id = vm.ProductTypeId; ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId ?? 0).ProductTypeName; return(View("Create", vm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Dimension4).DocumentTypeId, DocId = pt.Dimension4Id, ActivityType = (int)ActivityTypeContants.Added, })); return(RedirectToAction("Create", new { id = vm.ProductTypeId }).Success("Data saved successfully")); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); Dimension4 temp = _Dimension4Service.Find(pt.Dimension4Id); Dimension4 ExRec = Mapper.Map <Dimension4>(temp); temp.Dimension4Name = pt.Dimension4Name; temp.IsActive = pt.IsActive; temp.Description = pt.Description; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; _Dimension4Service.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); ViewBag.id = pt.ProductTypeId; ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName; return(View("Create", pt)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Dimension4).DocumentTypeId, DocId = temp.Dimension4Id, ActivityType = (int)ActivityTypeContants.Modified, xEModifications = Modifications, })); ViewBag.id = pt.ProductTypeId; ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName; return(RedirectToAction("Index", new { id = pt.ProductTypeId }).Success("Data saved successfully")); } } ViewBag.id = vm.ProductTypeId; ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId ?? 0).ProductTypeName; return(View("Create", vm)); }