Пример #1
0
        //private function
        private tblLoanRequest LoanRequestCalculation(LoanRequestNewDTO loanRequestDTO, tblLoanRequest loanRequest)
        {
            var interestRate = 0;

            switch (loanRequestDTO.payDay)
            {
            case 10:
                interestRate             = 10;
                loanRequest.loan_PayDate = DateTime.Now.AddDays(10);
                break;

            case 20:
                interestRate             = 15;
                loanRequest.loan_PayDate = DateTime.Now.AddDays(15);
                break;

            case 30:
                interestRate             = 30;
                loanRequest.loan_PayDate = DateTime.Now.AddDays(30);
                break;

            default:
                interestRate = 0;
                break;
            }
            loanRequest.loan_InterestRate   = interestRate;
            loanRequest.loan_InterestAmount = Decimal.Parse((loanRequestDTO.amount * interestRate / 100).ToString());
            loanRequest.loan_LoanAmount     = Decimal.Parse((Decimal.Parse(loanRequestDTO.amount.ToString()) + loanRequest.loan_InterestAmount).ToString());

            return(loanRequest);
        }
Пример #2
0
        //-> 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));
        }
Пример #3
0
        public async Task <JsonResult> RequestLoan_Post(LoanRequestNewDTO loanRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new HttpException((int)HttpStatusCode.BadRequest, ConstantHelper.KEY_IN_REQUIRED_FIELD);
                }

                Response.StatusCode = 200;
                var account = await handler.CreateLoanRequest(loanRequest, Request);

                return(Json(account.acct_AccountID, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                if (ex.Message == ConstantHelper.ALREADY_REQUEST_LOAN ||
                    ex.Message == ConstantHelper.KEY_IN_REQUIRED_FIELD ||
                    ex.Message == ConstantHelper.INVALID_PIN ||
                    ex.Message == ConstantHelper.PIN_EXPIRED)
                {
                    Response.StatusCode = 400;
                }
                else
                {
                    Response.StatusCode = 500;
                }
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
Пример #4
0
        public async Task <JsonResult> LoanRequest(LoanRequestNewDTO loanRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new HttpException((int)HttpStatusCode.BadRequest, ConstantHelper.KEY_IN_REQUIRED_FIELD);
                }

                Response.StatusCode = 200;
                return(Json(await handler.Create(loanRequest), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                if (ex.Message == ConstantHelper.ALREADY_REQUEST_LOAN || ex.Message == ConstantHelper.KEY_IN_REQUIRED_FIELD)
                {
                    Response.StatusCode = 410;
                }
                else
                {
                    Response.StatusCode = 500;
                }
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
Пример #5
0
 public async Task <IHttpActionResult> Create(LoanRequestNewDTO newDTO)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         return(Ok(await handler.CreateLoanRequest(newDTO)));
     }
     catch (HttpException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #6
0
        //-> CreateLoanRequest
        public async Task <AccountViewDTO> CreateLoanRequest(LoanRequestNewDTO loanRequestDTO, HttpRequestBase Request)
        {
            var account = await db.tblAccounts.FirstOrDefaultAsync(a => a.acct_Deleted == null && a.acct_AccountID == loanRequestDTO.accountID);

            if (account == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "NotFound");
            }
            var loan = db.tblLoanRequests.FirstOrDefault(x => x.loan_AccountID == loanRequestDTO.accountID &&
                                                         x.loan_Status.ToLower() != "rejected" && x.loan_Status.ToLower() != "approve" && x.loan_Balance > 0);

            if (loan != null)
            {
                throw new HttpException(_ErrorCode, ConstantHelper.ALREADY_REQUEST_LOAN);
            }
            //-- need to uncomment this statement
            var tblPin = db.tblPins.FirstOrDefault(x => x.pins_AccountID == account.acct_AccountID &&
                                                   x.pins_isUsed == null && x.pins_Name == loanRequestDTO.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);
                }
            }
            tblPin.pins_isUsed = "Y";
            await DocumentUpload(Request, loanRequestDTO);



            loanRequestDTO = StringHelper.TrimStringProperties(loanRequestDTO);
            var loanRequest = await SaveToLoanRequest(
                loanRequestDTO.payDay,
                loanRequestDTO.amount,
                loanRequestDTO.accountID,
                loanRequestDTO.loan_Purpose);

            await db.Entry(loanRequest).ReloadAsync();

            sendmail(loanRequest, account);
            return(await SelectByID(int.Parse(loanRequest.loan_AccountID.ToString())));
        }
Пример #7
0
        /*
         * //-> Create
         * public async Task<LoanRequestViewDTO> Create(LoanRequestNewDTO newDTO)
         * {
         *  var record = await db.tblAccounts.FirstOrDefaultAsync(x => x.deleted == null && x.id == newDTO.accountID);
         *  if (record == null)
         *      throw new HttpException((int)HttpStatusCode.BadRequest, "This account has been deleted or does not exsit");
         *
         *  if (record.status == "Pending")
         *      throw new HttpException((int)HttpStatusCode.BadRequest, ConstantHelper.ALREADY_REQUEST_LOAN);
         *
         *  newDTO = StringHelper.TrimStringProperties(newDTO);
         *  var loanRequest = await new AccountHandler().SaveToLoanRequest(newDTO, newDTO.accountID);
         *  return await SelectByID(loanRequest.id);
         * }
         */

        public async Task <LoanRequestViewDTO> CreateLoanRequest(LoanRequestNewDTO loanRequestDTO)
        {
            var account = await db.tblAccounts.FirstOrDefaultAsync(a => a.deleted == null && a.id == loanRequestDTO.accountID);

            if (account == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "NotFound");
            }

            var loan = db.tblLoanRequests.FirstOrDefault(x => x.accountID == loanRequestDTO.accountID &&
                                                         x.status != "rejected" && x.status != "approve" && x.loan_Balance > 0);

            if (loan != null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, ConstantHelper.ALREADY_REQUEST_LOAN);
            }

            var tblPin = db.tblPins.FirstOrDefault(x => x.accountID == account.id &&
                                                   x.isUsed == null && x.name == loanRequestDTO.pin);

            if (tblPin == null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, ConstantHelper.INVALID_PIN);
            }
            else
            {
                if (DateTime.Now.Subtract(tblPin.date.Value).Minutes > 3)
                {
                    throw new HttpException((int)HttpStatusCode.BadRequest, ConstantHelper.PIN_EXPIRED);
                }
            }

            tblPin.isUsed = "Y";

            loanRequestDTO = StringHelper.TrimStringProperties(loanRequestDTO);
            var loanRequest = await SaveToLoanRequest(
                loanRequestDTO.payday,
                loanRequestDTO.amount,
                loanRequestDTO.accountID,
                loanRequestDTO.purpose);

            return(await SelectByID(int.Parse(loanRequest.id.ToString())));
        }
