Example #1
0
        public BookModel Bind(ProBook book, ViewModelBindOption bindOptions)
        {
            this.Id           = book.BookId;
            this.Name         = book.BookName;
            this.BookSize     = book.BookSize;
            this.BookType     = book.BookType;
            this.Introduction = book.Introduction;
            this.CreateTime   = book.CreateTime;
            this.EditeTime    = book.EditeTime;
            this.BookCover    = book.BookCover;

            if (ContainEnumType <BookBindType>(bindOptions.BookBindType, BookBindType.Pics))
            {
                this.Pics = PicModel.BindList(book.Pics, bindOptions);
            }
            if (ContainEnumType <BookBindType>(bindOptions.BookBindType, BookBindType.Author))
            {
                UserServiceClient       client  = new UserServiceClient();
                AdvancedResult <AdUser> userRes = client.GetUserInfoByID(book.AdUserId);
                if (userRes.Error == DataStructure.AppError.ERROR_SUCCESS && userRes.Data != null)
                {
                    this.Author = new UserModel().Bind(userRes.Data, bindOptions);
                }
            }

            return(this);
        }
Example #2
0
        public ProductModel Bind(ProProduct product, ViewModelBindOption bindOptions)
        {
            this.Id          = product.Pid;
            this.Title       = product.Title;
            this.Description = product.BbInfo;
            this.IsWash      = product.IsWash;
            this.CreateTime  = product.CreateTime;
            this.ViewNum     = product.ViewNum;
            this.State       = product.State;
            this.Price       = product.Price;
            this.Sex         = product.Sex;
            this.ItemType    = product.ItemType;
            this.ItemSort    = product.ItemSort;
            this.Age         = (int)((product.MinAge + product.MaxAge) / 2.0);

            if (ContainEnumType <ProductBindType>(bindOptions.ProductBindType, ProductBindType.Pics))
            {
                this.Pics = PicModel.BindList(product.pics, bindOptions);
            }

            if (ContainEnumType <ProductBindType>(bindOptions.ProductBindType, ProductBindType.Author))
            {
                UserServiceClient       client  = new UserServiceClient();
                AdvancedResult <AdUser> userRes = client.GetUserInfoByID(product.CreateId);
                if (userRes.Error == DataStructure.AppError.ERROR_SUCCESS && userRes.Data != null)
                {
                    this.Author = new UserModel().Bind(userRes.Data, bindOptions);
                    if (!string.IsNullOrEmpty(userRes.Data.Qq))
                    {
                        this.QQ = userRes.Data.Qq;
                    }
                    if (!string.IsNullOrEmpty(userRes.Data.Mobile))
                    {
                        this.Phone = userRes.Data.Mobile;
                    }
                }
            }
            if (ContainEnumType <ProductBindType>(bindOptions.ProductBindType, ProductBindType.ReplyCount))
            {
                ReplyServiceClient client = new ReplyServiceClient();
                AdvancedResult <PageEntity <GenReply> > response = client.LoadReplyListByBBPostID(product.Pid, 0, 0);
                if (response.Error == AppError.ERROR_SUCCESS)
                {
                    this.ReplyNum = response.Data.RecordsCount;
                }
            }
            return(this);
        }