public static bool AddBook(string title, long? isbn, Authors authors, double? price, string url, Reviews reviews) { var b = CreateBookHeader(title, isbn, price, url); b.Authors = GetAuthors(authors); b.Reviews = GetReviews(reviews); SessionState.dbBookstore.Books.Add(b); try { SessionState.dbBookstore.SaveChanges(); } catch (DbEntityValidationException exception) { SessionState.dbBookstore.Books.Remove(b); Console.WriteLine("Validation error. Book Title or Author Name is too long or just missing for book with ISBN: " + isbn); return false; } return true; }
public static ICollection<Model.Review> GetReviews(Reviews reviews) { var result = new List<Model.Review>(); if (reviews != null) { reviews.reviews.ForEach(r => { var review = new Review(); review.Author = BookstoreDAL.GetAuthor(r.Author); if (r.Text.StartsWith("\n")) { review.Text = r.Text.Remove(0, 2).Trim(); } else { review.Text = r.Text; } if (r.CreatDate == null) { review.CreatDate = DateTime.Now; } else { review.CreatDate = DateTime.Parse(r.CreatDate); } result.Add(review); }); } return result; }