コード例 #1
0
 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();
     }
 }
コード例 #2
0
 public void AddBook(Book book)
 {
     using (var context = new LibraryContext())
     {
         book.isDeleted = false;
         context.Books.Add(book);
         context.SaveChanges();
     }
 }
コード例 #3
0
 public static BookDomainModel Create(Book book)
 {
     return new BookDomainModel
     {
         Id = book.Id,
         Title = book.Title,
         IsBorrowed = book.IsBorrowed,
         GenreId = book.GenreId,
         UserId = book.UserId
     };
 }
コード例 #4
0
 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();
     }
 }