public ActionResult DeleteConfirmed(ReasonViewModel vm) { if (ModelState.IsValid) { Person person = new PersonService(_unitOfWork).Find(vm.id); BusinessEntity businessentiry = _BusinessEntityService.Find(vm.id); Buyer buyer = _BuyerService.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 = "Buyer is deleted with Name:" + person.Name, DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.SaleOrder).DocumentTypeId, UploadDate = DateTime.Now, }; new ActivityLogService(_unitOfWork).Create(al); //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 buyer _BuyerService.Delete(buyer); _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)); }