public ActionResult Index(int?page) { int pageSize = 6; int pageNumber = (page ?? 1); var websiteContent = _unitOfWork.WebsiteContent.GetWebsiteContent(); var model = new BlogsPageViewModel() { BlogList = _unitOfWork.Blog.GetActiveBlogs().Select(b => new BlogListViewModel() { Id = b.Id, Caption = b.Caption, BlogType = b.BlogType.Name, Image = b.ImagePath + "/" + b.ImageName, Date = b.Date, Text = StripHTML.StripHtml(b.Text) }).OrderBy(b => b.Date).ThenBy(b => b.Id).ToPagedList(pageNumber, pageSize), BlogsMainImageName = websiteContent.BlogsMainImageName, BlogsMainImagePath = websiteContent.BlogsMainImagePath, BlogsSubtitle = websiteContent.BlogsSubtitle, BlogsTitle = websiteContent.BlogsTitle }; ViewBag.TopImage = websiteContent.BlogsMainImagePath + "/" + websiteContent.BlogsMainImageName; ViewBag.Headline = websiteContent.BlogsTitle; ViewBag.SubHeadline = websiteContent.BlogsSubtitle; return(View(model)); }
public IActionResult Index(int page = 1, string filterNumber = null) { int pageSize = 3; // number of blogs on page var filterVariants = new List <SelectListItem> { new SelectListItem { Text = "Recently created", Value = "1" }, new SelectListItem { Text = "First created", Value = "2" }, new SelectListItem { Text = "Popularity", Value = "3" }, new SelectListItem { Text = "Number of posts", Value = "4" } }; IEnumerable <Blog> source = _blogService.GetAllBlogs(); switch (filterNumber) { case "1": // recently created first source = source.OrderByDescending(m => m.CreatedDateTime); break; case "2": // first created first source = source.OrderBy(m => m.CreatedDateTime); break; case "3": // with more likes first source = source.OrderByDescending(m => m.Posts.Sum(p => p.Likes.Count)); break; case "4": // with more posts first source = source.OrderByDescending(m => m.Posts.Count); break; default: // recently created first by default source = source.OrderByDescending(m => m.CreatedDateTime); break; } var count = source.ToList().Count; var items = source.Skip((page - 1) * pageSize).Take(pageSize).ToList(); PageViewModel pageViewModel = new PageViewModel(count, page, pageSize); BlogsPageViewModel viewModel = new BlogsPageViewModel { PageViewModel = pageViewModel, Blogs = items, FiltersSelectListItems = filterVariants, CurrentFilterNumber = string.IsNullOrEmpty(filterNumber) ? "1" : filterNumber, }; return(View(viewModel)); }
public ActionResult SaveBlogsContent(BlogsPageViewModel model) { var websiteContent = _unitOfWork.WebsiteContent.GetWebsiteContent(); var HomepagePath = "/DynamicContent/BlogsContent"; websiteContent.BlogsTitle = model.BlogsTitle; websiteContent.BlogsSubtitle = model.BlogsSubtitle; if (model.BlogsMainImageFile != null) { websiteContent.BlogsMainImageName = model.BlogsMainImageFile.FileName; websiteContent.BlogsMainImagePath = HomepagePath; model.BlogsMainImageFile.SaveAs(Path.Combine(Server.MapPath(HomepagePath), model.BlogsMainImageFile.FileName)); } _unitOfWork.Complete(); return(RedirectToAction("Index")); }
public BlogsPage() { BindingContext = new BlogsPageViewModel(); InitializeComponent(); }