public ActionResult _ArticlesTablePartial()
        {
            var repo     = DependencyResolver.Current.GetService <IRepository>();
            var auth     = DependencyResolver.Current.GetService <IAuthProvider>();
            var userGuid = auth.UserGuid;
            var model    = new ArticlesListModel(userGuid);

            ViewBag.Statuses = repo.GetStatuses(userGuid);
            return(PartialView("Partial/_ArticlesTablePartial", model));
        }
        public async Task <ArticlesListModel> GetArticlesInCategory(string categoryUrl, string filter, string orderBy, SortDirection sortDirection, Guid?currentUserId)
        {
            ArticlesListModel articlesListModel = null;

            using (PoshBoutiqueData dataContext = new PoshBoutiqueData())
            {
                Category category = await dataContext.Categories.FirstOrDefaultAsync(c => c.UrlName == categoryUrl);

                if (category == null && !categoryUrl.Equals(ArticlesProvider.ALL_CATEGORIES_URL_NAME, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(null);
                }

                articlesListModel          = new ArticlesListModel();
                articlesListModel.Category = new CategoriesConverter().ToModel(category);

                IQueryable <Article> articlesQuery = dataContext.Articles
                                                     .Where(article => article.Visible);
                if (category != null)
                {
                    articlesQuery = articlesQuery.Where(article => article.Categories.Any(c => c.Id == category.Id));
                }

                if (!string.IsNullOrEmpty(filter))
                {
                    articlesQuery = articlesQuery
                                    .Where(article => article.Title.Contains(filter) || article.Description.Contains(filter) || article.MaterialDescription.Contains(filter));
                }

                if (!string.IsNullOrEmpty(orderBy))
                {
                    articlesQuery = articlesQuery.Sort(orderBy, sortDirection);
                }

                List <Article> articlesList = await articlesQuery.ToListAsync();

                HashSet <int> userLikes = this.GetUserLikes(currentUserId);

                ArticlesConverter converter = new ArticlesConverter();
                articlesListModel.Articles = articlesList.Select(a => converter.ToModel(a, userLikes)).ToList();
            }

            return(articlesListModel);
        }
Exemple #3
0
        public async Task <IHttpActionResult> Get(string categoryUrl, string orderBy, SortDirection sortDirection, string filter = null)
        {
            Guid?currentUserId = null;

            if (this.User.Identity.IsAuthenticated)
            {
                currentUserId = new Guid(this.User.Identity.GetUserId());
            }

            ArticlesProvider  articlesProvider = new ArticlesProvider();
            ArticlesListModel articlesList     = await articlesProvider.GetArticlesInCategory(categoryUrl, filter, orderBy, sortDirection, currentUserId);

            if (articlesList == null)
            {
                return(this.NotFound());
            }

            return(this.Ok(articlesList));
        }
Exemple #4
0
        public ActionResult _ArticlesListPartial()
        {
            var model = new ArticlesListModel();

            return(PartialView(model));
        }