public Borrowing Create(string bookTitle, string accountName) { // TODO Should be dependency injection here 2x var dbBookService = new DbBookService(Database); var book = dbBookService.Read(bookTitle); var dbAccountService = new DbAccountService(Database); var account = dbAccountService.Read(accountName); if (Database.BorrowingsTbl.Any(x => x.BookId == book.Id)) { return(null); } else { var borrowing = new Borrowing { WhenBorrowed = DateTime.Now }; book.Borrowings.Add(borrowing); account.BooksBorrowed.Add(borrowing); Database.SaveChanges(); return(borrowing); } }
public void Create(string bookTitle, string categoryDescription, string accountName) { // TODO Should be dependency injection here 3x var dbBookService = new DbBookService(Database); var book = dbBookService.Read(bookTitle); var dbCathegoryService = new DbCategoryServices(Database); var category = dbCathegoryService.Read(categoryDescription); var dbAccountService = new DbAccountService(Database); var account = dbAccountService.Read(accountName); var bookCat = new BookCategory { When = DateTime.Now, Who = account }; book.BelongsToCatgegories.Add(bookCat); category.BooksBelongsToCategory.Add(bookCat); Database.SaveChanges(); }