public ActionResult Post(Dimension1 vm) { Dimension1 pt = vm; if (ModelState.IsValid) { if (vm.Dimension1Id <= 0) { pt.IsActive = true; pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; try { _Dimension1Service.Create(pt); } catch (Exception ex) { ViewBag.Mode = "Add"; string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View("Create", vm)); } _logger.LogActivityDetail(logVm.Map(new ActiivtyLogViewModel { DocTypeId = Constants.DocumentTypeIdConstants.Dimension1, DocId = pt.Dimension1Id, ActivityType = (int)ActivityTypeContants.Added, })); return(RedirectToAction("Create", new { id = vm.ProductTypeId }).Success("Data saved successfully")); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); Dimension1 temp = _Dimension1Service.Find(pt.Dimension1Id); Dimension1 ExRec = Mapper.Map <Dimension1>(temp); temp.Dimension1Name = pt.Dimension1Name; temp.IsActive = pt.IsActive; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = _modificationCheck.CheckChanges(LogList); try { _Dimension1Service.Update(temp); } catch (Exception ex) { ViewBag.Mode = "Edit"; string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View("Create", pt)); } _logger.LogActivityDetail(logVm.Map(new ActiivtyLogViewModel { DocTypeId = Constants.DocumentTypeIdConstants.Dimension1, DocId = temp.Dimension1Id, ActivityType = (int)ActivityTypeContants.Modified, xEModifications = Modifications, })); return(RedirectToAction("Index", new { id = vm.ProductTypeId }).Success("Data saved successfully")); } } return(View("Create", vm)); }
public ActionResult Post(Dimension1ViewModel vm) { Dimension1 pt = Mapper.Map <Dimension1ViewModel, Dimension1>(vm); if (ModelState.IsValid) { if (vm.Dimension1Id <= 0) { pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; _Dimension1Service.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.Dimension1).DocumentTypeId, DocId = pt.Dimension1Id, ActivityType = (int)ActivityTypeContants.Added, })); return(RedirectToAction("Create", new { id = vm.ProductTypeId }).Success("Data saved successfully")); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); Dimension1 temp = _Dimension1Service.Find(pt.Dimension1Id); Dimension1 ExRec = Mapper.Map <Dimension1>(temp); temp.Dimension1Name = pt.Dimension1Name; temp.IsActive = pt.IsActive; temp.Description = pt.Description; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; _Dimension1Service.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.Dimension1).DocumentTypeId, DocId = temp.Dimension1Id, 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)); }