Example #1
0
        public MainPage()
        {
            this.InitializeComponent();
            Request r = new Request {
            };

            plvm = new PostListViewModel(r);
            PreviousPageButton.Visibility = Visibility.Collapsed;
            Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;

            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame.CanGoBack)
            {
                // Show UI in title bar if opted-in and in-app backstack is not empty.
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                    AppViewBackButtonVisibility.Visible;
            }
            else
            {
                // Remove the UI from the title bar if in-app back stack is empty.
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                    AppViewBackButtonVisibility.Collapsed;
            }
        }
Example #2
0
        public ActionResult DeletePost(Guid Id)
        {
            var post = db.Posts.Find(Id);

            if (post != null)
            {
                db.Posts.Remove(post);
                db.SaveChanges();
            }

            // return success
            var list = new List <PostViewModel>();

            DataContextService.ApplyEntitySorting(db.Posts.ToList()).ForEach(c => list.Add(new PostViewModel(c)));

            var vm = new PostListViewModel
            {
                Posts = list
            };
            var str    = RenderPartialToStringExtensions.RenderPartialToString(ControllerContext, "DeletePost", vm);
            var result = new
            {
                Data    = str,
                Success = true
            };

            return(Json(result));
        }
Example #3
0
        // GET: Posts
        public ActionResult Index(string tag, int pageNumber = 1, bool showDraft = false)
        {
            var pageCount = 0;

            var posts = _repositories.Posts.Get(filter: p => showDraft ? true: !p.Draft, orderBy: list => list.OrderByDescending(post => post.Date));

            if (!String.IsNullOrEmpty(tag))
            {
                posts = posts.Where(p => p.Categories.Contains(tag));
            }

            pageCount = (posts.Count() - 1) / PostsPerPage + 1;

            if (pageNumber > pageCount)
            {
                throw new ArgumentException($"Requested page {pageNumber} but there are only {pageCount} pages");
            }

            posts = posts.Skip((pageNumber - 1) * PostsPerPage).Take(PostsPerPage);


            var viewModel = new PostListViewModel()
            {
                Settings    = _settings,
                Posts       = posts.Select(p => CreatePostViewModel(p)),
                PageCount   = pageCount,
                CurrentPage = pageNumber,
                Tag         = tag
            };

            return(View(viewModel));
        }
Example #4
0
        public async Task <IActionResult> Index(int?page)
        {
            var pageNo   = page ?? 1;
            var pageSize = 50;

            var posts = await new AllPostQuery(_conn).Run();

            posts = posts.OrderByDescending(p => p.Id);
            var pageCount = (int)posts.Count() / pageSize;
            var vm        = new PostListViewModel()
            {
                Posts = posts.Skip((pageNo - 1) * pageSize).Take(pageSize)
            };

            if (pageNo > 1)
            {
                vm.PrevPage = pageNo - 1;
            }
            if (pageCount > pageNo)
            {
                vm.NextPage = pageNo + 1;
            }

            return(View(vm));
        }
Example #5
0
        private void Subreddit_Click(object sender, RoutedEventArgs e)
        {
            PostCategory c = PostCategory.HOT;

            switch (((Button)sender).Content.ToString())
            {
            case "NEW":
                c = PostCategory.NEW;
                break;

            case "TOP":
                c = PostCategory.TOP;
                break;

            case "RISING":
                c = PostCategory.RISING;
                break;

            case "CONTROVERSIAL":
                c = PostCategory.CONTROV;
                break;

            case "GO":
                subreddit = SubredditSearchBox.Text;
                break;
            }

            Request r = new Request {
                subreddit = subreddit, cat = c
            };

            plvm = new PostListViewModel(r);
            Bindings.Update();
            pageNum = 0;
        }
