//Gets posts list with entries by selected category except for banned user's post(used in layout) public List <PostWithEntriesViewModel> GetPostListByCategoryWithEntries(int categoryId) { var user = _httpContext.HttpContext.User; int? UserId = null; List <int> blockedUserIdList = new List <int>(); //gets blocked user list if (user.Claims.Count() > 0) { UserId = int.Parse(user.Claims.ToList().First(x => x.Type == ClaimTypes.NameIdentifier).Value); foreach (var item in _blockedUserService.GetAll(UserId.Value)) { blockedUserIdList.Add(item.BlockedUserId); } } var List = new List <PostWithEntriesViewModel>(); var postsWithEntries = _postRepository.GetAllWithEntries(categoryId).ToList(); if (postsWithEntries != null) { foreach (var item in postsWithEntries) { var postModel = new PostWithEntriesViewModel(); postModel.Post.Id = item.Id; postModel.Post.CategoryId = item.CategoryId; postModel.Post.UserId = item.UserId; postModel.Post.Title = item.Title; postModel.Post.ClickCount = item.ClickCount; postModel.Post.UpdateDate = item.UpdateDate; postModel.Post.CreateDate = item.CreateDate; var entries = item.Entries.Where(x => !blockedUserIdList.Contains(x.UserId)).ToList(); if (entries != null) { foreach (var entry in entries) { var entryModel = new EntryViewModel(); entryModel.Content = entry.Content; entryModel.CreateDate = entry.CreateDate; entryModel.UpdateDate = entry.UpdateDate; entryModel.Id = entry.Id; entryModel.PostId = entry.PostId; entryModel.UserId = entry.UserId; postModel.EntryList.Add(entryModel); } } List.Add(postModel); } } return(List); }
public IActionResult BlockedUsers(int blockCurrentUserId) { ViewBag.queryGetBlockedUser = _blockedUserService.GetAll(blockCurrentUserId); return(View()); }
public IActionResult GetAll() { var result = _blockedUserService.GetAll(); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult UnblockUser(string UserId) { if (string.IsNullOrEmpty(UserId)) { return(RedirectToAction("Error")); } string id = _blockedUserService.GetAll().First(u => u.UserId == UserId).Id; _blockedUserService.Remove(id); return(RedirectToAction("Index")); }