public ActionResult DeleteConfirmed(ReasonViewModel vm) { if (ModelState.IsValid) { Person person = new PersonService(_unitOfWork).Find(vm.id); BusinessEntity businessentiry = _BusinessEntityService.Find(vm.id); Courier Courier = _CourierService.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 = "Courier 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); } LedgerAccount LedgerAccount = new LedgerAccountService(_unitOfWork).GetLedgerAccountByPersondId(vm.id); new LedgerAccountService(_unitOfWork).Delete(LedgerAccount); 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 Courier _CourierService.Delete(Courier); _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)); }