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(); }
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(); } }
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(); } }
public static List <LoanDTO> GetByUser(int idUser) { db Sgmach = new db(); List <LoanDTO> loans = new List <LoanDTO> (); List <Loan> loansUser = Sgmach.Loans.Where(loan => loan.UserId == idUser).ToList(); return(loans); }
public static WithdrawalsDTO GetById(int id) { WithdrawalsDTO withdrawalsDTO = new WithdrawalsDTO(); db DB = new db(); var withdrawal = DB.Withdrawing.FirstOrDefault(w => w.Id == id); withdrawalsDTO = WithdrawalsConvert.DALtoDTO(withdrawal); return(withdrawalsDTO); }
public static RepaymentsDTO getRepaymentById(int id) { db DB = new db(); Repayments repyment = DB.Repayments.FirstOrDefault(r => r.RepaymentId == id); User user = DB.Users.FirstOrDefault(u => u.UserId == repyment.UserId); RepaymentsDTO repaymentDTO = RepaymentConvert.DALtoDTO(repyment); repaymentDTO.UserName = user.firstName + " " + user.lastname; return(repaymentDTO); }
public static List <FundDTO> GetList() { DB db = new DB(); List <FundDTO> list = new List <FundDTO>(); foreach (Fund fund in db.Funds) { list.Add(FundConvert.DALtoDTO(fund)); } return(list); }
public static List <LoanDTO> GetAll() { db Sgmach = new db(); List <LoanDTO> loans = new List <LoanDTO>(); foreach (Loan loan in Sgmach.Loans) { loans.Add(LoanConvert.DALtoDTO(loan)); } return(loans); }
public static List <WithdrawalsDTO> GetAll() { List <WithdrawalsDTO> withdrawalsDTOs = new List <WithdrawalsDTO>(); db DB = new db(); List <withdrawing> withdrawals = DB.Withdrawing.ToList(); foreach (withdrawing withdrawal in withdrawals) { withdrawalsDTOs.Add(WithdrawalsConvert.DALtoDTO(withdrawal)); } return(withdrawalsDTOs); }
public static LoanDTO GetByID(int LoanId) { db Sgmach = new db(); Loan loan = Sgmach.Loans.FirstOrDefault(l => l.LoanId == LoanId); LoanDTO loanDTO = LoanConvert.DALtoDTO(loan); List <Repayments> Repayments = Sgmach.Repayments.Where(r => r.LoanId == LoanId).ToList(); foreach (var Repayment in Repayments) { loanDTO.Repayments.Add(RepaymentConvert.DALtoDTO(Repayment)); } return(loanDTO); }
public ActionResult Get() { DpositsANDwithdrawals DW = new DpositsANDwithdrawals(); db db = new db(); for (int i = 0; i < 12; i++) { var thisYear = DateTime.Today.Year; DW.withdrawals[i] = db.Withdrawing.Where(withdrawal => withdrawal.Date.Month == (i + 1) && withdrawal.Date.Year == thisYear).Sum(withdrawal => withdrawal.Amount); DW.deposits[i] = db.Deposits.Where(deposit => deposit.Date.Month == (i + 1) && deposit.Date.Year == thisYear).Sum(deposit => deposit.Amount); } return(Ok(DW)); }
public ActionResult getExpnditureANDdeposits() { ExpnditureANDincoms expnditureANDincoms = new ExpnditureANDincoms(); db db = new db(); for (int i = 0; i < 12; i++) { var thisYear = DateTime.Today.Year; expnditureANDincoms.incoms[i] = db.Incoms.Where(incom => incom.Date.Month == (i + 1) && incom.Date.Year == thisYear).Sum(incom => incom.Amount); expnditureANDincoms.expnditure[i] = db.Expenditure.Where(ex => ex.Date.Month == (i + 1) && ex.Date.Year == thisYear).Sum(ex => ex.Amount); } return(Ok(expnditureANDincoms)); }
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(); }
public static List <RepaymentsDTO> GetAll() { List <RepaymentsDTO> repyments = new List <RepaymentsDTO>(); db DB = new db(); foreach (var repyment in DB.Repayments) { var r = RepaymentConvert.DALtoDTO(repyment); User user = DB.Users.FirstOrDefault(u => u.UserId == r.UserId); r.UserName = user.firstName + " " + user.lastname; repyments.Add(r); } return(repyments); }
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(); }
public static List <WithdrawalsDTO> GetByUser(int userId) { List <WithdrawalsDTO> withdrawalsDTOs = new List <WithdrawalsDTO>(); db DB = new db(); List <withdrawing> withdrawals = DB.Withdrawing.Where(w => w.UserId == userId).ToList(); foreach (withdrawing withdrawal in withdrawals) { WithdrawalsDTO withdrawalDTO = WithdrawalsConvert.DALtoDTO(withdrawal); withdrawalDTO.Fund = DB.Funds.FirstOrDefault(f => f.FundId == withdrawal.FundId).fund_name; withdrawalsDTOs.Add(withdrawalDTO); } return(withdrawalsDTOs); }
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(); }
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(); }
public static int GetFutureBalance(string idFund, DateTime FutureDate) { List <Expenditure> expenditures = new List <Expenditure>(); List <Income> incomes = new List <Income>(); List <withdrawing> withdrawings = new List <withdrawing>(); // List<Deposit> deposits = new List<Deposit>(); List <Repayments> repayments = new List <Repayments>(); List <Loan> loans = new List <Loan>(); int FutureBalance = 0; int FuturIncomes = 0; int FutureExpenditures = 0; int FutureWithdrawals = 0; DB Sgmach = new DB(); var Today = DateTime.Today; if (idFund == "1") { expenditures = Sgmach.Expenditure.Where(e => e.Date < FutureDate && e.NameStatus == "future").ToList(); incomes = Sgmach.Incoms.Where(i => i.Date <FutureDate && i.Date> Today).ToList(); // loans = Sgmach.Loans.Where(l => (FutureDate > l. && l.date_start > Today)).ToList(); repayments = Sgmach.Repayments.Where(r => FutureDate > r.Date && r.Date > Today && r.NameStatus != "performed").ToList(); } withdrawings = Sgmach.Withdrawing.Where(w => w.FundId == idFund && w.Date < FutureDate && w.NameStatus != "performed").ToList(); foreach (Income income in incomes) { FuturIncomes += income.Amount; } foreach (Expenditure ex in expenditures) { FutureExpenditures += ex.Amount; } foreach (Loan loan in loans) { FutureWithdrawals += loan.Amount; } foreach (Repayments repayment in repayments) { FuturIncomes += (int)repayment.Amount; } Fund fund = Sgmach.Funds.FirstOrDefault(f => f.FundId == idFund); FutureBalance = (int)fund.Balance; FutureBalance += FuturIncomes; FutureBalance -= (FutureWithdrawals + FutureExpenditures); return(FutureBalance); }
public static FundDTO GetById(string id) { FundDTO Fund = new FundDTO(); DB db = new DB(); foreach (Fund fund in db.Funds) { if (fund.FundId == id) { Fund = FundConvert.DALtoDTO(fund); Fund.Futurbalance = GetFutureBalance(id, DateTime.Now.AddMonths(1)); return(Fund); } } return(null); }
public static List <WithdrawalsDTO> GetByFund(string FundId) { List <WithdrawalsDTO> withdrawalsDTOs = new List <WithdrawalsDTO>(); db DB = new db(); List <withdrawing> withdrawals = DB.Withdrawing.Where(w => w.FundId == FundId).ToList(); foreach (withdrawing withdrawal in withdrawals) { WithdrawalsDTO withdrawalDTO = WithdrawalsConvert.DALtoDTO(withdrawal); // User_in_fund User= DB.User_in_fund.FirstOrDefault(u => u.userID == withdrawal.UserId); // withdrawalDTO.User = UserBL.Get_user_byFund(FundId, withdrawal.UserId); withdrawalsDTOs.Add(withdrawalDTO); } return(withdrawalsDTOs); }
static public void SetScore(LoanDTO Loan) { db Sgmach = new db(); int score = 0; User user = Sgmach.Users.FirstOrDefault(u => u.UserId == Loan.id_user); if (user == null) { throw new Exception("user didnt fund"); } score = score + (int)user.Scoring; if (Loan.amount < 30000) { score = score + 10; } Loan.Score = score; }
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(); } }
public static List <LoanDTO> GetAll() { db Sgmach = new db(); List <LoanDTO> loans = new List <LoanDTO> (); foreach (Loan loan in Sgmach.Loans) { LoanDTO loanDTO = LoanConvert.DALtoDTO(loan); if (loan.NameManagement_status == "Unauthorized") { var Today = DateTime.Now; var monthWait = ((Today.Year - loan.EnteryDate.Year) * 12) - loan.EnteryDate.Month + Today.Month; loanDTO.Score = monthWait * 10; } loans.Add(loanDTO); } return(loans); }
public static double Balance(int loanId) { double balance = 0; db SGmach = new db(); Loan loan = SGmach.Loans.FirstOrDefault(l => l.LoanId == loanId); if (loan == null || loan.NameManagement_status == "performed") { return(0); } List <Repayments> repayments = SGmach.Repayments.Where(r => r.LoanId == loanId && r.NameStatus == "future").ToList(); foreach (var payment in repayments) { balance += payment.Amount; } return(balance); }
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(); } }
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; } }
public static List <UserDTO> GetUsersToAdd(string fundId) { List <UserDTO> users = new List <UserDTO>(); //List<User> usersDAL = new List<User>(); DB Sgmach = new DB(); Fund fund = Sgmach.Funds.FirstOrDefault(f => f.FundId == fundId); DateTime Today = DateTime.Today; //usersDAL = Sgmach.Users.Where(u =>u.joining_date.GetValueOrDefault().AddMonths((int)fund.required_months) <= Today //&&(fund.required_vip==true&&u.VIP==true||fund.required_vip==false)).ToList(); var query = from u in Sgmach.Users where (u.joining_date.AddMonths((int)fund.required_months)) <= Today where !(from uf in Sgmach.UserInFunds where uf.FundId == fund.FundId select uf.UserId).Contains(u.UserId) select u; foreach (User user in query) { users.Add(Userconvert.DALtoDTO(user)); } return(users); }
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; } }
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(); }