public ActionResult DeleteConfirmed(ReasonViewModel vm) { if (ModelState.IsValid) { Person person = new PersonService(_unitOfWork).Find(vm.id); BusinessEntity businessentiry = _BusinessEntityService.Find(vm.id); Agent Agent = _AgentService.Find(vm.id); ActivityLog al = new ActivityLog() { ActivityType = (int)ActivityTypeContants.Deleted, CreatedBy = User.Identity.Name, CreatedDate = DateTime.Now, DocId = vm.id, UserRemark = vm.Reason, Narration = "Agent is deleted with Name:" + person.Name, DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.SaleOrder).DocumentTypeId, UploadDate = DateTime.Now, }; new ActivityLogService(_unitOfWork).Create(al); //Then find all the Person Address associated with the above Person. PersonAddress personaddress = _PersonAddressService.GetShipAddressByPersonId(vm.id); _PersonAddressService.Delete(personaddress.PersonAddressID); IEnumerable <PersonContact> personcontact = new PersonContactService(_unitOfWork).GetPersonContactIdListByPersonId(vm.id); //Mark ObjectState.Delete to all the Person Contact For Above Person. foreach (PersonContact item in personcontact) { new PersonContactService(_unitOfWork).Delete(item.PersonContactID); } IEnumerable <PersonBankAccount> personbankaccount = new PersonBankAccountService(_unitOfWork).GetPersonBankAccountIdListByPersonId(vm.id); //Mark ObjectState.Delete to all the Person Contact For Above Person. foreach (PersonBankAccount item in personbankaccount) { new PersonBankAccountService(_unitOfWork).Delete(item.PersonBankAccountID); } // Now delete the Parent Agent _AgentService.Delete(Agent); _BusinessEntityService.Delete(businessentiry); new PersonService(_unitOfWork).Delete(person); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(PartialView("_Reason", vm)); } return(Json(new { success = true })); } return(PartialView("_Reason", vm)); }
public ActionResult DeleteConfirmed(ReasonViewModel vm) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); if (ModelState.IsValid) { Person person = new PersonService(_unitOfWork).Find(vm.id); BusinessEntity businessentiry = _BusinessEntityService.Find(vm.id); JobWorker jobworker = _JobWorkerService.Find(vm.id); LogList.Add(new LogTypeViewModel { ExObj = person, }); LogList.Add(new LogTypeViewModel { ExObj = businessentiry, }); LogList.Add(new LogTypeViewModel { ExObj = jobworker, }); //Then find Ledger Account associated with the above Person. LedgerAccount ledgeraccount = _AccountService.GetLedgerAccountFromPersonId(vm.id); _AccountService.Delete(ledgeraccount.LedgerAccountId); //Then find all the Person Address associated with the above Person. PersonAddress personaddress = _PersonAddressService.GetShipAddressByPersonId(vm.id); _PersonAddressService.Delete(personaddress.PersonAddressID); IEnumerable <PersonContact> personcontact = new PersonContactService(_unitOfWork).GetPersonContactIdListByPersonId(vm.id); //Mark ObjectState.Delete to all the Person Contact For Above Person. foreach (PersonContact item in personcontact) { new PersonContactService(_unitOfWork).Delete(item.PersonContactID); } IEnumerable <PersonBankAccount> personbankaccount = new PersonBankAccountService(_unitOfWork).GetPersonBankAccountIdListByPersonId(vm.id); //Mark ObjectState.Delete to all the Person Contact For Above Person. foreach (PersonBankAccount item in personbankaccount) { new PersonBankAccountService(_unitOfWork).Delete(item.PersonBankAccountID); } IEnumerable <PersonProcess> personProcess = new PersonProcessService(_unitOfWork).GetPersonProcessIdListByPersonId(vm.id); //Mark ObjectState.Delete to all the Person Process For Above Person. foreach (PersonProcess item in personProcess) { new PersonProcessService(_unitOfWork).Delete(item.PersonProcessId); } IEnumerable <PersonRegistration> personregistration = new PersonRegistrationService(_unitOfWork).GetPersonRegistrationIdListByPersonId(vm.id); //Mark ObjectState.Delete to all the Person Registration For Above Person. foreach (PersonRegistration item in personregistration) { new PersonRegistrationService(_unitOfWork).Delete(item.PersonRegistrationID); } // Now delete the Parent JobWorker _JobWorkerService.Delete(jobworker); _BusinessEntityService.Delete(businessentiry); new PersonService(_unitOfWork).Delete(person); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(PartialView("_Reason", vm)); } LogActivity.LogActivityDetail(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocCategoryConstants.JobWorker).DocumentTypeId, DocId = vm.id, ActivityType = (int)ActivityTypeContants.Deleted, UserRemark = vm.Reason, User = User.Identity.Name, DocNo = person.Name, xEModifications = Modifications }); return(Json(new { success = true })); } return(PartialView("_Reason", vm)); }