public int GetCountByStatus(BookInfo bookInfo, SupportAgainstStatus supportOrAgainst)
        {
            IEnumerable<SupportORAgainst> supportORAgainsts
                = this.DataSource.SupportORAgainstInfos.Where(c => c.BookInfo.ID == bookInfo.ID);

            supportORAgainsts = supportORAgainsts.Where(c => c.Status == supportOrAgainst);

            return supportORAgainsts.Count();
        }
Esempio n. 2
0
        public static BookServerModel GetServerModel(BookInfo entity)
        {
            BookServerModel model = new BookServerModel();

            model.ID = entity.ID;
            model.BookName = entity.BookName;
            model.ISBN = entity.ISBN;
            model.CreateTime = entity.CreateTime;

            return model;
        }
        public int GetCountByUser(BookInfo bookInfo, UserInfo userInfo)
        {
            IEnumerable<SupportORAgainst> supportORAgainsts
                = this.DataSource.SupportORAgainstInfos.Where(c => c.BookInfo.ID == bookInfo.ID);

            if (userInfo != null)
            {
                supportORAgainsts = supportORAgainsts.Where(c => c.UserInfo.ID == userInfo.ID);
                return supportORAgainsts.Count();
            }
            else
            {
                return 0;
            }
        }
        public int GetCount(BookInfo bookInfo, Boolean supportOrObjection = true, UserInfo userInfo = null)
        {
            IEnumerable<SupportAndObjectionInfo> supportAndObjections
                = this.DataSource.SupportAndObjectionInfos.Where(c => c.BookInfo.ID == bookInfo.ID);

            if (userInfo != null)
            {
                supportAndObjections = supportAndObjections.Where(c => c.UserInfo.ID == userInfo.ID);
            }
            else
            {
                supportAndObjections = supportAndObjections.Where(c => c.SupportOrObjection == supportOrObjection);
            }

            return supportAndObjections.Count();
        }
        public void Add(BookInfo entity)
        {
            ICollection<BookAndCategoryRelation> tempBookAndCategorys = entity.TempBookAndCategorys;
            ICollection<BookAndAuthorRelation> tempBookAndAuthors = entity.TempBookAndAuthors;

            if (entity.PublisherInfo != null)
            {
                entity.PublisherInfo = this.DataSource.PublisherInfos.Find(entity.PublisherInfo.ID);
            }

            entity.BookAndAuthors = null;
            entity.BookAndCategorys = null;
            this.DataSource.BookInfos.Add(entity);
            this.DataSource.SaveChanges();

            RefreshBookRelationEntity(entity, tempBookAndCategorys, tempBookAndAuthors);
        }
Esempio n. 6
0
        public static DetailBookModel GetViewModel(BookInfo bookInfo, UserInfo userInfo)
        {
            IBookDetailInfoDataProvider iBookDetailInfoDataProvider = new BookDetailInfoDataProvider();
            DetailBookModel model = new DetailBookModel();

            model.ID = bookInfo.ID;
            model.BookName = bookInfo.BookName;
            model.ISBN = bookInfo.ISBN;

            if (bookInfo.PublisherInfo != null)
            {
                model.PublisherName = bookInfo.PublisherInfo.PublisherName;
                model.PublisherNameValue = bookInfo.PublisherInfo.ID.ToString();
                model.PublisherDisplayDescription = bookInfo.PublisherInfo.PublisherIntroduction;
            }

            model.Publish_Date = bookInfo.Publish_Date.ToString(UntityContent.IOSDateTemplate);
            model.Avaliable_Inventory = Convert.ToInt32(bookInfo.Avaliable_Inventory).ToString();
            model.Max_Inventory = Convert.ToInt32(bookInfo.Max_Inventory).ToString();
            model.Price_Inventory = bookInfo.Price_Inventory.ToString("F");

            string categoryNameValue = string.Empty;
            model.CatagoryName = GetCategoryName(bookInfo, out categoryNameValue);
            model.CatagoryNameValue = categoryNameValue;

            string displayName = string.Empty;
            string authorNameValue = string.Empty;
            model.AuthorName = GetAuthorName(bookInfo, out displayName, out authorNameValue);
            model.AuthorDisplayName = displayName;
            model.AuthorNameValue = authorNameValue;

            model.IsAvaliable = bookInfo.Avaliable_Inventory > 0 ? true : false;

            ISupportORAgainstInfoDataProvider dataProvider = new SupportORAgainstInfoDataProvider();
            model.IsAvaliableForSupport = dataProvider.GetCountByUser(bookInfo, userInfo) >= 1 ? false : true;
            model.Supports = dataProvider.GetCountByStatus(bookInfo, SupportAgainstStatus.Support).ToString();
            model.Objections = dataProvider.GetCountByStatus(bookInfo, SupportAgainstStatus.Against).ToString();

            return model;
        }
