private static void SendReminder(CreditLineLoan loan, DateTime now, string userName) { var amountToPay = Money.Zero; var deadline = DateTime.MinValue; if (loan.FinalDeadline.Date == now.AddDays(-2).Date&& loan.Loaned > loan.Repaid) { amountToPay = loan.Loaned - loan.Repaid; deadline = loan.FinalDeadline; } else if (loan.SecondDeadline.Date == now.AddDays(-2).Date&& loan.AmounBeforeSecondDeadline > loan.Repaid) { amountToPay = loan.AmounBeforeSecondDeadline - loan.Repaid; deadline = loan.SecondDeadline; } else if (loan.FirstDeadline.Date == now.AddDays(-2).Date&& loan.AmounBeforeFirstDeadline > loan.Repaid) { amountToPay = loan.AmounBeforeFirstDeadline - loan.Repaid; deadline = loan.FirstDeadline; } if (amountToPay > Money.Zero && deadline > DateTime.MinValue) { string email = string.Format(U5006.CREDITLINEREMINDEREMAIL, userName, amountToPay.ToString(), deadline.Date.ToShortDateString(), AppSettings.Site.Name); Mailer.SendCreditLineRemainderEmail(email, userName); } }
public override void DataBind() { Button1.Text = U5007.BORROW; base.DataBind(); CreditLineLoan loan = CreditLineManager.GetUsersLoans(user.Id, false).FirstOrDefault(); if (loan == null) { RepayBorrowDescriptionLiteral.Text = string.Format(U5007.MAXBORROW, CreditLineManager.GetMaxPossibleRequest(user).ToString()); BorrowButton.Visible = true; BorrowButton.Text = U5007.BORROW; RepayButton.Visible = false; RepayPlaceHolder.Visible = false; } else { RepayPlaceHolder.Visible = true; RepayBorrowDescriptionLiteral.Text = string.Format(U5007.CANTBORROWUNTIL, loan.Loaned - loan.Repaid); FirstDateLiteral.Text = loan.FirstDeadline.ToShortDateString(); SecondDateLiteral.Text = loan.SecondDeadline.ToShortDateString(); FinalDateLiteral.Text = loan.FinalDeadline.ToShortDateString(); FirstRepayLiteral.Text = loan.AmounBeforeFirstDeadline.ToString(); SecondRepayLiteral.Text = loan.AmounBeforeSecondDeadline.ToString(); FinalRepayLiteral.Text = loan.Loaned.ToString(); RepayButton.Visible = true; RepayButton.Text = U5007.PAYBACK; BorrowButton.Visible = false; RepayPlaceHolder.Visible = true; } }
public static void AcceptRequest(int creditLineRequestId) { Money maxLoan = GlobalPool.Get(PoolsHelper.GetBuiltInProfitPoolId(Pools.CreditLine)).SumAmount; CreditLineRequest request = new CreditLineRequest(creditLineRequestId); if (request.LoanRequested > maxLoan) { request.Status = CreditLineRequestStatus.Rejected; request.Save(); throw new MsgException("There is not enough money in the pool. The request has been rejected."); } request.Status = CreditLineRequestStatus.Accepted; request.Save(); Member user = new Member(request.UserId); DateTime now = AppSettings.ServerTime; CreditLineLoan loan = new CreditLineLoan(); loan.UserId = user.Id; loan.Loaned = request.LoanRequested; loan.FirstDeadline = now.AddDays(AppSettings.CreditLine.FirstDeadlineDays); loan.SecondDeadline = now.AddDays(AppSettings.CreditLine.SecondDeadlineDays); loan.FinalDeadline = now.AddDays(AppSettings.CreditLine.FinalDeadlineDays); loan.AmounBeforeFirstDeadline = Money.MultiplyPercent(request.LoanRequested, AppSettings.CreditLine.FirstRepayPercent); loan.AmounBeforeSecondDeadline = Money.MultiplyPercent(request.LoanRequested, AppSettings.CreditLine.SecondRepayPercent); loan.BorrowDate = now; loan.Repaid = Money.Zero; loan.Save(); var moneyWithoutFee = Money.MultiplyPercent(request.LoanRequested, 100 - AppSettings.CreditLine.Fee); GlobalPoolManager.SubtractFromPool(PoolsHelper.GetBuiltInProfitPoolId(Pools.CreditLine), moneyWithoutFee); user.AddToPurchaseBalance(moneyWithoutFee, "Credit Line", BalanceLogType.CreditLine); user.SaveBalances(); Mailer.SendNewCreditLineMessage(user.Email, request.LoanRequested); }