コード例 #1
0
        /// <summary>
        /// 根据业务实体对象返回对应的视图模型
        /// </summary>
        /// <param name="boId"></param>
        /// <returns></returns>
        public ArticleVM GetVM(Article bo)
        {
            var boVM = new ArticleVM();

            _BoMapToVM(bo, boVM);
            return(boVM);
        }
コード例 #2
0
        /// <summary>
        /// 根据业务实体对象 Id 返回对应的视图模型
        /// </summary>
        /// <param name="boId"></param>
        /// <returns></returns>
        public async Task <ArticleVM> GetVM(Guid id)
        {
            var boVM = new ArticleVM();
            // 初始化数据对象
            var bo = await _boRepository.GetSingleAsyn(id);

            if (bo == null)
            {
                // 缺省的直接创建
                bo        = new Article();
                boVM.Id   = bo.Id;
                boVM.Name = "";
                await SaveBo(boVM);

                bo = await _boRepository.GetSingleAsyn(boVM.Id);
            }

            // 映射基本的属性值
            _BoMapToVM(bo, boVM);

            // 设置供前端下拉选项所需要的数据集合
            await SetRelevanceItems(boVM);

            return(boVM);
        }
コード例 #3
0
        public async Task SetRelevanceItems(ArticleVM boVM)
        {
            // 设置关联的文章附件
            var files = await _businessFileService.GetAllAsyn(x => x.RelevanceObjectID == boVM.Id);

            boVM.FileCollection = new List <BusinessFileVM>();
            foreach (var item in files)
            {
                boVM.FileCollection.Add(new BusinessFileVM(item));
            }

            // 设置关联的栏目
            var tempCollection = await _articleInTopicRepository.GetAllIncludingAsyn(x => x.ArticleTopic, y => y.MasterArticle);

            var articleTopicCollection = from x in tempCollection
                                         where x.MasterArticle.Id == boVM.Id
                                         select x.ArticleTopic;

            boVM.TopicItemIdCollection = new List <string>();
            boVM.TopicItemCollection   = new List <ControlModels.PlainFacadeItem>();
            var topicCollection = await _articleTopicRepository.GetAllAsyn();

            foreach (var topic in topicCollection.OrderBy(x => x.SortCode))
            {
                var item = new PlainFacadeItem()
                {
                    ID = topic.Id.ToString(), Name = topic.Name, IsActive = false
                };
                if (articleTopicCollection.FirstOrDefault(x => x.Id == topic.Id) != null)
                {
                    item.IsActive = true;
                }
                boVM.TopicItemCollection.Add(item);
            }
        }
コード例 #4
0
 /// <summary>
 /// 视图对象的属性转换为业务对象的属性
 /// </summary>
 /// <param name="bo"></param>
 private void _VMMapToBo(Article bo, ArticleVM boVM)
 {
     bo.Id                 = boVM.Id;
     bo.Name               = boVM.Name;
     bo.Description        = boVM.Description;
     bo.SortCode           = boVM.SortCode;
     bo.ArticleSecondTitle = boVM.ArticleSecondTitle;
     bo.ArticleSource      = boVM.ArticleSource;
     bo.ArticleContent     = boVM.ArticleContent;
 }
コード例 #5
0
 /// <summary>
 /// 业务对象的属性转换为视图对象的属性
 /// </summary>
 /// <param name="bo"></param>
 private void _BoMapToVM(Article bo, ArticleVM boVM)
 {
     boVM.Id                 = bo.Id;
     boVM.Name               = bo.Name;
     boVM.Description        = bo.Description;
     boVM.SortCode           = bo.SortCode;
     boVM.ArticleSecondTitle = bo.ArticleSecondTitle;
     boVM.ArticleSource      = bo.ArticleSource;
     boVM.ArticleContent     = bo.ArticleContent;
     boVM.PublishDate        = bo.PublishDate.ToString("yyyy-MM-dd");
     boVM.UpVoteNumber       = bo.UpVoteNumber;
     if (bo.CreatorUser != null)
     {
         boVM.CreateUserName = bo.CreatorUser.ChineseFullName;
     }
 }
コード例 #6
0
        public async Task <bool> SaveBo(ArticleVM boVM)
        {
            var bo = _boRepository.GetSingle(boVM.Id);

            if (bo == null)
            {
                bo = new Article();
            }

            _VMMapToBo(bo, boVM);

            //处理作者用户信息
            if (!String.IsNullOrEmpty(boVM.CreateUserName))
            {
                bo.CreatorUser = await _userManager.FindByNameAsync(boVM.CreateUserName);
            }

            var result = await _boRepository.AddOrEditAndSaveAsyn(bo);

            //处理关联栏目
            if (boVM.TopicItemIdCollection != null)
            {
                var topicCollection = await _articleTopicRepository.GetAllAsyn();

                foreach (var topic in topicCollection)
                {
                    _articleInTopicRepository.DeleteAndSaveBy(x => x.ArticleTopic.Id == topic.Id && x.MasterArticle.Id == bo.Id);
                }
                foreach (var topicIdItem in boVM.TopicItemIdCollection)
                {
                    var topic = await _articleTopicRepository.GetSingleAsyn(Guid.Parse(topicIdItem));

                    var articleInTopic = new ArticleInTopic()
                    {
                        ArticleTopic = topic, MasterArticle = bo
                    };
                    await _articleInTopicRepository.AddOrEditAndSaveAsyn(articleInTopic);
                }
            }

            return(result);
        }