Example #6
0
        public static PostListViewModel ToOverview(this PostsData <PostsNode> source, string baseCategory = "")
        {
            var posts = new List <PostOverview>();

            foreach (var edge in source.EdgeList.Edges)
            {
                var ov = new PostOverview();
                ov.Id         = edge.Node.Id;
                ov.Cursor     = edge.Cursor;
                ov.AuthorInfo = $"{edge.Node.Author.ToAuthorInfo()} am {edge.Node.Date.ToShortDateString()}";
                ov.Categories = edge.Node.Categories.ToCategoryList(baseCategory);
                ov.Excerpt    = edge.Node.Excerpt;
                ov.IsSticky   = edge.Node.IsSticky;
                ov.Title      = edge.Node.Title;
                ov.Date       = edge.Node.Date;
                ov.Link       = $"/post/{ov.Id}";
                posts.Add(ov);
            }

            var vm = new PostListViewModel
            {
                Posts    = posts,
                PageInfo = source.EdgeList.PageInfo
            };

            return(vm);
        }
        public void Index_SyncRequest_RetrievesPostsPropertyFromModel()
        {
            Mock <PostService> mock = new Mock <PostService>();

            mock.Setup(m => m.GetPage(It.IsAny <IEnumerable <PostDTO> >(), It.IsAny <int>())).Returns(new PostDTO[] {
                new PostDTO {
                    Id         = 2,
                    Title      = "Programmer",
                    Department = new DepartmentDTO {
                        Code = 123
                    },
                    NumberOfUnits = 1,
                    Salary        = 100000,
                    Premium       = 20000
                }
            });
            PostController controller = GetNewPostControllerWithControllerContext(mock.Object, null, null);

            ViewResult result = controller.Index(null, null) as ViewResult;

            PostListViewModel model = result.ViewData.Model as PostListViewModel;

            Assert.AreEqual(1, model.Posts.Count());
            Assert.AreEqual(2, model.Posts.FirstOrDefault().Id);
            Assert.AreEqual("Programmer", model.Posts.FirstOrDefault().Title);
        }
        public IActionResult Index([FromQuery] int?page)
        {
            var pageNumber = page == null || page <= 0 ? 1 : page.Value;

            var host  = Request.Scheme + "://" + Request.Host;
            var posts = _repository.GetPosts().Select(x => new PostsIndexViewModel
            {
                Id            = x.Id,
                Author        = x.Author,
                AuthorImage   = x.User.ImageUrl,
                Title         = x.Title,
                Description   = x.Description,
                ImageUrl      = x.ImageUrl,
                Category      = x.CategoryId,
                Link          = host + _repository.GetLink(x.Slug),
                DatePublished = x.DateCreated,
                CommentCount  = x.Comments.Count
            });
            var model = new PostListViewModel
            {
                PostsIndexViewModels = new PagedList <PostsIndexViewModel>(
                    posts,
                    pageNumber,
                    12)
            };

            return(View(model));
        }
        public IActionResult Categories([FromQuery] string Category, [FromQuery] int?page)
        {
            var pageNumber = page == null || page <= 0 ? 1 : page.Value;
            var host       = Request.Scheme + "://" + Request.Host;

            //if (String.IsNullOrWhiteSpace(Category))
            //{
            //    return RedirectToAction(nameof(Index));
            //}
            var posts = _repository.GetCategoryPosts(Category).Select(x => new PostsIndexViewModel
            {
                Id            = x.Id,
                Author        = x.Author,
                AuthorImage   = x.User.ImageUrl,
                Title         = x.Title,
                Description   = x.Description,
                ImageUrl      = x.ImageUrl,
                Category      = x.CategoryId,
                Link          = host + _repository.GetLink(x.Slug),
                DatePublished = x.DateCreated,
                CommentCount  = x.Comments.Count
            });
            var model = new PostListViewModel
            {
                PostsIndexViewModels = new PagedList <PostsIndexViewModel>(
                    posts,
                    pageNumber,
                    20)
            };

            ViewBag.Category = Category;
            return(View(model));
        }
        public IActionResult Search([FromQuery] string Search, [FromQuery] int?page)
        {
            var pageNumber = page == null || page <= 0 ? 1 : page.Value;

            if (String.IsNullOrWhiteSpace(Search))
            {
                return(RedirectToAction(nameof(Index)));
            }

            var posts = _repository.SearchPosts(Search).Select(post => new PostsIndexViewModel
            {
                Id            = post.Id,
                Author        = post.Author,
                Title         = post.Title,
                Description   = post.Description,
                ImageUrl      = post.ImageUrl,
                Link          = _repository.GetLink(post.Slug),
                Category      = post.CategoryId,
                DatePublished = post.DateCreated,
                CommentCount  = post.Comments.Count,
                Body          = post.Body,
                AuthorImage   = post.User.ImageUrl
            });
            var model = new PostListViewModel
            {
                Search = Search,
                PostsIndexViewModels = new PagedList <PostsIndexViewModel>(posts, pageNumber, 12)
            };

            return(View(model));
        }
