public void MakeSubscription(Book book, string userId, bool isToTheLibrary) { using (var context = new LibraryContext()) { DateTime returnDate; if (isToTheLibrary) { returnDate = DateTime.Today; } else { returnDate = DateTime.Today.AddDays(14); } context.InSubscriptions.Add(new InSubscription { ISBN = book.ISBN, IsInUse = true, UserId = userId, DateOfReceipt = DateTime.Today, ReturnDate = returnDate }); book.Quantity -= 1; EditBook(book); context.SaveChanges(); } }
public void AddBook(Book book) { using (var context = new LibraryContext()) { book.isDeleted = false; context.Books.Add(book); context.SaveChanges(); } }
public static BookDomainModel Create(Book book) { return new BookDomainModel { Id = book.Id, Title = book.Title, IsBorrowed = book.IsBorrowed, GenreId = book.GenreId, UserId = book.UserId }; }
public void EditBook(Book book) { using (var context = new LibraryContext()) { var original = context.Books.Find(book.ISBN); context.Entry(original).CurrentValues.SetValues(book); context.SaveChanges(); } }