// GET: Home public ActionResult Index(int Page = 1, int?Category = -1) { if (Category == null || Category == -1) { ViewBag.CategoryId = null; var blogs = CacheHelper.GetBlogsWithOutDraftDeleteFromCache().ToPagedList(Page, 5); return(View(blogs)); } else { var category = _categoryManager.Find(x => x.Id == Category); if (category == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.CategoryId = Category; var catBlogs = _blogCategoryManager.ListQueryable().Where(x => x.CategoryId == Category).Select(u => u.Blog).ToList(); var blogs = catBlogs.Where(x => x.IsDelete == false && x.IsDraft == false).ToList().ToPagedList(Page, 5); return(View(blogs)); } }
// GET: Admin/Blog public ActionResult Index(int?id) { IndexViewModel model = new IndexViewModel(); if (id == null || id == -1) { model.Blogs = _blogManager.List(); } else { var category = _categoryManager.Find(x => x.Id == id); if (category == null) { // hatalı kategori seçimi return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } model.Blogs = _blogCategoryManager.ListQueryable().Where(x => x.CategoryId == id).Select(u => u.Blog).ToList(); } foreach (var item in model.Blogs) { item.Text = HttpUtility.HtmlDecode(item.Text); } model.Categories = _categoryManager.ListQueryable().OrderBy(x => x.Name).ToList(); return(View(model)); }
public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var blog = _blogManager.Find(x => x.Id == id && x.AppUserId == CurrentSession.User.Id); if (blog == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EditViewModel model = new EditViewModel(); model.Tittle = blog.Tittle; model.Summary = blog.Summary; model.IsDraft = blog.IsDraft; model.Text = HttpUtility.HtmlDecode(blog.Text); model.BlogId = (Guid)id; model.Categories = _blogCategoryManager.ListQueryable().Where(x => x.BlogId == id).Select(u => u.Category).ToList(); model.Tags = _tagManager.ListQueryable().Where(x => x.BlogId == id).ToList(); ViewBag.CategoryId = new SelectList(CacheHelper.GetCategoriesFromCache(), "Id", "Name"); return(View(model)); }
// GET: User/Home public ActionResult Index(int Page = 1, int?Category = -1) { var user = _userManager.Find(x => x.Username == "userauthor20"); CurrentSession.Set <AppUser>("login", user); if (Category == null || Category == -1) { ViewBag.CategoryId = null; var blogs = CacheHelper.GetBlogsWithOutDraftDeleteFromCache().ToPagedList(Page, 5); return(View(blogs)); } else { var category = _categoryManager.Find(x => x.Id == Category); if (category == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.CategoryId = Category; var catBlogs = _blogCategoryManager.ListQueryable().Where(x => x.CategoryId == Category).Select(u => u.Blog).ToList(); var blogs = catBlogs.Where(x => x.IsDelete == false && x.IsDraft == false).ToList().ToPagedList(Page, 5); foreach (var item in blogs) { item.Text = HttpUtility.HtmlDecode(item.Text); } return(View(blogs)); } }