public BeneficiaryPaymentRegRespObj DeleteBeneficiaryPayment(DeleteBeneficiaryAccountTransactionObj regObj) { var response = new BeneficiaryPaymentRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage() } }; try { if (regObj.Equals(null)) { response.Status.Message.FriendlyMessage = "Error Occurred! Unable to proceed with your request"; response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid"; return(response); } if (!EntityValidatorHelper.Validate(regObj, out var valResults)) { var errorDetail = new StringBuilder(); if (!valResults.IsNullOrEmpty()) { errorDetail.AppendLine("Following error occurred:"); valResults.ForEachx(m => errorDetail.AppendLine(m.ErrorMessage)); } else { errorDetail.AppendLine("Validation error occurred! Please check all supplied parameters and try again"); } response.Status.Message.FriendlyMessage = errorDetail.ToString(); response.Status.Message.TechnicalMessage = errorDetail.ToString(); response.Status.IsSuccessful = false; return(response); } if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, new[] { "PortalAdmin", "CRMAdmin", "CRMManager" }, ref response.Status.Message)) { return(response); } var thisBeneficiaryAccTrans = GetBeneficiaryAccTransactionInfo(regObj.BeneficiaryAccTransId); if (thisBeneficiaryAccTrans == null) { response.Status.Message.FriendlyMessage = "No Beneficiary Payment Information found for the specified BeneficiaryPayment Id"; response.Status.Message.TechnicalMessage = "No Beneficiary Payment Information found!"; return(response); } thisBeneficiaryAccTrans.Status = Status.Deleted; var deleteBenAccTrans = _beneAccTransRepository.Update(thisBeneficiaryAccTrans); _uoWork.SaveChanges(); if (deleteBenAccTrans.BeneficiaryAccountTransactionId < 1) { response.Status.Message.FriendlyMessage = "Error Occurred! Unable to complete your request. Please try again later"; response.Status.Message.TechnicalMessage = "Unable to save to database"; return(response); } response.Status.IsSuccessful = true; response.PaymentId = deleteBenAccTrans.BeneficiaryAccountTransactionId; response.Status.Message.FriendlyMessage = "Deleted Successfully"; } catch (DbEntityValidationException ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); response.Status.Message.FriendlyMessage = "Error Occurred! Please try again later"; response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message; response.Status.IsSuccessful = false; return(response); } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); response.Status.Message.FriendlyMessage = "Error Occurred! Please try again later"; response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message; response.Status.IsSuccessful = false; return(response); } return(response); }
public BeneficiaryPaymentRegRespObj AddBeneficiaryPayment(RegBeneficiaryPaymentObj regObj) { var response = new BeneficiaryPaymentRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage() } }; try { if (regObj.Equals(null)) { response.Status.Message.FriendlyMessage = "Error Occurred! Unable to proceed with your request"; response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid"; return(response); } if (!EntityValidatorHelper.Validate(regObj, out var valResults)) { var errorDetail = new StringBuilder(); if (!valResults.IsNullOrEmpty()) { errorDetail.AppendLine("Following error occurred:"); valResults.ForEachx(m => errorDetail.AppendLine(m.ErrorMessage)); } else { errorDetail.AppendLine("Validation error occurred! Please check all supplied parameters and try again"); } response.Status.Message.FriendlyMessage = errorDetail.ToString(); response.Status.Message.TechnicalMessage = errorDetail.ToString(); response.Status.IsSuccessful = false; return(response); } if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getRequesterRoles(), ref response.Status.Message)) { return(response); } var associatedBeneficiary = GetBeneficiaryInfo(regObj.BeneficiaryId); if (associatedBeneficiary == null) { response.Status.Message.FriendlyMessage = "Ooops ! Beneficiary Does not Exist!"; response.Status.Message.TechnicalMessage = "No Beneficiary Information Found"; return(response); } if (associatedBeneficiary.Status != Status.Active) { response.Status.Message.FriendlyMessage = "Sorry!This Beneficiary Cannot Perform Any Transaction Yet! Please Contact Administrator"; response.Status.Message.TechnicalMessage = "Beneficiary Isn't Approved yet"; return(response); } var associatedBeneAccount = GetBeneficiaryAccountInfo(associatedBeneficiary.BeneficiaryAccountId); if (associatedBeneAccount == null) { response.Status.Message.FriendlyMessage = "Ooops ! Beneficiary Account Does not Exist!"; response.Status.Message.TechnicalMessage = "No Beneficiary Account Information Found"; return(response); } if (!string.IsNullOrWhiteSpace(regObj.PaymentReference)) { if (DataCheck.IsNumeric(regObj.PaymentReference)) { response.Status.Message.FriendlyMessage = "Error Occurred! Payment reference must be Numbers Only"; response.Status.Message.TechnicalMessage = "Payment Reference is invalid"; return(response); } var associatedBenPayment = GetBeneficiaryPayment(new SettingSearchObj { Status = -2 }); if (associatedBenPayment.Any()) { if (associatedBenPayment.FindAll(payment => payment.PaymentReference == regObj.PaymentReference) .Any()) { response.Status.Message.FriendlyMessage = "Error Occurred! Payment reference is Invalid"; response.Status.Message.TechnicalMessage = "Duplicate Error! Payment Reference is Invalid!"; return(response); } } } //store date for Concurrency... var nowDateTime = DateMap.CurrentTimeStamp(); var nowDate = nowDateTime.Substring(0, nowDateTime.IndexOf(' ')); var nowTime = nowDateTime.Substring(nowDateTime.IndexOf('-') + 1); using (var db = _uoWork.BeginTransaction()) { #region Beneficiary Account Transaction Operation var newBeneficiaryTransaction = new BeneficiaryAccountTransaction { BeneficiaryAccountId = associatedBeneAccount.BeneficiaryAccountId, BeneficiaryId = regObj.BeneficiaryId, Amount = regObj.AmountPaid, PreviousBalance = associatedBeneAccount.AvailableBalance, NewBalance = (associatedBeneAccount.AvailableBalance + regObj.AmountPaid), TransactionSource = TransactionSourceType.Account_TopUp, TransactionType = TransactionType.Credit, Status = Status.Active, RegisteredBy = regObj.AdminUserId, TimeStampRegistered = nowDateTime, }; var transactionAdded = _beneAccTransRepository.Add(newBeneficiaryTransaction); _uoWork.SaveChanges(); if (transactionAdded.BeneficiaryAccountTransactionId < 1) { db.Rollback(); response.Status.Message.FriendlyMessage = "Error Occurred! Unable to complete your request. Please try again later"; response.Status.Message.TechnicalMessage = "Unable to save to database"; return(response); } #endregion #region Beneficiary Payment Operation var newBeneficiaryPayment = new BeneficiaryPayment { BeneficiaryId = regObj.BeneficiaryId, BeneficiaryAccountId = associatedBeneAccount.BeneficiaryAccountId, PaymentDate = regObj.PaymentDate, PaymentReference = regObj.PaymentReference, PaySource = (PaySource)regObj.PaySource, PaymentSourceName = ((PaySource)regObj.PaySource).ToString().Replace("_", " "), RegisteredBy = regObj.AdminUserId, TimeStampRegistered = nowDateTime, Status = Status.Active, AmountPaid = regObj.AmountPaid, BeneficiaryAccountTransactionId = transactionAdded.BeneficiaryAccountTransactionId, }; var paymentAdded = _repositiory.Add(newBeneficiaryPayment); _uoWork.SaveChanges(); if (paymentAdded.BeneficiaryPaymentId < 1) { db.Rollback(); response.Status.Message.FriendlyMessage = "Error Occurred! Unable to complete your request. Please try again later"; response.Status.Message.TechnicalMessage = "Unable to save to database"; return(response); } #endregion #region Beneficiary Account Update associatedBeneAccount.AvailableBalance = transactionAdded.NewBalance; associatedBeneAccount.CreditLimit = 0; associatedBeneAccount.LastTransactionAmount = transactionAdded.Amount; associatedBeneAccount.LastTransactionType = transactionAdded.TransactionType; associatedBeneAccount.Status = Status.Active; associatedBeneAccount.LastTransactionId = transactionAdded.BeneficiaryAccountTransactionId; associatedBeneAccount.LastTransactionTimeStamp = DateMap.CurrentTimeStamp(); var updateBeneAccount = _beneAccRepository.Update(associatedBeneAccount); _uoWork.SaveChanges(); if (updateBeneAccount.BeneficiaryAccountId < 1) { db.Rollback(); response.Status.Message.FriendlyMessage = "Error Occurred! Unable to complete your request. Please try again later"; response.Status.Message.TechnicalMessage = "Unable to save to database"; return(response); } #endregion db.Commit(); response.Status.IsSuccessful = true; response.PaymentId = paymentAdded.BeneficiaryPaymentId; response.Status.Message.FriendlyMessage = "Payment Successful"; } } catch (DbEntityValidationException ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); response.Status.Message.FriendlyMessage = "Error Occurred! Please try again later"; response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message; response.Status.IsSuccessful = false; return(response); } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); response.Status.Message.FriendlyMessage = "Error Occurred! Please try again later"; response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message; response.Status.IsSuccessful = false; return(response); } return(response); }