Esempio n. 1
0
        public static void Add(LoanDTO loan)
        {
            SetScore(loan);
            db Sgmach = new db();
            //if its Approved
            Loan loanDAL = LoanConvert.DTOtoDAL(loan);

            loanDAL = Sgmach.Loans.Add(loanDAL).Entity;
            Sgmach.SaveChanges();
            if (loan.management_Status == "Approved")
            {
                int FutureBalance = FundBL.GetFutureBalance("1", loan.date_start);
                if (FutureBalance < loan.amount)
                {
                    loanDAL.remark += " יתרת הגמח ביום התחלת הלוואה קטנה מסכום ההלוואה";
                    loanDAL.NameManagement_status = "Invalid";
                }
                else
                {
                    SetRepayment(loanDAL);
                    if (loan.NameStatus == "active")
                    {
                        FundBL.Subtract_Balance(loan.amount);
                    }
                    Sgmach.SaveChanges();
                }
                loan.paid = false;
                // Loan loanDAL = LoanConvert.DTOtoDAL(loan);
                // loanDAL = Sgmach.Loans.Add(loanDAL).Entity;
                Sgmach.SaveChanges();
            }
        }
Esempio n. 2
0
        public static void Add(WithdrawalsDTO withdrawalDTO)
        {
            withdrawing withdrawal = WithdrawalsConvert.DTOtoDAL(withdrawalDTO);
            db          DB         = new db();

            DB.Withdrawing.Add(withdrawal);
            DB.SaveChanges();
            if (withdrawalDTO.Status == "performed")
            {
                FundBL.Subtract_Balance(withdrawalDTO.Amount, withdrawalDTO.FundId);
                User_in_fund user = DB.UserInFunds.FirstOrDefault(u => u.UserId == withdrawal.UserId && u.FundId == withdrawal.FundId);
                user.balance -= withdrawal.Amount;
            }
            DB.SaveChanges();
        }
Esempio n. 3
0
        static private void SetRepayment(Loan loan)
        {
            db Sgmach = new db();
            // DateTime date1 = loan.BeginningRepayment;
            // DateTime date2 = date1.AddMonths(loan.month);
            int c      = loan.Months / loan.Num_payments;
            int amount = loan.Amount / loan.Months;

            for (int i = 0; i <= loan.Num_payments; i = ++i)
            {
                Repayments repayment = new Repayments()
                {
                };

                repayment.Amount = amount;
                if (i == loan.Num_payments)
                {
                    repayment.Amount = loan.Amount - (amount * (loan.Num_payments - 1));
                }
                repayment.Date   = loan.RepaymentStart.AddMonths(i + c);
                repayment.LoanId = loan.LoanId;

                Sgmach.Repayments.Add(repayment);
                Sgmach.SaveChanges();
            }
        }
Esempio n. 4
0
        public static void Update(LoanDTO loan)
        {
            db   Sgmach  = new db();
            Loan loanDAL = Sgmach.Loans.FirstOrDefault(l => l.LoanId == loan.id_loan);

            if (loanDAL == null)
            {
                throw new Exception("loan not found");
            }
            //if it became Approved
            if (loanDAL.NameManagement_status != "Approved" && loan.loan_status == "Approved")
            {
                int FutureBalance = FundBL.GetFutureBalance("1", loan.date_start);
                if (FutureBalance - 2000 < loan.amount)
                {
                    throw new Exception("you can loanding :balance<loan.amount");
                }
                if (FundBL.GetById("0").balance < loan.amount)
                {
                    throw new Exception("you can loanding :balance<loan.amount");
                }
                else
                {
                    SetRepayment(loanDAL);
                }
            }
            // loanDAL.loan_status = loan.loan_status;
            loanDAL.Months         = loan.month;
            loanDAL.RepaymentStart = loan.date_start;
            // loanDAL.paid = loan.paid;
            loanDAL.remark = loan.remark;
            Sgmach.SaveChanges();
        }
Esempio n. 5
0
        public static void Update(LoanDTO loan)
        {
            db   Sgmach  = new db();
            Loan loanDAL = Sgmach.Loans.FirstOrDefault(l => l.LoanId == loan.id_loan);

            loanDAL.Months                = loan.month;
            loanDAL.remark                = loan.remark;
            loanDAL.NameStatus            = loan.NameStatus;
            loanDAL.RepaymentStart        = loan.date_start;
            loanDAL.NameManagement_status = loan.management_Status;
            if (loanDAL == null)
            {
                throw new Exception("loan not found");
            }
            //if it became Approved
            if (loanDAL.NameManagement_status != "Approved" && loan.management_Status == "Approved" && loanDAL.NameStatus != "active")
            {
                if (loan.NameStatus == "future")
                {
                    int FutureBalance = FundBL.GetFutureBalance("1", loan.date_start);
                    if (FutureBalance - 2000 < loan.amount)
                    {
                        loanDAL.remark = "סכום ההלוואה גדול מיתרת הגמח";
                        loanDAL.NameManagement_status = "Invalid";
                    }
                    else
                    {
                        SetRepayment(loanDAL);
                        loanDAL.NameManagement_status = "Approved";
                    }
                }
            }
            else if (loanDAL.NameManagement_status != "Approved" && loan.management_Status == "Approved" && loan.NameStatus == "active")
            {
                loanDAL.NameManagement_status = "Approved";
                loanDAL.NameStatus            = "active";
                loanDAL.RepaymentStart        = DateTime.Today;
                SetRepayment(loanDAL);
            }

            // if the loan become active (the friend get the money) the  fund  Balance have to Subtract
            if (loan.NameStatus == "active" && loanDAL.NameStatus != "active")
            {
                loanDAL.NameStatus     = "active";
                loan.management_Status = "Proper";
                FundBL.Subtract_Balance(loan.amount);
            }

            Sgmach.SaveChanges();
        }