Esempio n. 7
0
        public static BookToRentModel GetViewMode(BookInfo bookInfo, UserInfo userInfo)
        {
            BookToRentModel model = new BookToRentModel();
            model.ID = bookInfo.ID;
            model.BookName = bookInfo.BookName;

            string displayName = string.Empty;
            string authorNameValue = string.Empty;
            model.AuthorName = BookManage.BookModel.GetAuthorName(bookInfo, out displayName, out authorNameValue);
            model.AuthorName = displayName;

            model.ISBN = bookInfo.ISBN;

            if (bookInfo.PublisherInfo != null)
            {
                model.PublisherName = bookInfo.PublisherInfo.PublisherName;
            }
            model.Publish_Date = bookInfo.Publish_Date.ToString(UntityContent.IOSDateTemplate);
            model.Avaliable_Inventory = Convert.ToInt32(bookInfo.Avaliable_Inventory).ToString();
            model.Max_Inventory = Convert.ToInt32(bookInfo.Max_Inventory).ToString();
            model.Book_Description = "Waiting for DB......";

            int canBorrowCount =  Unity.Helper.DataUnity.GetCanBorrowCount(userInfo);
            IBorrowAndReturnRecordInfoDataProvider iBorrowAndReturnRecordInfoDataProvider =
                new BorrowAndReturnRecordInfoDataProvider();
            int alreadyBorrowedCount = iBorrowAndReturnRecordInfoDataProvider.GetBooksInHandCount(userInfo);

            model.Can_Borrow_Count = canBorrowCount.ToString();
            if (alreadyBorrowedCount >= canBorrowCount)
            {
                model.Still_Can_Borrow_Count = Convert.ToInt32(0).ToString();
                model.Still_Can_Borrow = false;
            }
            else
            {
                model.Still_Can_Borrow_Count = (canBorrowCount - alreadyBorrowedCount).ToString();
                model.Still_Can_Borrow = true;
            }

            return model;
        }
 private void RemoveBookRelationEntity(BookInfo book)
 {
     this.DataSource.BookAndAuthorRelation.RemoveRange(this.DataSource.BookAndAuthorRelation.Where(r => r.Book_ID == book.ID));
     this.DataSource.BookAndCategoryRelation.RemoveRange(this.DataSource.BookAndCategoryRelation.Where(r => r.Book_ID == book.ID));
     this.DataSource.SaveChanges();
 }
 private void RefreshBookRelationEntity(BookInfo book, ICollection<BookAndCategoryRelation> tempBookAndCategorys, ICollection<BookAndAuthorRelation> tempBookAndAuthors)
 {
     if (tempBookAndAuthors != null)
     {
         foreach (var item in tempBookAndAuthors)
         {
             this.DataSource.BookAndAuthorRelation.Add(new BookAndAuthorRelation { Book_ID = book.ID, Author_ID = item.AuthorInfo.ID });
         }
         this.DataSource.SaveChanges();
     }
     if (tempBookAndCategorys != null)
     {
         foreach (var item in tempBookAndCategorys)
         {
             this.DataSource.BookAndCategoryRelation.Add(new BookAndCategoryRelation { Book_ID = book.ID, Category_ID = item.CategoryInfo.ID });
         }
         this.DataSource.SaveChanges();
     }
 }
        public void Update(BookInfo entity)
        {
            ICollection<BookAndCategoryRelation> tempBookAndCategorys = entity.TempBookAndCategorys;
            ICollection<BookAndAuthorRelation> tempBookAndAuthors = entity.TempBookAndAuthors;

            BookInfo book = this.GetBookInfoByID(entity.ID);

            book.BookName = entity.BookName;
            book.ISBN = entity.ISBN;
            book.Publish_Date = entity.Publish_Date;
            book.Price_Inventory = entity.Price_Inventory;

            book.Avaliable_Inventory = entity.Avaliable_Inventory;
            book.Max_Inventory = entity.Max_Inventory;

            if (entity.PublisherInfo != null)
            {
                book.PublisherInfo = this.DataSource.PublisherInfos.Find(entity.PublisherInfo.ID);
            }
            else
            {
                book.PublisherInfo = null;
            }

            this.DataSource.SaveChanges();

            RemoveBookRelationEntity(book);

            RefreshBookRelationEntity(book,tempBookAndCategorys,tempBookAndAuthors);
        }
Esempio n. 11
0
        public BookInfo GetEntity()
        {
            BookInfo bookInfo = new BookInfo();

            BookInfoDataProvider bookInfoDataProvider = new BookInfoDataProvider();
            IBookInfoDataProvider iBookInfoDataProvider = bookInfoDataProvider;

            if (this.ID > 0)
            {

                bookInfo = iBookInfoDataProvider.GetBookInfoByID(this.ID);
            }

            bookInfo.ID = this.ID;
            bookInfo.BookName = this.BookName;
            bookInfo.ISBN = this.ISBN;

            bookInfo.Publish_Date = Convert.ToDateTime(this.Publish_Date);
            bookInfo.Price_Inventory = Decimal.Parse(this.Price_Inventory);
            bookInfo.Avaliable_Inventory = Convert.ToInt32(Convert.ToDecimal(this.Avaliable_Inventory));
            bookInfo.Max_Inventory = Convert.ToInt32(this.Max_Inventory);

            bookInfo.PublisherInfo = GetPublisherInfo(this.PublisherNameValue, bookInfoDataProvider);
            bookInfo.TempBookAndAuthors = GetAuthorInfoRelationList(this.AuthorNameValue, bookInfo, bookInfoDataProvider);
            bookInfo.TempBookAndCategorys = GetCategoryInfoRelationList(this.CatagoryNameValue, bookInfo, bookInfoDataProvider);

            return bookInfo;
        }
