// GET: /ProductMaster/Edit/5 public ActionResult Edit(int id) { Dimension3 D1 = _Dimension3Service.Find(id); Dimension3ViewModel pt = Mapper.Map <Dimension3, Dimension3ViewModel>(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 { Dimension3ViewModel vm = new Dimension3ViewModel(); 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(Dimension3ViewModel vm) { Dimension3 pt = Mapper.Map <Dimension3ViewModel, Dimension3>(vm); if (ModelState.IsValid) { if (vm.Dimension3Id <= 0) { pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; _Dimension3Service.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.Dimension3).DocumentTypeId, DocId = pt.Dimension3Id, ActivityType = (int)ActivityTypeContants.Added, })); return(RedirectToAction("Create", new { id = vm.ProductTypeId }).Success("Data saved successfully")); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); Dimension3 temp = _Dimension3Service.Find(pt.Dimension3Id); Dimension3 ExRec = Mapper.Map <Dimension3>(temp); temp.Dimension3Name = pt.Dimension3Name; temp.IsActive = pt.IsActive; temp.Description = pt.Description; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; _Dimension3Service.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; TempData["CSEXC"] += message; return(View("Create", vm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Dimension3).DocumentTypeId, DocId = temp.Dimension3Id, 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)); }