public bool Add(BookDetailsBLL item, out string serverSideError)
        {
            //HACK: in manip bar impl, we try to insert a new book before working on it. Better approach possible.
            if (item.Description.Title == null)
                item.Description.Title = "New book";

            if (item.IsValid)
            {
                using (ProtoLibEntities context = new ProtoLibEntities())
                {
                    if (DatabaseDependantValidation(item,context, out serverSideError))
                    {
                        //Good to go.
                        BookDetails newBook = new BookDetails();
                        newBook.BookDimensions = new BookDimensions();
                        CrossLayerEntityConverter.BookDetailsBllToDal(context, item, newBook);
                        context.BookDetailsSet.AddObject(newBook);

                        context.SaveChanges();

                        return true;
                    }
                }

                return false;
            }
            else
            {
                //FIXME: return IDataErrorInfo validation
                serverSideError = "The BookDetails object is invalid";
                return false;
            }
        }
        /// <summary>
        ///Doesn't support automatically adding NEW related entities... eg. authors,
        ///categories, etc.
        /// </summary>
        public static void BookDetailsBllToDal(ProtoLibEntities context, BookDetailsBLL bllBook, BookDetails dalBook)
        {
            dalBook.ISBN13 = bllBook.PublishInfo.ISBN13;
            dalBook.ISBN10 = bllBook.PublishInfo.ISBN10;
            dalBook.EditionNumber = bllBook.PublishInfo.EditionNumber;
            dalBook.EditionName = bllBook.PublishInfo.EditionName;
            dalBook.Printing = bllBook.PublishInfo.Printing;
            dalBook.DatePublished = bllBook.PublishInfo.DatePublished;

            dalBook.Title = bllBook.Description.Title;
            dalBook.TitleLong = bllBook.Description.TitleLong;
            dalBook.Summary = bllBook.Description.Summary;
            dalBook.Notes = bllBook.Description.Notes;
            dalBook.Language = bllBook.Description.Language;
            dalBook.AmazonLink = bllBook.Description.AmazonLink;

            dalBook.BookDimensions.Pages = bllBook.Dimensions.Pages;
            dalBook.BookDimensions.Height = bllBook.Dimensions.Height;
            dalBook.BookDimensions.Width = bllBook.Dimensions.Width;
            dalBook.BookDimensions.Thickness = bllBook.Dimensions.Thickness;
            dalBook.BookDimensions.Weight = bllBook.Dimensions.Weight;

            //HACK: Use LINQ intersects
            dalBook.Authors.Clear();
            foreach (int authorID in bllBook.AuthorIDs)
                dalBook.Authors.Add(context.Authors.First(a => a.AuthorID == authorID));

            dalBook.Categories.Clear();
            foreach (int categoryID in bllBook.CategoryIDs)
                dalBook.Categories.Add(context.Categories.First(c => c.CategoryID == categoryID));

            dalBook.Subjects.Clear();
            foreach (int subjectID in bllBook.SubjectIDs)
                dalBook.Subjects.Add(context.Subjects.First(s => s.SubjectID == subjectID));

            //dalBook.PublisherID = bllBook.PublishInfo.PublisherID;
            if (bllBook.PublishInfo.PublisherID != null)
                dalBook.Publisher = context.Publishers.First(p => p.PublisherID == (int)bllBook.PublishInfo.PublisherID);
        }
        public static void BookDetailsDalToBll(ProtoLibEntities context, BookDetailsBLL bllBook, BookDetails dalBook)
        {
            bllBook.ItemID = dalBook.BookDetailsID;

            bllBook.PublishInfo.ISBN13 = dalBook.ISBN13;
            bllBook.PublishInfo.ISBN10 = dalBook.ISBN10;
            bllBook.PublishInfo.EditionNumber = dalBook.EditionNumber;
            bllBook.PublishInfo.EditionName = dalBook.EditionName;
            bllBook.PublishInfo.Printing = dalBook.Printing;
            bllBook.PublishInfo.DatePublished = dalBook.DatePublished;

            bllBook.Description.Title = dalBook.Title;
            bllBook.Description.TitleLong = dalBook.TitleLong;
            bllBook.Description.Summary = dalBook.Summary;
            bllBook.Description.Notes = dalBook.Notes;
            bllBook.Description.Language = dalBook.Language;
            bllBook.Description.AmazonLink = dalBook.AmazonLink;

            bllBook.Dimensions.Pages = dalBook.BookDimensions.Pages;
            bllBook.Dimensions.Height = dalBook.BookDimensions.Height;
            bllBook.Dimensions.Width = dalBook.BookDimensions.Width;
            bllBook.Dimensions.Thickness = dalBook.BookDimensions.Thickness;
            bllBook.Dimensions.Weight = dalBook.BookDimensions.Weight;

            bllBook.AuthorIDs.Clear();
            foreach (Author a in dalBook.Authors)
                bllBook.AuthorIDs.Add(a.AuthorID);

            bllBook.CategoryIDs.Clear();
            foreach (Category c in dalBook.Categories)
                bllBook.CategoryIDs.Add(c.CategoryID);

            bllBook.SubjectIDs.Clear();
            foreach (Subject s in dalBook.Subjects)
                bllBook.SubjectIDs.Add(s.SubjectID);

            bllBook.PublishInfo.PublisherID = bllBook.PublishInfo.PublisherID;
        }
示例#4
0
 /// <summary>
 /// Create a new BookDetails object.
 /// </summary>
 /// <param name="bookDetailsID">Initial value of the BookDetailsID property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="publisherID">Initial value of the PublisherID property.</param>
 public static BookDetails CreateBookDetails(global::System.Int32 bookDetailsID, global::System.String title, global::System.Int32 publisherID)
 {
     BookDetails bookDetails = new BookDetails();
     bookDetails.BookDetailsID = bookDetailsID;
     bookDetails.Title = title;
     bookDetails.PublisherID = publisherID;
     return bookDetails;
 }
示例#5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the BookDetailsSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBookDetailsSet(BookDetails bookDetails)
 {
     base.AddObject("BookDetailsSet", bookDetails);
 }