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 void Add(Category category) { using (var db = new DBContext()) { try { db.Categories.Add(category); db.SaveChanges(); } catch (System.Data.Entity.Infrastructure.DbUpdateException) { throw new Repositories.Exceptions.CategoryAlreadyExistsException(); } } }