public ActionResult Category(int id, string sortByTitle = "", string sortByDate = "desc") { var news = _repository.Find(n => n.NewsCategoryId == id); var result = news.Include("User").Include("NewsCategory"); news = result.Where(n => n.Status == "Approved"); IQueryable <News> newsLocal = news; if (!String.IsNullOrEmpty(sortByDate)) { if (sortByDate == "asc") { newsLocal = news.OrderBy(n => n.ModifiedOn); } else { newsLocal = news.OrderByDescending(n => n.ModifiedOn); } news = newsLocal; } if (!String.IsNullOrEmpty(sortByTitle)) { if (sortByTitle == "asc") { newsLocal = news.OrderBy(n => n.Title); } else { newsLocal = news.OrderByDescending(n => n.Title); } news = newsLocal; } GlobalRepository <NewsCategory> _categoriesRepository = new GlobalRepository <NewsCategory>(); var categories = _categoriesRepository.Find(c => c.Id == id); var titlu = categories.Select(c => c.Name).FirstOrDefault(); ViewBag.Name = titlu; ViewBag.Pages = (int)news.Count() / pageSize + 1; if (news.Count() % pageSize == 0) { ViewBag.Pages = ViewBag.Pages - 1; } var newsVM = new NewsVM { News = news }; return(View(newsVM)); }
public ActionResult Delete(int id) { var entity = _repository.Find(m => m.Id == id); var news = entity.FirstOrDefault(); if (news.UserId != User.Identity.GetUserId() && !User.IsInRole("Administrator")) { return(HttpNotFound()); } _repository.Remove(news); return(RedirectToAction("Show", "News", new { id = news.NewsId })); }
public ActionResult Delete(int id) { var category = _repository.Find(c => c.Id == id).FirstOrDefault(); _repository.Remove(category); return(RedirectToAction("ManageCategories")); }
public ActionResult Show(int id) { var result = _repository.Find(n => n.Id == id); var news = result.FirstOrDefault(); ViewBag.showButtons = false; if (User.IsInRole("Editor") || User.IsInRole("Administrator")) { ViewBag.showButtons = true; } ViewBag.isAdmin = User.IsInRole("Administrator"); ViewBag.currentUser = User.Identity.GetUserId(); var newResult = Mapper.Map <News, NewsDtoForUpdate>(news); var commentsRepository = new GlobalRepository <Comment>(); var comments = commentsRepository.Find(c => c.NewsId == news.Id).OrderByDescending(c => c.CreatedOn); var newsForm = new NewsForm { Id = news.Id, Title = news.Title, Content = news.Content, Image = news.Image, NewsCategoryId = news.NewsCategoryId, NewsCategory = news.NewsCategory, ModifiedBy = Guid.Parse(news.UserId), User = news.User, ModifiedOn = news.ModifiedOn, Comments = comments.ToList() }; return(View(newsForm)); }