//-> Create First Time : no account created yet public async Task <AccountViewDTO> Create(AccountNewDTO accountDTO, HttpRequestBase Request) { using (var transaction = db.Database.BeginTransaction()) { try { var tblPin = db.tblPins.FirstOrDefault(x => x.pins_Phone == accountDTO.acct_PhoneNumber && x.pins_isUsed == null && x.pins_Name == accountDTO.pin); if (tblPin == null) { throw new HttpException(_ErrorCode, ConstantHelper.INVALID_PIN); } else { if (DateTime.Now.Subtract(tblPin.pins_Date.Value).Minutes > 3) { throw new HttpException(_ErrorCode, ConstantHelper.PIN_EXPIRED); } } tblAccount eAcc = db.tblAccounts.FirstOrDefault(x => x.acct_PhoneNumber.Trim() == accountDTO.acct_PhoneNumber.Trim()); if (eAcc != null) { throw new HttpException(_ErrorCode, ConstantHelper.PHONE_EXIST); } eAcc = db.tblAccounts.FirstOrDefault(x => x.acct_Email.Trim() == accountDTO.acct_Email.Trim()); if (eAcc != null) { throw new HttpException(_ErrorCode, ConstantHelper.EMAIL_EXIST); } tblPin.pins_isUsed = "Y"; accountDTO = StringHelper.TrimStringProperties(accountDTO); var account = (tblAccount)MappingHelper.MapDTOToDBClass <AccountNewDTO, tblAccount>(accountDTO, new tblAccount()); account.acct_CreatedDate = DateTime.Now; account.acct_Status = "Pending"; db.tblAccounts.Add(account); await db.SaveChangesAsync(); List <sm_doc> documents = await DocumentHelper.SaveUploadFiles(db, ConstantHelper.TABLE_ACCOUNT_ID, account.acct_AccountID, Request);// tmp not useful , just reserve data for using in the furture accountDTO.acct_AccountID = account.acct_AccountID; var loanRequest = await SaveToLoanRequest(accountDTO); transaction.Commit(); await db.Entry(loanRequest).ReloadAsync(); sendmail(loanRequest, account); return(await SelectByID(account.acct_AccountID)); } catch (Exception ex) { transaction.Rollback(); throw new Exception(ex.Message); } } }
//-> Create public async Task <LoanRequestViewDTO> Create(LoanRequestNewDTO loanRequestDTO) { IQueryable <tblLoanRequest> loanRequestQuery = from l in db.tblLoanRequests where l.loan_Deleted == null select l; int countLoanRequest = await loanRequestQuery.CountAsync(); if (countLoanRequest > 1) { throw new HttpException((int)HttpStatusCode.BadRequest, ConstantHelper.ALREADY_REQUEST_LOAN); } loanRequestDTO = StringHelper.TrimStringProperties(loanRequestDTO); var loanRequest = (tblLoanRequest)MappingHelper.MapDTOToDBClass <LoanRequestNewDTO, tblLoanRequest>(loanRequestDTO, new tblLoanRequest()); loanRequest.loan_CreatedDate = DateTime.Now; loanRequest.loan_PayDate = DateTime.Now; loanRequest.loan_Status = "Pending"; //loanRequest.loanAmount = Decimal.Parse((LoanRequestCalculation(loanRequestDTO)).ToString()); loanRequest = LoanRequestCalculation(loanRequestDTO, loanRequest); db.tblLoanRequests.Add(loanRequest); await db.SaveChangesAsync(); db.Entry(loanRequest).Reload(); return(await SelectByID(loanRequest.loan_LoanRequestID)); }