// [Authorize] public HttpResponseMessage ValidationChecks(TellerPostingDto tellerPostingDto) { if (CheckIfCustomerAccountIsClosed(tellerPostingDto.CustomerAccountId) == true) { errorMessage = errorMessage + "Customer Account is Closed"; } if (tellerPostingDto.PostingType == "Withdrawal") { if (!CheckCustomerAccountBalance(tellerPostingDto.CustomerAccountId, tellerPostingDto.Amount)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); } if (!CheckTillBalance(tellerPostingDto.Amount)) { errorMessage = errorMessage + "Insufficient Till Account Balance"; } } if (!errorMessage.Equals("")) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); } return(Request.CreateResponse(HttpStatusCode.OK, "Proceed")); }
// [Authorize] public HttpResponseMessage AddTellerPosting(TellerPostingDto tellerPostingDto) { var businessStatus = _context.BusinessStatus.SingleOrDefault(); var customerAccountStatus = _context.CustomerAccounts .SingleOrDefault(c => c.Id == tellerPostingDto.CustomerAccountId).IsClosed; var userId = _context.Users.SingleOrDefault(c => c.Email.Equals(RoleName.EMAIL)).Id; var teller = _context.Tellers.SingleOrDefault(c => c.UserTellerId.Equals(userId)); if (teller != null) { var tellerId = teller.Id; tellerPostingDto.TellerId = tellerId; if (businessStatus.Status == false) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, CBA.BUSINESS_CLOSED_REFRESH_MSG)); } if (customerAccountStatus == true) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Customer Account is <b>CLOSED</b>")); } tellerPostingDto.TransactionDate = DateTime.Now; var tellerPosting = new TellerPosting(); tellerPosting = Mapper.Map <TellerPostingDto, TellerPosting>(tellerPostingDto); _context.TellerPostings.Add(tellerPosting); _context.SaveChanges(); EnforceDoubleEntry(tellerPostingDto.Amount, tellerPosting.CustomerAccountId, tellerPostingDto.PostingType); var financialReportDto = new FinancialReportDto(); financialReportDto.PostingType = "Teller Posting"; if (tellerPostingDto.PostingType == "Deposit") { financialReportDto.CreditAccount = GetCustomerAccountName(tellerPostingDto.CustomerAccountId); financialReportDto.CreditAmount = tellerPostingDto.Amount; financialReportDto.DebitAccount = GetTillAccountName(); financialReportDto.DebitAmount = tellerPostingDto.Amount; } else { financialReportDto.DebitAccount = GetCustomerAccountName(tellerPostingDto.CustomerAccountId); financialReportDto.DebitAmount = tellerPostingDto.Amount; financialReportDto.CreditAccount = GetTillAccountName(); financialReportDto.CreditAmount = tellerPostingDto.Amount; } financialReportDto.ReportDate = DateTime.Now; if (!errorMessage.Equals("")) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); } CBA.AddReport(financialReportDto); return(Request.CreateResponse(HttpStatusCode.OK, "Teller Posted Successfully")); } errorMessage = "You have not been assigned a Till Account"; return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); }