public PartialViewResult _LatestBlog() { using (MikeUpjohnCMSEntities db = new MikeUpjohnCMSEntities()) { BlogsListViewModel blog = (from x in db.Blogs join y in db.Images on x.BlogImageID equals y.ImageID into ya from y in ya.DefaultIfEmpty() join z in db.Images on x.BlogThumbnailImageID equals z.ImageID into za from z in za.DefaultIfEmpty() orderby x.BlogDate select new BlogsListViewModel { BlogID = x.BlogID, BlogTitle = x.BlogTitle, BlogAuthor = x.BlogAuthor, BlogDate = x.BlogDate, BlogSummary = x.BlogSummary, BlogPost = x.BlogPost, BlogImage = (y != null ? Settings.UPLOADSIMAGEFILEPATH + y.ImageFileName : Settings.DEFAULTIMAGEFILEPATH), BlogThumbnail = (z != null ? Settings.UPLOADSIMAGEFILEPATH + z.ImageFileName : Settings.DEFAULTIMAGEFILEPATH), IsDisabled = x.IsDisabled, IsDeleted = x.IsDeleted, BlogCreatedDate = x.BlogCreatedDate }).FirstOrDefault(); return(PartialView(blog)); } }
public IActionResult News(int id) { var blogModel = new BlogsListViewModel { Blogs = repository.Blogs.OrderBy(p => p.BlogID).Where(p => p.BlogID == Convert.ToInt16(id)) }; return(View(blogModel)); }
public BlogsListViewModel GetBlogArticles(string search = null) { var articles = _blogRepository.GetArticles(search); var model = new BlogsListViewModel { Articles = articles.GenerateArticleUrls(), Search = search, TotalArticles = articles.Count }; return(model); }
public ActionResult Index(string categories, string tag) { List <Author> authors = db.Authors.ToList(); IQueryable <Models.Blog> blogs = db.Blogs.Include(p => p.Author); List <Tag> Tags = db.Tags.ToList(); List <Models.Blog> Blogs = db.Blogs.ToList(); List <string> tag_name = new List <string>(); for (int i = 0; i < Tags.Count(); i++) { tag_name.Add(Tags[i].Name); } tag_name.Add("Все"); SelectList tags = new SelectList(tag_name); List <Models.Blog> Blogs_d = new List <Models.Blog>(); Blogs_d = blogs.ToList(); if (!String.IsNullOrEmpty(categories) && !categories.Equals("Все")) { Blogs_d.Clear(); for (int i_1 = 0; i_1 < blogs.Count(); i_1++) { if (blogs.ToList()[i_1].Tag == categories) { if (!String.IsNullOrEmpty(tag) && !tag.Equals("Все")) { for (int i = 0; i < Blogs.Count(); i++) { int count_tags = Blogs.ToList()[i].Tags.Count(); for (int j = 0; j < count_tags; j++) { if (Blogs.ToList()[i].Tags.ToList()[j].Name == tag && Blogs.ToList()[i].Tag == categories) { string name_tag = Blogs.ToList()[i].Name; if (!Blogs_d.Contains(Blogs.ToList()[i])) { Blogs_d.Add(Blogs.ToList()[i]); } } } } } } } } BlogsListViewModel plvm = new BlogsListViewModel { Blogs = Blogs_d.ToList(), Categories = Categories, Tags = tags }; string result = "Вы не авторизованы"; string name_user = ""; if (User.Identity.IsAuthenticated) { result = "Ваш логин: " + User.Identity.Name; name_user = User.Identity.Name; } bool IsAdmin = HttpContext.User.IsInRole("admin"); if (User.Identity.IsAuthenticated) { if (!IsAdmin) { ViewBag.Result = result + ", вы не Администратор и не можете Удалять | Редактировать Блоги."; } else { ViewBag.Result = result + ", вы Администратор."; } } else { ViewBag.Result = result; } ViewData["username"] = name_user; return(View("Index", plvm)); }