Example #11
0
        public async Task <IActionResult> Index(int page = 1)
        {
            var model = new PostListViewModel();

            model.CurrentPage = page;
            model.PostCount   = await _dbContext.BlogPosts
                                .CountAsync(x => x.SiteId == _site.Id &&
                                            !x.IsDisabled &&
                                            !x.IsHidden);

            model.PageCount = model.PostCount.GetPageCountForResults(PageSize);
            var recordSkip = ExtensionMethods.CalculateRecordSkip(PageSize, page);

            model.Posts = await _dbContext.BlogPosts
                          .Where(x => x.SiteId == _site.Id &&
                                 !x.IsDisabled &&
                                 !x.IsHidden)
                          .OrderByDescending(x => x.PublishedOn)
                          .Skip(recordSkip)
                          .Take(PageSize)
                          .ProjectTo <PostModel>()
                          .ToListAsync();

            return(View(model));
        }
Example #12
0
        public ViewResult Feed(string category = null, int page = 1)
        {
            Debug.Write(RouteData.Values);

            var posts = postRepository.Posts
                        .Include(p => p.Channel)
                        .Include(p => p.User);

            if (category != null && category != "")
            {
                posts = posts.Where(p => p.Channel.Name.Equals(category));
            }

            var total = posts.Count();

            posts = posts.OrderByDescending(p => p.Timestamp)
                    .Skip((page - 1) * PageSize)
                    .Take(PageSize);

            var model = new PostListViewModel {
                Posts          = posts,
                PaginationInfo = new PaginationViewModel {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = total
                },
                CurrentCategory = category,
                User            = (User)HttpContext.Session["user"]
            };

            return(View(model));
        }
Example #13
0
        public PostListPage(PostListViewModel viewModel)
        {
            InitializeComponent();

            BindingContext = this.viewModel = viewModel;
            viewModel.LoadFeedCommand.Execute(null);
        }
Example #14
0
        public ViewResult Search(string text = "", int page = 1) //add comment
        {
            IEnumerable <Post> posts = repository.Posts.Where(p => p.Title.ToUpper().Contains(text.ToUpper()));

            if (posts.Count() == 0)
            {
                posts = repository.Posts.Where(p => p.Text.ToUpper().Contains(text.ToUpper()));

                //if (posts.Count() == 0)
                //  posts = repository.Posts.Where(p => p.Comments.Where(comment => comment.Text.ToUpper().Contains(text.ToUpper()));
            }

            PostListViewModel model = new PostListViewModel
            {
                Posts = posts
                        .OrderByDescending(post => post.DateChanged)
                        .Skip((page - 1) * pageSize)
                        .Take(pageSize),

                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = posts.Count(),
                },
                Ratings = repository.Ratings
            };

            return(View("List", model));
        }
        public void FilterScenario()
        {
            var viewModel = new PostListViewModel(navigationMock.Object,
                                                  service.Object,
                                                  progressBarMock.Object,
                                                  windowmanager.Object,
                                                  backgroundLoader.Object);

            ScreenExtensions.TryActivate(viewModel);

            viewModel.SearchText = "3";

            Assert.IsTrue(viewModel.OriginList.Count == 5);
            Assert.IsTrue(viewModel.PostList.Count == 1);

            viewModel.SearchText = " ";

            Assert.IsTrue(viewModel.PostList.Count == 5);

            viewModel.SearchText = string.Empty;

            Assert.IsTrue(viewModel.PostList.Count == 5);

            viewModel.SearchText = "abc";

            Assert.IsTrue(viewModel.PostList.Count == 2);

            viewModel.SearchText = "777";

            Assert.IsTrue(viewModel.PostList.Count == 1);

            viewModel.SearchText = "5";

            Assert.IsTrue(viewModel.PostList.Count == 1);
        }
