public ResponseBase CanScrubCustomer(Account account) { var response = new ResponseBase(); // Does account have more than one contract? var contracts = _contractRepository.GetContractsByAccountId(account.Id.Value); var master = account as MasterAccount; if (master != null) { var subAccounts = _accountRepository.GetAllSubAccounts(master.Id.Value); if (subAccounts.Count > 0) { response.IsSuccessful = false; response.Message = "This Account has sub-accounts. Cannot Delete"; return response; } } else { response.IsSuccessful = false; response.Message = "This Account is a sub-account. Cannot Delete"; } if (contracts.Count > 1) { response.IsSuccessful = false; response.Message = "This Customer has multiple Contracts. Cannot Delete."; return response; } response.IsSuccessful = true; return response; }
public ResponseBase ScrubContract(Contract contract) { if (_invoicingService == null) _invoicingService = ServiceFactory.GetService<IInvoicingService>(); // yuk hack var response = new ResponseBase(); if (_invoicingService.HasContractBeenInvoiced(contract)) { response.IsSuccessful = false; response.Message = "This Contract has been invoiced. Cannot scrub data."; return response; } try { LoggingUtility.LogDebug("ScrubContract", "ScrubbingService", string.Format("Scrubbing Contract Number {0}. Phone 1: {1}", contract.ContractNumber, contract.PhoneNumber1)); response.IsSuccessful = _contractRepository.Delete(contract); _importManager.RescanForContracts(); LoggingUtility.LogDebug("ScrubContract", "ScrubbingService", string.Format("Scrubbing completed for Contract Number {0}. Phone 1: {1}", contract.ContractNumber, contract.PhoneNumber1)); } catch (Exception ex) { LoggingUtility.LogException(ex); LoggingUtility.LogDebug("ScrubContract", "ScrubbingService", string.Format("Scrubbing Failed for Contract Number {0}. Phone 1: {1}", contract.ContractNumber, contract.PhoneNumber1)); } return response; }
/// <summary> /// Delete's all evidence of a Customer having been in the sytem. /// </summary> /// <param name="account">Single account to delete</param> public ResponseBase ScrubCustomer(Account account) { if (_invoicingService == null) _invoicingService = ServiceFactory.GetService<IInvoicingService>(); // yuk hack var response = new ResponseBase(); // Does account have more than one contract? var contracts = _contractRepository.GetContractsByAccountId(account.Id.Value); if (contracts.Count == 0) { response.IsSuccessful = false; return response; } response = CanScrubCustomer(account); if (!response.IsSuccessful) return response; // Delete Invoices if (!DeleteInvoices(account)) { response.IsSuccessful = false; response.Message = "Could not delete Invoices"; return response; } // Call normal Scrub Contract return ScrubContract(contracts[0]); }
public ResponseBase MakeInvoiceRoot(int accountId) { var response = new ResponseBase(); var account = _accountRepository.GetAccount(accountId); if (account == null) { response.SetFailure("Could not find Account to updated"); return response; } if (account.IsInvoiceRoot) { response.IsSuccessful = true; return response; } try { account.IsInvoiceRoot = true; if (_accountRepository.UpdateAccount(account)) { account.LogActivity("Dettached from Master Account to be an Invoice Root"); response.IsSuccessful = true; return response; } } catch (Exception ex) { LoggingUtility.LogException(ex); response.SetFailure(Constants.Messages.INTERNAL_ERROR); } return response; }
public ResponseBase ReAttachToMasterAccount(int subAccountId) { var response = new ResponseBase(); var subAccount = _accountRepository.GetAccount(subAccountId); // verify this is an invoice root account if (subAccount is MasterAccount) { response.SetFailure("Cannot add the Master Account as a sub Account of another Account."); return response; } if (!subAccount.IsInvoiceRoot) { response.SetFailure("Accounts that are already sub-accounts cannot be added as a sub-account"); return response; } subAccount.IsInvoiceRoot = false; try { using (var ts = new TransactionScope()) { if (_accountRepository.UpdateAccount(subAccount)) { subAccount.LogActivity("Re-attached as Sub-Account"); response.IsSuccessful = true; } ts.Complete(); } } catch (Exception ex) { LoggingUtility.LogException(ex); response.SetFailure(Constants.Messages.INTERNAL_ERROR); } return response; }
public ResponseBase SaveCustomFee(CustomFee customFee) { var response = new ResponseBase(); try { if (customFee.Id.HasValue) { _customFeeRepository.Update(customFee); } else { _customFeeRepository.Insert(customFee); if (!customFee.Id.HasValue) { response.IsSuccessful = false; response.Message = "Addition of new Custom Fee has failed"; return response; } } response.IsSuccessful = true; } catch (Exception ex) { LoggingUtility.LogException(ex); response.IsSuccessful = false; response.Message = "Could not " + (customFee.Id.HasValue ? "add" : "update") + " the custom fee"; } return response; }
public ResponseBase RemoveCustomFee(CustomFee customFee) { var response = new ResponseBase(); // Check no contracts are using this fee. var contracts = _contractRepository.GetAllContractsWithCustomFee(customFee); if (contracts.Count > 0) { response.IsSuccessful = false; response.Message = "Cannot delete Custom Fees still associated with contracts"; return response; } try { _customFeeRepository.Delete(customFee); response.IsSuccessful = true; } catch (Exception ex) { LoggingUtility.LogException(ex); response.IsSuccessful = false; response.Message = "Could not remove the custom fee"; } return response; }