コード例 #7
0
        /// <summary>
        /// 根据列表分页器的参数
        /// </summary>
        /// <param name="listPageParameter"></param>
        /// <param name="boService"></param>
        /// <param name=""></param>
        /// <returns></returns>
        public async Task <List <ArticleVM> > GetboVMCollectionAsyn(ListPageParameter listPageParameter)
        {
            var pageIndex = Int16.Parse(listPageParameter.PageIndex);
            var pageSize  = Int16.Parse(listPageParameter.PageSize);

            var typeID       = "";
            var keyword      = "";
            var typeName     = "所有文章";
            var objectAmount = 0;

            if (!String.IsNullOrEmpty(listPageParameter.ObjectTypeID))
            {
                typeID = listPageParameter.ObjectTypeID;
            }
            if (!String.IsNullOrEmpty(listPageParameter.Keyword))
            {
                keyword = listPageParameter.Keyword;
            }

            #region 1.构建与 keyword 相关的查询 lambda 表达式,用于对查询结果的过滤(给 Where 使用)
            Expression <Func <Article, bool> > predicateExpession = x =>
                                                                    x.Name.Contains(keyword) ||
                                                                    x.ArticleSecondTitle.Contains(keyword) ||
                                                                    x.ArticleContent.Contains(keyword) ||
                                                                    x.Description.Contains(keyword);
            #endregion

            #region 2.根据属性名称确定排序的属性的 lambda 表达式
            var sortPropertyName = listPageParameter.SortProperty;
            var type             = typeof(Article);
            var target           = Expression.Parameter(typeof(object));
            var castTarget       = Expression.Convert(target, type);
            var getPropertyValue = Expression.Property(castTarget, sortPropertyName);
            var sortExpession    = Expression.Lambda <Func <Article, object> >(getPropertyValue, target);
            #endregion

            PaginatedList <Article> boCollection = new PaginatedList <Article>();

            //var roleId = listPageParameter.ObjectTypeID;
            if (String.IsNullOrEmpty(typeID))
            {
                var tempCollection = await _boRepository.GetAllIncludingAsyn(x => x.CreatorUser);

                objectAmount = _boRepository.GetAll().Count();

                if (listPageParameter.SortDesc == "")
                {
                    boCollection = tempCollection.OrderByDescending(sortExpession).AsQueryable().ToPaginatedList(pageIndex, pageSize);
                }
                else
                {
                    boCollection = tempCollection.OrderBy(sortExpession).AsQueryable().ToPaginatedList(pageIndex, pageSize);
                }
            }
            else
            {
                var tempCollection = await _articleInTopicRepository.GetAllIncludingAsyn(x => x.ArticleTopic, y => y.MasterArticle);

                var articleTopic      = _articleTopicRepository.GetSingle(Guid.Parse(typeID));
                var articleCollection = from x in tempCollection
                                        where x.ArticleTopic.Id == articleTopic.Id
                                        select x.MasterArticle;

                typeName     = articleTopic.Name;
                objectAmount = tempCollection.Count();

                if (listPageParameter.SortDesc == "")
                {
                    boCollection = articleCollection.AsQueryable().OrderByDescending(sortExpession).ToPaginatedList(pageIndex, pageSize);
                }
                else
                {
                    boCollection = articleCollection.AsQueryable().OrderBy(sortExpession).ToPaginatedList(pageIndex, pageSize);
                }
            }

            var boVMCollection = new List <ArticleVM>();
            var counter        = 0;
            foreach (var bo in boCollection)
            {
                var boVM = new ArticleVM();
                _BoMapToVM(bo, boVM);
                boVM.OrderNumber = (++counter + (pageIndex - 1) * pageSize).ToString();
                boVMCollection.Add(boVM);
            }


            listPageParameter.PageAmount    = boCollection.TotalPageCount.ToString();
            listPageParameter.ObjectAmount  = boCollection.TotalCount.ToString();
            listPageParameter.PagenateGroup = PagenateGroupRepository.GetItem <Article>(boCollection, 10, pageIndex);
            listPageParameter.Keyword       = keyword;
            listPageParameter.TypeName      = typeName;

            return(boVMCollection);
        }