public ActionResult BlogPosts(RenderWidgetViewModel model) { IList<BlogItem> posts; var isPagingEnabled = model.GetOptionValue<bool>("ShowPager"); var pageSize = model.GetOptionValue<int>("PageSize"); var page = Request.QueryString["blogpage"].ToIntOrDefault(); int postsCount; using (var api = ApiFactory.Create()) { var request = new GetBlogPostsModel { Take = pageSize, IncludeTags = true, IncludeCategories = true }; SortAndFilterRequest(request); if (isPagingEnabled) { var skipCount = page == 0 ? 0 : (page - 1) * pageSize; request.Skip = skipCount; } request.Take = pageSize; var pages = api.Blog.BlogPosts.Get(new GetBlogPostsRequest { Data = request }); posts = pages.Data.Items.Select( x => new BlogItem { IntroText = x.IntroText, PublishedOn = x.ActivationDate, Title = x.Title, Url = x.BlogPostUrl, Author = x.AuthorName, Tags = x.Tags, Categories = x.Categories }).ToList(); postsCount = pages.Data.TotalCount; } var items = new BlogItemsModel { Items = posts, ShowAuthor = model.GetOptionValue<bool>("ShowAuthor"), ShowDate = model.GetOptionValue<bool>("ShowDate"), ShowCategories = model.GetOptionValue<bool>("ShowCategories"), ShowTags = model.GetOptionValue<bool>("ShowTags"), ShowPager = isPagingEnabled, NumberOfPages = (int)Math.Ceiling((double)postsCount / pageSize), CurrentPage = page > 0 ? page : 1 }; return View(items); }
public ActionResult Album(RenderWidgetViewModel request) { var albumRequest = new GetAlbumCommandRequest { FolderId = request.GetOptionValue<Guid?>(ImagesGalleryModuleConstants.OptionKeys.AlbumFolder), WidgetViewModel = request, RenderBackUrl = false }; var albumViewModel = GetCommand<GetAlbumCommand>().ExecuteCommand(albumRequest); return View("Album", albumViewModel); }
public ActionResult GetCategories(RenderWidgetViewModel model) { var categories = new List<CategoryItem>(); using (var api = ApiFactory.Create()) { var useSpecificCategoryTree = model.GetOptionValue<bool>("UseSpecificCategoryTree"); var categoryTreeName = model.GetOptionValue<string>("CategoryTreeName"); var treeRequest = new GetCategoryTreesModel(); var treePages = api.Root.Categories.Get(new GetCategoryTreesRequest { Data = treeRequest }); var query = treePages.Data.Items.Where(item => item.AvailableFor.Contains(new Guid("75E6C021-1D1F-459E-A416-D18477BF2020"))); if (useSpecificCategoryTree) { query = query.Where(item => item.Name == categoryTreeName); } var categoryTreeIds = query .Select(item => item.Id) .ToList(); foreach (var treeId in categoryTreeIds) { var request = new GetCategoryTreeRequest { CategoryTreeId = treeId, Data = { IncludeNodes = true } }; var pages = api.Root.Category.Get(request); categories.AddRange(pages.Nodes .Where(node => node.ParentId == null) .OrderBy(node => node.Name) .Select(node => new CategoryItem { Name = node.Name, Id = node.Id })); } } return View(categories); }