public void AddPersonName(string PersonName) { using (var db = new InvestmentdbContext()) { db.Add(new People { Name = PersonName }); db.SaveChanges(); } }
//To update the wrong entry made in Expenditure Table public void Update_Expenditure(int id, float expenditure, string purpose) { using (var db = new InvestmentdbContext()) { var SExpenditure = db.Expenditures.OrderBy(e => e.ExpenditureId); foreach (var Eid in SExpenditure) { if (Eid.ExpenditureId == id) { Eid.ExpenseAmount = expenditure; Eid.PurposeOfExpenditure = purpose; } } db.SaveChanges(); } }
//To update the wrong entry made in Income Table public void Update_Income(int id, float income, string source) { using (var db = new InvestmentdbContext()) { var SIncome = db.Incomes.OrderBy(i => i.IncomeId); foreach (var Iid in SIncome) { if (Iid.IncomeId == id) { Iid.IncomeReceived = income; Iid.SourceOfIncome = source; } } db.SaveChanges(); } }
//to Delete Wrong Expenditure public void Delete_Expenditure(int id) { using (var db = new InvestmentdbContext()) { var queryIncome = db.Expenditures.OrderBy(i => i.ExpenditureId); foreach (var Eid in queryIncome) { if (Eid.ExpenditureId == id) { db.Remove(Eid); } } db.SaveChanges(); } }
public void Delete_People(int id) { using (var db = new InvestmentdbContext()) { var peopleId = db.Peoples.OrderBy(i => i.PeopleId); foreach (var Pid in peopleId) { if (Pid.PeopleId == id) { db.Remove(Pid); } } db.SaveChanges(); } }
//to Delete Wrong Income public void Delete_Income(int id) { using (var db = new InvestmentdbContext()) { var queryIncome = db.Incomes.OrderBy(i => i.IncomeId); // var fid = (float)id; foreach (var Iid in queryIncome) { if (Iid.IncomeId == id) { db.Remove(Iid); } } db.SaveChanges(); } }
public void AddExpenditure(float amount, string purpose, string name) { if (amount <= 0) { throw new Exception("Invalid input"); } else { using (var db = new InvestmentdbContext()) { var q2 = db.Peoples.Where(p => p.Name == name); foreach (var p in q2) { db.Add(new Expenditure { ExpenseAmount = amount, Day = DateTime.Now, PurposeOfExpenditure = purpose, PeopleId = p.PeopleId }); } db.SaveChanges(); } } }
// Adding entry to database with exception handling public void AddIncome(float amount, string source, string name) { if (amount <= 0) { throw new Exception("Invalid input"); } else { using (var db = new InvestmentdbContext()) { var q1 = db.Peoples.Where(p => p.Name == name); foreach (var p in q1) { db.Add(new Income { IncomeReceived = amount, Day = DateTime.Now, SourceOfIncome = source, PeopleId = p.PeopleId }); } db.SaveChanges(); } } }