Esempio n. 12
0
        public ICollection<BookAndCategoryRelation> GetCategoryInfoRelationList(string cIDs, BookInfo book, BookInfoDataProvider bookInfoDataProvider)
        {
            ICollection<BookAndCategoryRelation> list = new List<BookAndCategoryRelation>();
            if (!String.IsNullOrEmpty(cIDs))
            {
                var aArrary = cIDs.Split(UntityContent.SplitValueStr);
                foreach (var item in aArrary)
                {
                    if (!String.IsNullOrEmpty(item))
                    {
                        long catID = long.Parse(item);
                        BookAndCategoryRelation relationEntity = new BookAndCategoryRelation();
                        relationEntity.BookInfo = book;
                        relationEntity.CategoryInfo = bookInfoDataProvider.DataSource.CategoryInfos.FirstOrDefault(c => c.ID == catID);
                        list.Add(relationEntity);
                    }
                }
            }

            return list;
        }
Esempio n. 13
0
        public ICollection<BookAndAuthorRelation> GetAuthorInfoRelationList(string aIDs, BookInfo book, BookInfoDataProvider bookInfoDataProvider)
        {
            ICollection<BookAndAuthorRelation> list = new List<BookAndAuthorRelation>();
            if (!String.IsNullOrEmpty(aIDs))
            {
                var aArrary = aIDs.Split(UntityContent.SplitValueStr);
                foreach (var item in aArrary)
                {
                    if (!String.IsNullOrEmpty(item))
                    {
                        long authID = long.Parse(item);
                        BookAndAuthorRelation relationEntity = new BookAndAuthorRelation();
                        relationEntity.BookInfo = book;
                        relationEntity.AuthorInfo = bookInfoDataProvider.DataSource.AuthorInfos.FirstOrDefault(a => a.ID == authID);
                        list.Add(relationEntity);
                    }
                }
            }

            return list;
        }
Esempio n. 14
0
        public static string GetCategoryName(BookInfo bookInfo, out string categoryNameValue)
        {
            string categoryName = string.Empty;
            string nameValue = string.Empty;

            foreach (var item in bookInfo.BookAndCategorys.OrderBy(b => b.OrderIndex))
            {
                categoryName += item.CategoryInfo.CategoryName + UntityContent.CategoryPathTemplate;
                nameValue += item.CategoryInfo.ID.ToString() + UntityContent.SplitValueStr;
            }

            categoryNameValue = nameValue;
            return categoryName.TrimEnd(UntityContent.CategoryPathTemplate);
        }
Esempio n. 15
0
        public static string GetAuthorName(BookInfo bookInfo, out string authorDisplayName, out string authorNameValue)
        {
            string authorName = string.Empty;
            string displayName = string.Empty;
            string valueName = string.Empty;
            foreach (var item in bookInfo.BookAndAuthors.OrderBy(a => a.OrderIndex))
            {
                authorName += item.AuthorInfo.AuthorName + UntityContent.AuthorPathTemplate;
                displayName += item.AuthorInfo.AuthorName + UntityContent.SplitDisplayStr;
                valueName += item.AuthorInfo.ID.ToString() + UntityContent.SplitValueStr;
            }

            authorNameValue = valueName;
            authorDisplayName = displayName;
            return authorName.TrimEnd(UntityContent.AuthorPathTemplate);
        }
Esempio n. 16
0
        public static BookModel GetViewModel(BookInfo bookInfo)
        {
            BookModel model = new BookModel();

            model.ID = bookInfo.ID;
            model.BookName = bookInfo.BookName;
            model.ISBN = bookInfo.ISBN;

            if (bookInfo.PublisherInfo != null)
            {
                model.PublisherName = bookInfo.PublisherInfo.PublisherName;
                model.PublisherNameValue = bookInfo.PublisherInfo.ID.ToString();
            }

            model.Publish_Date = bookInfo.Publish_Date.ToString(UntityContent.IOSDateTemplate);
            model.Avaliable_Inventory = Convert.ToInt32(bookInfo.Avaliable_Inventory).ToString();
            model.Max_Inventory = Convert.ToInt32(bookInfo.Max_Inventory).ToString();
            model.Price_Inventory = bookInfo.Price_Inventory.ToString("F");

            string categoryNameValue = string.Empty;
            model.CatagoryName = GetCategoryName(bookInfo, out categoryNameValue);
            model.CatagoryNameValue = categoryNameValue;

            string displayName = string.Empty;
            string authorNameValue = string.Empty;
            model.AuthorName = GetAuthorName(bookInfo, out displayName, out authorNameValue);
            model.AuthorDisplayName = displayName;
            model.AuthorNameValue = authorNameValue;

            model.IsUse = bookInfo.Max_Inventory > 0 ? true : false;

            return model;
        }