Beispiel #1
0
        public IList <HeaderRowVM> GetAllHeaders(ClaimsPrincipal contextUser)
        {
            var user = _userService.GetUserWithRoles(contextUser);

            var headers = _headerRepository.GetAll().Include("Posts");

            if (!user.IsAdmin)
            {
                headers = headers.Where(x => x.IsAdminOnly == false);
            }

            return(headers.ToList().Select(x =>
                                           new HeaderRowVM()
            {
                HeaderCode = x.IdCode,
                PostCount = x.Posts.Count,
                Title = x.Title
            }
                                           ).ToList());
        }
 public IQueryable <Header> GetAll()
 {
     return(_headerRepository.GetAll());
 }
 // GET: Footer
 public ActionResult Header()
 {
     var header = headerRepository.GetAll().FirstOrDefault();
     return PartialView(header);
 }
        public ActionResult Add()
        {
            var model = headerRepository.GetAll().FirstOrDefault();

            return(View(model));
        }
        public IActionResult Post(int?id, string q, string category)
        {
            ViewBag.admin      = admindisplay;
            ViewBag.user       = userdisplay;
            ViewBag.categories = _categoryrepository.GetAll();
            List <Post> allposts = _postrepository.GetAll();

            if (!string.IsNullOrEmpty(q))
            {
                List <Post>          searchPosts    = allposts.Where(i => (_headerrepository.GetById(i.headerId).heading.ToLower().Contains(q))).ToList();
                List <PostViewModel> postViewModels = new List <PostViewModel>();
                foreach (var item in searchPosts)
                {
                    List <string> categorynames = new List <string>();
                    var           ids           = _postcategoryrepository.GetCategories(item.id);
                    foreach (var catId in ids)
                    {
                        categorynames.Add(_categoryrepository.GetById(catId).name);
                    }
                    var postvm = new PostViewModel()
                    {
                        post          = item,
                        categoryNames = categorynames,
                        postHeader    = _headerrepository.GetById(item.headerId)
                    };
                    postViewModels.Add(postvm);
                }
                postViewModels = postViewModels.OrderByDescending(p => p.post.date).ToList();
                ViewBag.header = _headerrepository.GetById(15);
                ViewBag.query  = q;
                return(View("list", postViewModels));
            }

            if (!string.IsNullOrEmpty(category))
            {
                var catId         = _categoryrepository.GetAll().FirstOrDefault(c => (c.name.Equals(category))).id;
                var searchPostIds = _postcategoryrepository.GetPosts(catId);
                List <PostViewModel> postViewModels = new List <PostViewModel>();
                foreach (var postId in searchPostIds)
                {
                    List <string> categorynames = new List <string>();
                    var           ids           = _postcategoryrepository.GetCategories(postId);
                    foreach (var cId in ids)
                    {
                        categorynames.Add(_categoryrepository.GetById(cId).name);
                    }
                    var postvm = new PostViewModel()
                    {
                        post          = _postrepository.GetById(postId),
                        categoryNames = categorynames,
                        postHeader    = _headerrepository.GetById(_postrepository.GetById(postId).headerId)
                    };
                    postViewModels.Add(postvm);
                }
                ViewBag.header = _headerrepository.GetAll().FirstOrDefault(c => (c.heading.Equals(category)));
                postViewModels = postViewModels.OrderByDescending(p => p.post.date).ToList();
                return(View("list", postViewModels));
            }

            PostViewModel pvm;

            if (id != null)
            {
                Post p        = allposts.FirstOrDefault(p => p.id == id);
                var  Comments = _commentRepository.GetPostComments(p.id);
                pvm = new PostViewModel()
                {
                    post     = p,
                    comments = Comments
                };
                ViewBag.commentCount = Comments.Count;
                ViewBag.header       = _headerrepository.GetById(p.headerId);
                p.viewCount++;
                _postrepository.Update(p);
            }

            else
            {
                Random rastgele = new Random();
                int    sayi     = rastgele.Next(allposts.Count);
                Post   p        = allposts[sayi];
                var    Comments = _commentRepository.GetPostComments(p.id);
                pvm = new PostViewModel()
                {
                    post     = p,
                    comments = Comments
                };
                ViewBag.commentCount = Comments.Count;
                ViewBag.header       = _headerrepository.GetById(p.headerId);
                p.viewCount++;
                _postrepository.Update(p);
            }
            return(View("post", pvm));
        }