Пример #1
0
        /// <summary>
        /// gets 3 latests posts
        /// </summary>
        /// <param name="locale">language</param>
        /// <returns>instance of <see cref="IEnumerable{PostDto}"/></returns>
        public async Task <IEnumerable <PostDto> > GetLatestAsync(Locale locale)
        {
            PostPagingParametersDto pagingParametersDto = new PostPagingParametersDto
            {
                Locale     = locale,
                PageNumber = 1,
                PageSize   = 3
            };

            return(await GetPostByPagingParameters(pagingParametersDto));
        }
Пример #2
0
        public void GetAllAsync_Default_ShouldReturnList()
        {
            using (var context = new VisitingStolacDbContext(_options))
            {
                var service = new PostRepository(context);
                PostPagingParametersDto dto = new PostPagingParametersDto
                {
                    Locale     = Locale.BOS,
                    PageNumber = 1,
                    PageSize   = 10
                };

                var x = service.GetAllAsync(dto).GetAwaiter().GetResult();
                Assert.IsTrue(x != null);
            }
        }
Пример #3
0
        /// <summary>
        /// private method for getting posts
        /// </summary>
        /// <param name="pagingParameters">instance of <see cref="PostPagingParametersDto"/></param>
        /// <returns>instance of <see cref="IEnumerable{PostDto}"/></returns>
        private async Task <IEnumerable <PostDto> > GetPostByPagingParameters(PostPagingParametersDto pagingParameters)
        {
            if (pagingParameters.PageNumber < 1)
            {
                pagingParameters.PageNumber = 1;
            }

            IList <Post> posts = _posts.Skip((pagingParameters.PageNumber - 1) * pagingParameters.PageSize)
                                 .Take(pagingParameters.PageSize).ToList();

            IList <PostDto> returnPosts = new List <PostDto>();

            foreach (var item in posts)
            {
                string text = _translations.Where(tr => tr.TextContentId == item.TextId)
                              .Where(tr => tr.Locale == pagingParameters.Locale)
                              .Select(tr => tr.Text).FirstOrDefault();

                string title = _translations.Where(tr => tr.TextContentId == item.TitleId)
                               .Where(tr => tr.Locale == pagingParameters.Locale)
                               .Select(tr => tr.Text).FirstOrDefault();

                List <MediaDto> medias = _medias.Where(m => m.GroupId == item.MediaGroupId).Select(m => new MediaDto()
                {
                    GroupId = m.GroupId,
                    Id      = m.Id,
                    Source  = m.Source,
                    Type    = m.Type.ToString(),
                    Url     = m.Url
                }).ToList();

                string administrator = _administrator.Username;

                returnPosts.Add(new PostDto()
                {
                    Id            = item.Id,
                    Title         = title,
                    Text          = text,
                    Administrator = administrator,
                    Medias        = medias
                });
            }

            return(await Task.FromResult(returnPosts.OrderBy(p => p.Created)));
        }
Пример #4
0
 /// <summary>
 /// mocks getting all posts
 /// </summary>
 /// <param name="pagingParameters">instance of <see cref="PostPagingParametersDto"/></param>
 /// <returns>instance of <see cref="IEnumerable{PostDto}"/></returns>
 public async Task <IEnumerable <PostDto> > GetAllAsync(PostPagingParametersDto pagingParameters)
 {
     return(await GetPostByPagingParameters(pagingParameters));
 }