Beispiel #1
0
 /// <summary>
 /// Add new book into BookStorage
 /// </summary>
 /// <param name="book"> Book to add </param>
 public void Add(Book book)
 {
     if (book != null)
     {
         var results = new List <ValidationResult>();
         var context = new ValidationContext(book);
         if (!Validator.TryValidateObject(book, context, results, true))
         {
             foreach (var error in results)
             {
                 Console.WriteLine(error.ErrorMessage);
             }
         }
         else
         {
             if (!_db.Books.Contains(book))
             {
                 _db.Add(book);
             }
             else
             {
                 throw new ArgumentException("Duplicated book!");
             }
         }
     }
 }