public async Task <IActionResult> Index(string username, string filter, int?page) { UserPostsViewModel model = new UserPostsViewModel { Username = username, }; var pageNumber = page ?? 1; var currentUser = await this.userManager.GetUserAsync(this.User); if (filter == UserPostsFilter.Liked.ToString()) { model.Action = UserPostsFilter.Liked.ToString(); var posts = await this.userPostsService.ExtractLikedPostsByUsername(username, currentUser); model.Posts = posts.ToPagedList(pageNumber, GlobalConstants.BlogPostsOnPage); } else if (filter == UserPostsFilter.Created.ToString()) { model.Action = UserPostsFilter.Created.ToString(); var posts = await this.userPostsService.ExtractCreatedPostsByUsername(username, currentUser); model.Posts = posts.ToPagedList(pageNumber, GlobalConstants.BlogPostsOnPage); } return(this.View(model)); }
public IActionResult UserDetail(int Id, int pageNum = 1, int pageSize = 2) { var userPosts = new UserPostsViewModel(); var user = _context.appUsers.FirstOrDefault(x => x.Id == Id); userPosts.Id = user.Id; userPosts.UserName = user.UserName; userPosts.Gender = user.Gender; var posts = _context.posts.Where(x => x.UserId == Id).OrderBy(x => x.Id).Skip((pageNum - 1) * pageSize).Take(pageSize).Select( y => new PostReadViewModel { Id = y.Id, Title = y.Title, Content = y.Content, UserId = y.UserId } ).ToList(); userPosts.Posts = posts; int TotalPage = (int)Math.Ceiling(Decimal.Divide(_context.posts.Where(x => x.UserId == Id).ToList().Count, pageSize)); PaginationViewModel pagination = _paginationService.GetPagination(pageNum, pageSize, TotalPage); userPosts.Pagination = pagination; return(View(userPosts)); }
public UserPostsPage() { InitializeComponent(); DataContext = new UserPostsViewModel(); LoadingMoreShowAnimation = (Storyboard)FindResource( nameof(LoadingMoreShowAnimation)); LoadingMoreHideAnimation = (Storyboard)FindResource( nameof(LoadingMoreHideAnimation)); _autoUpdateCountTimer = new Timer(TimeSpan.FromSeconds(60).TotalMilliseconds); _autoUpdateCountTimer.Elapsed += AutoUpdateCountTimerCallback; _autoUpdateCountTimer.Stop(); //ReloadPostTypes(); //if (Enum.TryParse<PostType>( // Enum.GetName(typeof(PostType), SettingsManager.AppSettings.PostsType), // true, out var postType)) //{ // slcPostTypes.SelectedItem = // new KeyValuePair<PostType, string>(postType, PostTypes[postType]); //} //else //{ // slcPostTypes.SelectedItem = // new KeyValuePair<PostType, string>(PostType.Popular, PostTypes[PostType.Popular]); //} LocalizationUtils.LocalizationChanged += OnLocalizationChanged; SettingsManager.PersistentSettings.CurrentUserChanged += OnCurrentUserChanged; }
public UserPostsViewModel Get(string username) { User user = userDao.GetUser(username); UserPostsViewModel vm = new UserPostsViewModel() { Username = user.Username, Image = user.Image, UserPosts = postDAO.GetAllPostsByUserId(user.Id) }; return(vm); }
public UserPostsViewModel GetUserPosts(string userId, int?take = null, int skip = 0) { UserPostsViewModel userPosts = null; if (take.HasValue) { userPosts = new UserPostsViewModel { PagesCount = this.postsRepository.All().Where(x => x.FavoritePosts.Any(x => x.UserId == userId)).Count(), FavoritePosts = this.postsRepository.All() .Where(x => x.UserId == userId) .OrderByDescending(x => x.CreatedOn) .Select(x => new PostInCategoryViewModel { Id = x.Id, Content = x.Content, CategoryName = x.Category.Name, CreatedOn = x.CreatedOn, UserUserName = x.User.UserName, Title = x.Title, CommentsCount = x.Comments.Count(), }) .Skip(skip) .Take(10), }; } else { userPosts = new UserPostsViewModel { PagesCount = this.postsRepository.All().Where(x => x.FavoritePosts.Any(x => x.UserId == userId)).Count(), FavoritePosts = this.postsRepository.All() .Where(x => x.UserId == userId) .OrderByDescending(x => x.CreatedOn) .Select(x => new PostInCategoryViewModel { Id = x.Id, Content = x.Content, CategoryName = x.Category.Name, CreatedOn = x.CreatedOn, UserUserName = x.User.UserName, Title = x.Title, CommentsCount = x.Comments.Count(), }), }; } return(userPosts); }
public UserPostsViewModel Get(string username) { User searchResult = this.userDao.GetUser(username); IList <Post> usersPosts = this.postDAO.GetAllPostsByUserId(searchResult.Id); UserPostsViewModel output = new UserPostsViewModel() { Username = searchResult.Username, Image = searchResult.Image, UserPosts = usersPosts }; return(output); }
public async Task <IActionResult> UserPosts(string userId) { var posts = await _blogDbService.GetBlogPostsForUserId(userId); var username = ""; var firstPost = posts.FirstOrDefault(); if (firstPost != null) { username = firstPost.AuthorUsername; } var m = new UserPostsViewModel { Username = username, Posts = posts }; return(View(m)); }
public IActionResult Index(string username) { if (string.IsNullOrEmpty(username)) { return(View("LoginPage")); } //var postlist = postServer.FindAll().ToList(); var user = userServer.FindByName(username); var postlist = postServer.FindAll(user.UserId).ToList(); //if (user is null) //{ // return View("LogonPage"); //} var viewModel = new UserPostsViewModel() { PostList = postlist, User = user }; return(View(viewModel)); }