public IActionResult RateLoan(int loanId)
        {
            //Create loan review object to pass to view
            LoanRating loanRating = new LoanRating();

            //find current user

            User currentUser = CurrentUser();

            //assign current user to LoanRating object
            loanRating.currentUser = currentUser;

            //find loan in database
            Loan loanToRate = _libraryDB.Loans.Find(loanId);

            loanRating.loan = loanToRate;

            //find book for bookInfo
            Book     book    = _libraryDB.Books.Find(loanToRate.BookId);
            BookInfo apibook = _libraryDAL.GetBookInfo(book.TitleIdApi);

            loanRating.ApiBook = apibook;


            return(View(loanRating));
        }
        public IActionResult Transactions()
        {
            User currentUser = CurrentUser();

            TempData["CurrentUser"] = currentUser.Id;

            // grab all loans user is involved in, both sides
            List <Loan> userLoans = _libraryDB.Loans.Where(x => x.BookLoaner == currentUser.Id || x.BookOwner == currentUser.Id).ToList();
            //-------
            List <LoanRating> userLoansMoreInfo = new List <LoanRating>();

            foreach (Loan loan in userLoans)
            {
                //Create loan review object to pass to view
                LoanRating l = new LoanRating();

                //assign current user to LoanRating object
                l.currentUser = currentUser;
                l.loan        = loan;

                //find book for bookInfo
                Book     book    = _libraryDB.Books.Find(loan.BookId);
                BookInfo apibook = _libraryDAL.GetBookInfo(book.TitleIdApi);
                l.ApiBook = apibook;

                if (loan.BookOwner == currentUser.Id)
                {
                    l.otherUser = _libraryDB.Users.Find(loan.BookLoaner);
                }
                else
                {
                    l.otherUser = _libraryDB.Users.Find(loan.BookOwner);
                }

                l.otherEmail = _libraryDB.AspNetUsers.Find(l.otherUser.UserId).UserName;
                userLoansMoreInfo.Add(l);
            }



            return(View(userLoansMoreInfo));
        }
示例#3
0
        public Response Add(LoanRating value)
        {
            Response response = new Response();

            try
            {
                using (IDbConnection conn = GetConnection())
                {
                    conn.Insert(value);
                    response.Status      = true;
                    response.Description = "Successful";
                }
            }
            catch (Exception ex)
            {
                response.Status      = false;
                response.Description = ex.Message;
            }
            return(response);
        }
 public Response Put([FromBody] LoanRating value)
 {
     return(repo.Update(value));
 }
 public Response Post([FromBody] LoanRating value)
 {
     return(repo.Add(value));
 }
示例#6
0
        public Response ApproveTask(UpdateLoanStatus value)
        {
            Response response = new Response();
            string   sql      = string.Empty;

            if (value.LoanStatus.Contains("Approved"))
            {
                sql = "UPDATE mortgageloanapplication SET LoanStatus = ?LoanStatus, ApprovedDate = NOW() Where MortgageLoanID = ?MortgageLoanID";
            }
            else
            {
                sql = "UPDATE mortgageloanapplication SET LoanStatus = ?LoanStatus Where MortgageLoanID = ?MortgageLoanID";
            }

            using (IDbConnection conn = GetConnection())
            {
                if (value.LoanStatus.Contains("Approved"))
                {
                    conn.Open();
                    var tran = conn.BeginTransaction();
                    try
                    {
                        var mortgage = conn.Get <MortgageLoanApplication>(value.MortgageLoanID);
                        if (mortgage == null)
                        {
                            return new Response()
                                   {
                                       Status = false, Description = "MortgageLoanID does not exist"
                                   }
                        }
                        ;
                        var banks          = conn.Get <Bank>(mortgage.BankID);
                        var status         = conn.Get <LoanStatuses>(4);
                        var paymentstatute = conn.Get <PaymentStatutes>(5);
                        var loan           = new Loans()
                        {
                            DateApproved      = mortgage.ApprovedDate.HasValue ? mortgage.ApprovedDate.Value : DateTime.Now,
                            DateCreated       = DateTime.Now,
                            LoanAmount        = Convert.ToDecimal(mortgage.AmountBorrowed),
                            LoanBuyerStatus   = "No Action",
                            LoanBuyerStatusID = 1,
                            LoanDate          = mortgage.LoanDate.Value,
                            LoanStatus        = status.LoanStatus,
                            MortgageBank      = banks.BankName,
                            TitleHolder       = mortgage.FullName,
                            PropertyID        = long.Parse(mortgage.ProID),
                            UserID            = mortgage.UserID,
                            MortgageBankID    = long.Parse(mortgage.BankID),
                            Timeline          = long.Parse(mortgage.Paymentterms),
                            PerformanceRating = 100M,
                            Repayments        = long.Parse(mortgage.Paymentterms),
                            LoanStatusID      = status.LoanStatusID,
                            PaymentStatuteID  = paymentstatute.PaymentStatuteID,
                            PaymentStatute    = paymentstatute.PaymentStatute,
                            Score             = 100M,
                            ApplicationID     = mortgage.ApplicationID,
                            MortgageType      = mortgage.MortgageType
                        };
                        var     loanID = conn.Insert(loan);
                        decimal rate   = decimal.Parse("100.00");
                        var     rating = new LoanRating()
                        {
                            LoanID     = loanID.Value,
                            Rating     = rate,
                            RatingDesc = "Performing"
                        };
                        conn.Insert(rating);
                        var loanDocs = conn.GetList <MorgageLoanDocs>("Where MortgageLoanID = ?MortgageLoanID", new { value.MortgageLoanID }).AsList();
                        loanDocs.ForEach(item =>
                        {
                            var loandoc = new LoanDoc()
                            {
                                DocDesc    = item.DocsDesc,
                                DocLink    = item.DocsLink,
                                DocName    = item.DocsName,
                                LoanID     = loanID.Value,
                                MortgageId = value.MortgageLoanID
                            };
                            conn.Insert(loandoc);
                        });
                        // insert into repayment history
                        var     uus            = conn.Get <UUSBanks>(loan.MortgageBankID);
                        decimal totalrepayment = loan.LoanAmount * (1 + ((uus.InterestRate / 100) * (loan.Timeline / 12)));
                        decimal monthly        = totalrepayment / loan.Timeline;
                        int     duration       = 0;
                        while (duration < loan.Timeline)
                        {
                            duration++;

                            var repayment = new RepaymentHistory()
                            {
                                InterestRate = uus.InterestRate,
                                //Amount = monthly,
                                Amount = 0M,
                                LoanID = loanID.Value,
                                //Outstanding = totalrepayment - (monthly * duration),
                                Outstanding     = monthly,
                                Repayment       = "Unpaid",
                                DueDate         = loan.LoanDate.AddMonths(duration).ToLongDateString(),
                                TransactionDate = loan.LoanDate.AddMonths(duration)
                            };
                            conn.Insert(repayment);
                        }
                        var req = new UpdateLoanStatus2()
                        {
                            ApprovedDate   = mortgage.ApprovedDate.HasValue ? mortgage.ApprovedDate.Value : DateTime.Now,
                            LoanStatus     = value.LoanStatus,
                            MortgageLoanID = value.MortgageLoanID
                        };
                        conn.Execute(sql, req);
                        response.Status      = true;
                        response.Description = "Successful";
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        response.Status      = false;
                        response.Description = ex.Message;
                    }
                }
                else
                {
                    conn.Execute(sql, value);
                    response.Status      = true;
                    response.Description = "Successful";
                }
            }
            return(response);
        }