Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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));
        }