Esempio n. 6
0
        public static void Save(FundDTO fund)
        {
            DB DB = new DB();

            Fund fundDal = DB.Funds.FirstOrDefault(f => f.FundId == fund.Id);

            fundDal.required_vip = fund.required_vip;

            //fundDal.remark= fund.remark;

            fundDal.required_months = fund.Required_months;

            DB.SaveChanges();
        }
Esempio n. 7
0
        public static void Update(RepaymentsDTO repayment)
        {
            db         DB           = new db();
            Repayments repaymentDal = DB.Repayments.FirstOrDefault(r => r.RepaymentId == repayment.Id);

            if (repayment.NameStatus == "performed" && repaymentDal.NameStatus != "performed")
            {
                FundBL.AddBalance(repayment.Amount);
            }
            repaymentDal.Amount     = repayment.Amount;
            repaymentDal.NameStatus = repayment.NameStatus;
            repaymentDal.Date       = repayment.Date;
            // repaymentDal.remark= repayment.Remark;
            DB.SaveChanges();
        }
Esempio n. 8
0
        public static void AddFriends(int[] frinds, string fundID)
        {
            DateTime Today  = DateTime.Now;
            DB       Sgmach = new DB();
            int      Length = frinds.Length;

            for (var i = 0; i < Length; i++)
            {
                User_in_fund user_In_Fund = new User_in_fund();

                user_In_Fund.balance   = 0;
                user_In_Fund.date_join = Today;
                user_In_Fund.FundId    = fundID;
                user_In_Fund.UserId    = frinds[i];
                Sgmach.UserInFunds.Add(user_In_Fund);
                Sgmach.SaveChanges();
            }
        }
Esempio n. 9
0
        public static void Delte(int LoanId)
        {
            db   Sgmach = new db();
            Loan loan   = Sgmach.Loans.FirstOrDefault(l => l.LoanId == LoanId);

            if (loan.NameStatus != "future")
            {
                throw new Exception("ניתן למחוק רק הלוואות שתרם התחילו");
            }
            else
            {
                List <Repayments> repayments = Sgmach.Repayments.Where(r => r.LoanId == LoanId).ToList();
                foreach (var repayment in repayments)
                {
                    Sgmach.Repayments.Remove(repayment);
                }
                Sgmach.Loans.Remove(loan);
                Sgmach.SaveChanges();
            }
        }
Esempio n. 10
0
 public static void Subtract_Balance(int Value, string fundId = "1")
 {
     try
     {
         DB  db   = new DB();
         var fund = db.Funds.FirstOrDefault(f => f.FundId == fundId);
         if (fund != null)
         {
             fund.Balance = fund.Balance - Value;
             db.SaveChanges();
         }
         else
         {
             throw new Exception("fund id not found");
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 11
0
 public static void AddBalance(int Value, string fundId = "1")
 {
     fundId = fundId != null? fundId : "1";
     try
     {
         DB   db   = new DB();
         Fund fund = db.Funds.FirstOrDefault(f => f.FundId == fundId);
         if (fund != null)
         {
             fund.Balance = fund.Balance + Value;
             db.SaveChanges();
             Console.WriteLine(fund.Balance);
         }
         else
         {
             throw new Exception("fund id not found");
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 12
0
        public static void Updete(WithdrawalsDTO withdrawalDTO)
        {
            db          DB         = new db();
            withdrawing withdrawal = DB.Withdrawing.FirstOrDefault(w => w.Id == withdrawalDTO.Id);

            //if it changed to Approved
            if (withdrawal.NameStatus != "performed" && withdrawalDTO.Status == "performed")
            {
                FundBL.Subtract_Balance(withdrawalDTO.Amount, withdrawalDTO.FundId);
            }
            else
            {
                //if it was performed and changed to canceled
                if (withdrawal.NameStatus == "performed" && withdrawalDTO.Status == "canceled")
                {
                    FundBL.AddBalance(withdrawalDTO.Amount, withdrawalDTO.FundId);
                }
            }
            withdrawal.Amount = withdrawalDTO.Amount;
            withdrawal.Date   = withdrawalDTO.Date;
            // withdrawal.paymentMethod = withdrawalDTO.PaymentMethod;
            withdrawal.NameStatus = withdrawalDTO.Status;
            DB.SaveChanges();
        }