Exemple #1
0
        public GetArticlesOutput GetArticle(GetArticleInput input)
        {
            var article = _articleRepository.GetById(input.Id);
            var output  = GetArticlesOutputMapper.Map(article);

            output.Success = true;

            return(output);
        }
        // GET: Articles/Details/5
        public ActionResult Details(int?id)
        {
            if (!id.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var input = new GetArticleInput {
                Id = id.Value
            };
            var output = _articleAppService.GetArticle(input);

            if (!output.Articles.Any())
            {
                return(HttpNotFound());
            }

            return(View(output.Articles.First()));
        }
        // GET: Articles/Edit/5
        public ActionResult Edit(int?id)
        {
            if (!id.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var input = new GetArticleInput {
                Id = id.Value
            };
            var output = _articleAppService.GetArticle(input);

            if (!output.Articles.Any())
            {
                return(HttpNotFound());
            }

            var storesOutput = _storeAppService.GetAllStores();

            ViewBag.StoreId = new SelectList(storesOutput.Stores, "Id", "Name", output.Articles.First().StoreId);

            return(View(output.Articles.First()));
        }
        public async Task <PagedResultOutput <ArticleListDto> > GetArticleList(GetArticleInput input)
        {
            var query = _articleRepository.GetAll().Include(x => x.Category).Include(x => x.CreatorUser)
                        .WhereIf(!input.Filter.IsNullOrEmpty(), x => x.Title.Contains(input.Filter));
            // .WhereIf(AbpSession.UserId!=2,x=>x.CreatorUser.Id==AbpSession.UserId); //这里要改

            var count = await query.CountAsync();


            var articles = await query
                           .OrderBy(input.Sorting)
                           .PageBy(input)
                           .ToListAsync();

            var articleListOutput = articles.Select(x =>
            {
                var dto          = x.MapTo <ArticleListDto>();
                dto.CategoryName = x.Category.Name;
                dto.UserName     = x.CreatorUser.UserName;
                return(dto);
            }).ToList();

            return(new PagedResultOutput <ArticleListDto>(count, articleListOutput));
        }