public ActionResult Post(Reason pt) { if (ModelState.IsValid) { if (pt.ReasonId <= 0) { pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; _ReasonService.Create(pt); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View("Create", pt)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Reason).DocumentTypeId, DocId = pt.ReasonId, ActivityType = (int)ActivityTypeContants.Added, })); return(RedirectToAction("Create").Success("Data saved successfully")); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); Reason temp = _ReasonService.Find(pt.ReasonId); Reason ExRec = Mapper.Map <Reason>(temp); temp.ReasonName = pt.ReasonName; temp.DocumentCategoryId = pt.DocumentCategoryId; temp.IsActive = pt.IsActive; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; _ReasonService.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); return(View("Create", pt)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Reason).DocumentTypeId, DocId = temp.ReasonId, ActivityType = (int)ActivityTypeContants.Modified, xEModifications = Modifications, })); return(RedirectToAction("Index").Success("Data saved successfully")); } } PrepareViewBag(); return(View("Create", pt)); }