Example #16
0
        public async Task <IActionResult> DeletePost(PostListViewModel model)
        {
            if (model == null)
            {
                ShowAlertDanger("Could not delete empty post.");
                return(RedirectToAction(nameof(Index)));
            }

            try
            {
                await _newsService.RemovePostAsync(model.Post.Id);

                ShowAlertSuccess($"Removed Post \"{model.Post.Title}\"!");
            }
            catch (GraException gex)
            {
                ShowAlertDanger("Unable to remove Post: ", gex);
            }

            return(RedirectToAction(nameof(Index), new
            {
                category = model.Category,
                page = model.PaginateModel.CurrentPage,
                search = model.Search
            }));
        }
Example #17
0
        public async Task <ViewResult> List(string category, int page = 1)
        {
            IEnumerable <Post> posts = repository.Posts
                                       .Where(p => category == null || category == p.Category.Name);

            User curentUser = await GetCurrentUserAsync();

            if (curentUser != null)
            {
                posts = posts.Where(p => ((p.Rating.Count() > 2) & p.ValueRating >= curentUser.MinimalToShow) || (p.Rating.Count() <= 2));
            }

            PostListViewModel model = new PostListViewModel
            {
                Posts = posts.OrderByDescending(post => post.ValueRating).
                        Skip((page - 1) * pageSize)
                        .Take(pageSize),

                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = posts.Count()
                },
                CurrentCategory = category,

                Ratings = repository.Ratings
            };

            return(View(model));
        }
Example #18
0
        public ViewResult List(int postPage = 1, string postId = "", string categoryId = "")
        {
            var posts = _postRepository.Posts;

            if (!String.IsNullOrEmpty(categoryId) && _categoryRepository.getCategory(categoryId) != null)
            {
                posts = posts.Where(elem => elem.CategoryId == categoryId);
            }
            PostListViewModel list = new PostListViewModel
            {
                Posts = posts
                        .OrderByDescending(p => p.PublishedDateTime)
                        .Skip((postPage - 1) * PageSize)
                        .Take(PageSize),
                PostToOpen = postId,
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = postPage,
                    ItemsPerPage = PageSize,
                    TotalItems   = posts.Count()
                }
            };

            return(View(list));
        }
Example #19
0
        public IActionResult Search([FromQuery] string search, [FromQuery] int?page)
        {
            var pageNumber = page == null || page <= 0 ? 1 : page.Value;
            var host       = Request.Scheme + "://" + Request.Host;

            if (String.IsNullOrWhiteSpace(search))
            {
                return(RedirectToAction(nameof(Index)));
            }

            var result = _blogRepository.SearchPosts(search).Select(x => new PostsIndexViewModel
            {
                Author        = x.Author,
                AuthorImage   = x.User.ImageUrl,
                Body          = x.Body,
                CommentCount  = x.Comments.Count,
                DatePublished = x.DateCreated,
                Description   = x.Description,
                Id            = x.Id,
                ImageUrl      = x.ImageUrl,
                Link          = host + _blogRepository.GetLink(x.Slug),
                Title         = x.Title
            });

            var model = new PostListViewModel
            {
                Search = search,
                PostsIndexViewModels = new PagedList <PostsIndexViewModel>(result, pageNumber, 15)
            };

            return(View(model));
        }
        public MainWindow()
        {
            InitializeComponent();
            IBloggersPointService bloggersPointService = new BloggersPointService();
            IMessageService       messageService       = new MessageService();

            DataContext = PostListViewModel.Instance(bloggersPointService, messageService);
        }
