public async Task <ActionResult> Get()
        {
            #region Start the watch
            var watch = new Stopwatch();
            watch.Start();
            #endregion

            var result = await _entityServices.Get();

            #region End the watch
            watch.Stop();
            result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
            #endregion

            return(Ok(result));
        }
Beispiel #2
0
        public async Task <ArticleListModel> GetListModel(ArticleQuery query)
        {
            ArticleListModel     listModel = new ArticleListModel();
            IQueryable <Article> queryable = GetIncludes(p => p.AuthorUser, x => x.ArticleTags, p => p.ArticleFavorites); //Article Yapan User ve Taglar Gelsin

            if (!string.IsNullOrWhiteSpace(query.TagId))
            {
                var isTag = await _tagServices.Get(p => p.TagId == query.TagId);

                if (isTag != null)
                {
                    queryable = queryable.Where(p => p.ArticleTags.Select(x => x.TagId).Contains(isTag.TagId));
                }
            }

            if (query.UserId > 0)
            {
                var isUser = await _userServices.Get(p => p.Id == query.UserId);

                if (isUser != null)
                {
                    //Eğer Like yaptıklarını istiyorsak...
                    if (query.OnlyLiked)
                    {
                        queryable = queryable.Where(p => p.ArticleFavorites.Any(x => x.UserId == isUser.Id));
                    }
                    else
                    {
                        queryable = queryable.Where(p => p.AuthorUserId == isUser.Id);
                    }
                }
            }


            //.Select(p => new ArticleViewModel {Id=p.Id, AuthorUser = p.AuthorUser, AuthorUserId = p.AuthorUserId, Body = p.Body, CreatedAt = p.CreatedAt, Description = p.Description, Slug = p.Slug, Title = p.Title, UpdatedAt = p.UpdatedAt, Tags = p.ArticleTags.Select(x => x.TagId).ToList() })
            var articleList = queryable.OrderByDescending(p => p.UpdatedAt).Skip(query.Offset * query.Limit).Take(query.Limit).ToList();


            await Task.Run(() => listModel.Articles = _mapper.Map <List <Article>, List <ArticleViewModel> >(articleList));

            //listModel.Articles.ForEach(p =>
            //{
            //    p.Tags = articleList.FirstOrDefault(x => x.Id == p.Id).ArticleTags.Select(x => x.TagId).ToList();
            //});
            listModel.TotalCount = queryable.Count();

            return(listModel);
        }