public int Add(Expense expense) { using (var db = new DBContext()) { db.Categories.Attach(expense.Category); db.Expenses.Add(expense); db.SaveChanges(); return expense.ExpenseId; } }
public int Add(Expense expense) { if (!Expenses.ContainsKey(expense.Category)) { throw new CategoryDoesNotExistException(); } Random rnd = new Random(); int id = 0; do { id = (int) rnd.Next(1, 10000); } while (Expenses[expense.Category].ContainsKey(id) == true); Expenses[expense.Category].Add(id, expense); return id; }
public void Remove(Expense expense) { throw new NotImplementedException(); }