Example #21
0
        // GET: Builder/Widget
        public ActionResult RecentPostList()
        {
            var model = new PostListViewModel
            {
                PostList = _postService.Read(UserHelper.UserId, string.Empty).Take(6).ToList()
            };

            return(View("_RecentPostList", model));
        }
Example #22
0
        public IActionResult Index()
        {
            PostListViewModel postListViewModel = new PostListViewModel();

            postListViewModel.Posts = _postRepository.AllPosts;
            ViewBag.Title           = "List of Post";

            return(View(postListViewModel));
        }
Example #23
0
        public IViewComponentResult Invoke(List <PostView> pPostViews)
        {
            PostListViewModel model = new PostListViewModel
            {
                PostViews = pPostViews
            };

            return(View(model));
        }
Example #24
0
        public void Setup()
        {
            IBloggersPointService fakeBloggersPointService = new FakeBloggersPointService();
            var messageService = new Mock <IMessageService>().Object;

            _postListViewModel = new PostListViewModel(fakeBloggersPointService, messageService);
            _postListViewModel.PropertyChanged -= OnPropertyChanged;
            _postListViewModel.PropertyChanged += OnPropertyChanged;
            _isBusyPropertyChangedToTrue        = false;
        }
        public IActionResult Index(int categoryId)
        {
            var model = new PostListViewModel
            {
                Posts = categoryId > 0? _postService.GetByCategory(categoryId):_postService.GetAll()
            };

            //return View(_postService.GetListPostDetailDto());
            return(View(model));
        }
Example #26
0
        /// <summary>
        /// Index
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            var vm = new PostListViewModel
            {
                CurrentPageNumber = 1,
                Posts             = new List <PostViewModel>(),
            };

            return(View(vm));
        }
Example #27
0
        public async Task <IActionResult> Index()
        {
            var user = await userManager.GetUserAsync(User);

            var posts = await postRepository.GetListByUserId(user.Id);

            PostListViewModel model = mapper.Map <PostListViewModel>(posts);

            return(View(model));
        }
Example #28
0
        public ActionResult Index()
        {
            PostListViewModel model = new PostListViewModel();

            model.Posts = db.Posts
                          .Include(p => p.CreatedBy)
                          .Include(p => p.Comments)
                          .ToList();
            return(View(model));
        }
