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