public ActionResult All(string orderBy, string currentFilter, string searchString, int? page, string civilizationFilter, string categoryFilter)
        {
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            int pageNumber = page ?? 1;

            var articles = this.articlesServices.AllBySearchQuery(searchString, orderBy, civilizationFilter, categoryFilter);

            var viewModel = new AllArticlesViewModel()
            {
                Articles = articles.ToPagedList(pageNumber, Common.AllArticlesPageSize),
                CurrentOrder = orderBy,
                CurrentFilter = searchString,
                CivilizationFilter = civilizationFilter,
                Civilizations = this.GetCivilizations(civilizationFilter),
                CategoryFilter = categoryFilter,
                Categories = this.GetCategories(categoryFilter)
            };

            return this.View(viewModel);
        }
예제 #2
0
        public AllArticlesViewModel GetDeleteDraftModel(int draftId)
        {
            Article draftToDelete = dbContext.Articles.Find(draftId);

            if (draftToDelete == null)
            {
                return(null);
            }
            string modelCategory       = dbContext.Categories.Find(draftToDelete.CategoryId).CategoryName;
            AllArticlesViewModel model = mapper.Map <AllArticlesViewModel>(draftToDelete);

            model.Category = modelCategory;
            return(model);
        }
예제 #3
0
        public async Task <IActionResult> DeleteDraft(AllArticlesViewModel model)
        {
            var userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (ModelState.IsValid)
            {
                if (validationService.CheckDraftUserPermissions(userId, model.Id))
                {
                    editorService.DeleteDraft(model.Id);
                    return(RedirectToAction("AllDrafts"));
                }
            }

            return(RedirectToAction("NotPermitted"));
        }
예제 #4
0
        public ICollection <AllArticlesViewModel> LoadArticlesForReview()
        {
            ICollection <AllArticlesViewModel> articlesToReturn = new List <AllArticlesViewModel>();
            var articles = dbContext.Articles.Where(d => d.State == ArticleState.ForApproval && d.IsDeleted == false).OrderByDescending(x => x.CreationDate);

            if (articles == null)
            {
                return(null);
            }
            foreach (var article in articles)
            {
                AllArticlesViewModel tempArticleToReturnViewModel = mapper.Map <AllArticlesViewModel>(article);
                tempArticleToReturnViewModel.Category = dbContext.Categories.Where(c => c.Id == article.CategoryId).FirstOrDefault().CategoryName;
                articlesToReturn.Add(tempArticleToReturnViewModel);
            }
            return(articlesToReturn);
        }
        public async Task <IActionResult> GetAll(int currentPage = 1)
        {
            var articlesCount = await this.articlesService.GetTotalCountArticlesAsync();

            var pageCount = (int)Math.Ceiling((double)articlesCount / GlobalConstants.ArticlesPerPage);

            var articles = await this.articlesService
                           .GetAllAsync <ArticleViewModel>(GlobalConstants.ArticlesPerPage, (currentPage - 1) *GlobalConstants.ArticlesPerPage);

            var model = new AllArticlesViewModel()
            {
                Articles    = articles,
                CurrentPage = currentPage,
                PagesCount  = pageCount,
            };

            return(this.View(model));
        }
예제 #6
0
        public ICollection <AllArticlesViewModel> LoadAllDrafts(string userId)
        {
            ICollection <AllArticlesViewModel> draftsToReturn = new List <AllArticlesViewModel>();
            var userDrafts = dbContext.Articles.Where(d => d.CreatorId == userId && d.State == ArticleState.Draft && d.IsDeleted == false).OrderByDescending(x => x.CreationDate);

            if (draftsToReturn == null)
            {
                return(null);
            }

            foreach (var draft in userDrafts)
            {
                AllArticlesViewModel tempDraftViewModel = mapper.Map <AllArticlesViewModel>(draft);
                tempDraftViewModel.Category = dbContext.Categories.Where(c => c.Id == draft.CategoryId).FirstOrDefault().CategoryName;
                draftsToReturn.Add(tempDraftViewModel);
            }

            return(draftsToReturn);
        }
예제 #7
0
        public ICollection <AllArticlesViewModel> LoadMyPublishedArticles(string userId)
        {
            ICollection <AllArticlesViewModel> articlesToReturn = new List <AllArticlesViewModel>();
            var userArticlesForReview = dbContext.Articles.Where(d => d.CreatorId == userId && d.State == ArticleState.Published && d.IsDeleted == false).OrderByDescending(x => x.CreationDate);

            if (userArticlesForReview == null)
            {
                return(null);
            }

            foreach (var article in userArticlesForReview)
            {
                AllArticlesViewModel tempDraftViewModel = mapper.Map <AllArticlesViewModel>(article);
                tempDraftViewModel.Category = dbContext.Categories.Where(c => c.Id == article.CategoryId).FirstOrDefault().CategoryName;
                articlesToReturn.Add(tempDraftViewModel);
            }

            return(articlesToReturn);
        }
        public ActionResult All(int page = 1, string order = "default")
        {
            var model = new AllArticlesViewModel
            {
                Articles = articleService.GetByOrderCriterion(order)
                           .Skip((page - 1) * PerPageArticles)
                           .Take(PerPageArticles)
                           .AsQueryable()
                           .ProjectTo <ArticleAdminViewModel>(Mapper.ConfigurationProvider)
                           .ToList(),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PerPageArticles,
                    TotalItems   = articleService.GetCount()
                }
            };

            ViewBag.Order = order;

            return(View(model));
        }