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()); } }
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; } }
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; } } }
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; } }