Example #29
0
        public void Guncelwall(int id)
        {
            List <int> friendlist = userfriendsrevice.GetAll(x => x.UserId == id && x.Active == true).ToArray().Select(x => x.FriendId).ToList();


            List <int> friendlist2 = userfriendsrevice.GetAll(x => x.FriendId == id && x.Active == true).ToArray().Select(x => x.UserId).ToList();


            List <int> allfriendsIds = friendlist.Concat(friendlist2).ToList();


            //List<WallViewModel> wallList = wallservice.GetAll(x => allfriendsIds.Contains(x.UserId)).ToArray().OrderByDescending(x=>x.DateEdited).Select(x=> new WallViewModel(x)).ToList();

            List <PostListViewModel> postlist = (from use in userService.Query <Users>()
                                                 join post in userService.Query <Post>() on use.Id equals post.UserId
                                                 where use.Id == id
                                                 select new PostListViewModel
            {
                username = use.Username,
                Text = post.Text,
                LikeCount = post.LikeCount,
                UserId = use.Id,
                CreatedDate = post.CreatedDate,
                postId = post.Id
            }).ToList();


            //List<PostListViewModel> postlist2 = postservice.GetAll(x => allfriendsIds.Contains(x.UserId)).Select(x => new PostListViewModel(x)).ToList();


            var postlist2 = (from uf in userfriendsrevice.Query <UserFriend>()
                             join p in userfriendsrevice.Query <Post>() on uf.FriendId equals p.UserId
                             join use in userfriendsrevice.Query <Users>() on p.UserId equals use.Id
                             where uf.UserId == id && uf.Active == true
                             select new PostListViewModel
            {
                Text = p.Text,
                CreatedDate = p.CreatedDate,
                username = use.Username,
                LikeCount = p.LikeCount,
                UserId = use.Id,
                postId = p.Id
            }).ToList();;


            List <PostListViewModel> wallList = postlist.Concat(postlist2).ToList();

            PostListViewModel model = wallList.OrderByDescending(x => x.CreatedDate).Take(1).FirstOrDefault();



            var clients = Clients.All;

            clients.guncelwallpost(model.UserId, model.Text, model.CreatedDate, model.username, model.postId);
        }
        public async Task <HttpResponseMessage> GetListPost(string languageCode, POSTSORT_TYPE priority = POSTSORT_TYPE.NEW, byte categoryId = 0, POST_TYPE type = POST_TYPE.ARTICLE, byte numTop = 0)
        {
            try
            {
                //Dictionary<string, object> para = new Dictionary<string, dynamic>();
                //var data =  await _iPostRepo.GetAll(languageCode, (int)CategoryId.Posts, NUM_TOP, (byte)priority);
                List <string> list = new List <string> {
                    "LanguageCode", "CategoryId", "numTop", "priority", "type"
                };
                Dictionary <string, dynamic> para = null;
                if (numTop == 0)
                {
                    numTop = Convert.ToByte(NUM_TOP);
                }

                para = APIProvider.APIDefaultParameter(list, languageCode, categoryId, numTop, (byte)priority, type);

                var data = await _iPostRepo.Query(para);

                var lstPost = Mapper.Map <List <PostListViewModel> >(data);
                var results = new List <PostListViewModel>();
                if (lstPost != null)
                {
                    foreach (var item in lstPost)
                    {
                        string image = item.Image;
                        if (item.Image != null && item.Image != "")
                        {
                            image = item.Image.Contains(ValueConstants.IMAGE_DEFAULT) == true ? null : PatientPortal.Provider.Common.AppConfig.HostAddress_CMS + item?.Image.Remove(0, 1);
                        }
                        var post = new PostListViewModel()
                        {
                            Id                = item.Id,
                            CategoryId        = item.CategoryId,
                            PublishDate       = item.PublishDate,
                            Image             = image,
                            Author            = item.Author,
                            TitleTran         = item.TitleTran,
                            DescriptionTrans  = item.DescriptionTrans,
                            CategoryName      = item.CategoryName,
                            WorkflowStateId   = item.WorkflowStateId,
                            WorkflowStateName = item.WorkflowStateName,
                            Detail            = item.Detail
                        };
                        results.Add(post);
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.OK, results));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Example #31
0
        public async Task Initialize(PostListViewModel viewModel, object sort, Comparison<Post> sortMethod )
        {
            var collection = App.Current.Client.GetCollection<Post>("posts");
            this.limit = Increment;
            this.sort = sort;

            this.viewModel = viewModel;
            this.viewModel.ShowLoadMore = false;
            this.viewModel.Posts = collection.Filter(sortFilter: sortMethod);

            ((INotifyCollectionChanged)collection).CollectionChanged +=
    (sender, args) => this.viewModel.ShowLoadMore = this.viewModel.Posts.Count >= this.limit;

            await this.LoadData();
        }
Example #32
0
        protected async override void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            this.viewModel = new PostListViewModel();
            this.DataContext = this.viewModel;
            await this.PostList.Initialize(this.viewModel, new BestSort() { Votes = -1, ID = -1, Submitted = -1 }, (post1, post2) =>
            {
                var votesComparison = post2.Votes.CompareTo(post1.Votes);

                if (votesComparison != 0)
                {
                    return votesComparison;
                }

                var timeComparison = post2.Submitted.DateTime.CompareTo(post1.Submitted.DateTime);

                if (timeComparison != 0)
                {
                    return timeComparison;
                }

                return post2.Id.CompareTo(post1.Id);
            });
        }
Example #33
0
 protected async override void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     this.viewModel = new PostListViewModel();
     this.DataContext = this.viewModel;
     await this.PostList.Initialize(this.viewModel, new Sort() { ID = -1, Submitted = -1 }, (post1, post2) => post2.Submitted.DateTime.CompareTo(post1.Submitted.DateTime));
 }