Esempio n. 1
0
        public IActionResult Index(int page = 1)
        {
            var indexViewModel = new IndexViewModel();

            try
            {
                //TODO make another way to get pagination and all entities
                indexViewModel.Articles   = BaseMapper.MapViewModel(_articleMapper, _articleService.Get(true, page));
                indexViewModel.Categories = BaseMapper.MapViewModel(_categoryMapper, _categoryService.Get(false, page));
                indexViewModel.Tags       = BaseMapper.MapViewModel(_tagMapper, _tagService.Get(false, page));

                indexViewModel.PageViewModel = new PageViewModel(_articleService.Get(false, 1).Count());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, "Stopped program because of exception");
            }

            //var filtredArticles = articleViewModels.Where(p => p.ArticleCategories.Any(m => m.CategoryId == 2));

            return(View(indexViewModel));
        }
Esempio n. 2
0
        public IActionResult Edit(int?id)
        {
            var categories             = BaseMapper.MapViewModel(_categoryMapper, _categoryService.Get(false, 0));
            var categoriesSelectedList = new SelectList(categories.ToList(), "Id", "Name");

            ViewBag.Categories = categoriesSelectedList;

            var tags = BaseMapper.MapViewModel(_tagMapper, _tagService.Get(false, 0));

            ViewBag.Tags = tags;

            if (id.HasValue)
            {
                try
                {
                    var articleDTO = _articleService.GetById(id.Value);

                    if (articleDTO != null)
                    {
                        var articleViewModel = _articleMapper.Map(articleDTO);
                        return(View(articleViewModel));
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message, "Stopped program because of exception");
                    throw;
                }

                return(NotFound());
            }
            else
            {
                return(View(new ArticleViewModel()));
            }
        }