Exemplo n.º 1
0
        public List <CategoriDTO> getAllCategories()
        {
            var list    = _categoriService.GetAllCategori();
            var mapList = _mapper.Map <IEnumerable <CategoriDTO> >(list).ToList();

            return(mapList);
        }
        public PaginationList getPagNews([FromRoute] int value, [FromRoute] string filter)
        {
            if (filter == "null")
            {
                var newsList    = _newsService.GetAllNews().ToArray();
                var newsListDTO = _mapper.Map <IEnumerable <NewsDTO> >(newsList).ToList();

                int number_1  = value * 6 - 6;
                int number_2  = value * 6;
                var modelForm = new PaginationList();
                for (int i = number_1; i < number_2; i++)
                {
                    try
                    {
                        modelForm.News.Add(newsListDTO[i]);
                    }
                    catch (ArgumentOutOfRangeException e)
                    {
                    }
                }
                int count = newsList.Length / 6;
                if (newsList.Length % 6 > 0)
                {
                    modelForm.countButton = count + 1;
                }
                else
                {
                    modelForm.countButton = count;
                }
                return(modelForm);
            }
            else
            {
                var allCategorie = _categoriService.GetAllCategori().FirstOrDefault(x => x.Name == filter);
                if (allCategorie == null)
                {
                    var newsList    = _newsService.GetAllNews().Where(x => x.ManagerName == filter).ToArray();
                    var newsListDTO = _mapper.Map <IEnumerable <NewsDTO> >(newsList).ToList();

                    int number_1  = value * 6 - 6;
                    int number_2  = value * 6;
                    var modelForm = new PaginationList();
                    for (int i = number_1; i < number_2; i++)
                    {
                        try
                        {
                            modelForm.News.Add(newsListDTO[i]);
                        }
                        catch (ArgumentOutOfRangeException e)
                        {
                        }
                    }
                    int count = newsList.Length / 6;
                    if (newsList.Length % 6 > 0)
                    {
                        modelForm.countButton = count + 1;
                    }
                    else
                    {
                        modelForm.countButton = count;
                    }
                    return(modelForm);
                }
                else
                {
                    var newsList    = _newsService.GetAllNews().Where(x => x.CategoriName == filter).ToArray();
                    var newsListDTO = _mapper.Map <IEnumerable <NewsDTO> >(newsList).ToList();

                    int number_1  = value * 6 - 6;
                    int number_2  = value * 6;
                    var modelForm = new PaginationList();
                    for (int i = number_1; i < number_2; i++)
                    {
                        try
                        {
                            modelForm.News.Add(newsListDTO[i]);
                        }
                        catch (ArgumentOutOfRangeException e)
                        {
                        }
                    }
                    int count = newsList.Length / 6;
                    if (newsList.Length % 6 > 0)
                    {
                        modelForm.countButton = count + 1;
                    }
                    else
                    {
                        modelForm.countButton = count;
                    }
                    return(modelForm);
                }
            }
        }