Пример #8
0
        private async Task <bool> DocumentUpload(HttpRequestBase Request, LoanRequestNewDTO loanRequestDTO)
        {
            List <sm_doc> documents = await DocumentHelper.SaveUploadFiles(db, ConstantHelper.TABLE_ACCOUNT_ID, loanRequestDTO.accountID, Request);// tmp not useful , just reserve data for using in the furture

            IQueryable <sm_doc> query = from d in db.sm_doc
                                        where d.docs_Deleted == null && d.docs_TableID == ConstantHelper.TABLE_ACCOUNT_ID && d.docs_Value == loanRequestDTO.accountID.ToString()
                                        orderby d.docs_docID
                                        select d;

            List <sm_doc> records = await query.Take(3).ToListAsync();

            int id = 0;

            if (loanRequestDTO.idCard_change == 1)
            {
                id = records[0].docs_docID;
                var tmp = await db.sm_doc.FirstOrDefaultAsync(x => x.docs_Deleted == null && x.docs_docID == id);

                tmp.docs_Deleted = "1";
                await db.SaveChangesAsync();
            }

            if (loanRequestDTO.employmentLetter_change == 1)
            {
                id = records[1].docs_docID;
                var tmp = await db.sm_doc.FirstOrDefaultAsync(x => x.docs_Deleted == null && x.docs_docID == id);

                tmp.docs_Deleted = "1";
                await db.SaveChangesAsync();
            }

            if (loanRequestDTO.bankAccount_change == 1)
            {
                id = records[2].docs_docID;
                var tmp = await db.sm_doc.FirstOrDefaultAsync(x => x.docs_Deleted == null && x.docs_docID == id);

                tmp.docs_Deleted = "1";
                await db.SaveChangesAsync();
            }

            return(true);
        }