示例#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();
            }
        }
示例#2
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();
        }
示例#3
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();
        }
示例#4
0
        public static void Add(IncomeDTO income)
        {
            DB db = new DB();

            try
            {
                Income IncomeDAL = new Income();
                IncomeDAL = IncomeConvert.DTOtoDAL(income);
                db.Incoms.Add(IncomeDAL);
                FundBL.AddBalance((int)income.Amount);

                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString() + ' ' + income.ToString());
            }
        }
示例#5
0
 public static void cancelExpenditure(int ExpenditureId)
 {
     try
     {
         using (SuperGmachEntities db = new SuperGmachEntities())
         {
             Expenditure expenditure = db.Expenditure.FirstOrDefault(ex => ex.Id == ExpenditureId);
             if (expenditure == null)
             {
                 throw new Exception("expenditure not found");
             }
             expenditure.NameStatus = "canceled";
             FundBL.AddBalance(expenditure.Amount);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#6
0
 static public void AddExpenditure(ExpenditureDTO Expenditure)
 {
     using (SuperGmachEntities db = new SuperGmachEntities())
     {
         try
         {
             Expenditure e = ExpenditureConvert.TDOtoDAL(Expenditure);
             db.Expenditure.Add(e);
             //fundId 1 is for the main fund
             if (Expenditure.NameStatus == "performed")
             {
                 FundBL.Subtract_Balance(Expenditure.Amount, "1");
             }
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
示例#7
0
 public static void updateExpenditure(ExpenditureDTO expenditure)
 {
     using (SuperGmachEntities db = new SuperGmachEntities())
     {
         try
         {
             Expenditure update_expenditure = db.Expenditure.FirstOrDefault(e => e.Id == expenditure.Id);
             if (update_expenditure != null)
             {
                 update_expenditure.Amount = expenditure.Amount;
                 update_expenditure.Date   = expenditure.Date;
                 //update_expenditure.future_date = expenditure.future_date;
                 update_expenditure.Purpose  = expenditure.Purpose;
                 update_expenditure.Receives = expenditure.Receives;
                 ///chack if its became performed
                 if (expenditure.NameStatus != update_expenditure.NameStatus)
                 {
                     if (expenditure.NameStatus == "performed")
                     {
                         FundBL.Subtract_Balance(expenditure.Amount);
                     }
                     else
                     {
                         ///check if it was performed and change to canceled
                         if (expenditure.NameStatus == "canceled" && update_expenditure.NameStatus == "performed")
                         {
                             FundBL.AddBalance(expenditure.Amount);
                         }
                     }
                     update_expenditure.NameStatus = expenditure.NameStatus;
                 }
                 db.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
示例#8
0
        public static void AddDeposit(DepositDTO deposit)
        {
            DB db = new SuperGmachEntities();

            try
            {
                Deposit deposit_DAL = new Deposit();
                deposit_DAL = DepositConvert.DTOtoDAL(deposit);
                // System.Console.WriteLine(deposit+" DAL/n "+deposit_DAL);
                db.Deposits.Add(deposit_DAL);
                User user = db.Users.FirstOrDefault();
                db.SaveChanges();
                user.Scoring = (int)((int)user.Scoring + deposit.Amount * 0.5);
                User_in_fund user_In_Fund = db.UserInFunds.FirstOrDefault(u => u.UserId == deposit.UserId && u.FundId == deposit.FundId);
                user_In_Fund.balance += deposit.Amount;
                FundBL.AddBalance((int)deposit.Amount, deposit.FundId);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }