private bool IsUserMatchField(User user, IEnumerable <string> fieldFilter) { var objlvls = objectLevelRepository.GetAll().Where(x => x.ObjectId == user.OId).Select(x => x.FieldId); if (fieldFilter.Count() <= 0) { return(true); } foreach (var f in fieldFilter) { if (string.IsNullOrEmpty(f)) { return(true); } } foreach (var item in objlvls) { if (fieldFilter.Contains(item)) { return(true); } } return(false); }
public void Process(User source, UserViewModel destination, ResolutionContext context) { try { destination.PostCount = postRepository.GetAll().Count(x => x.AuthorId == source.OId && x.Status == ItemStatus.Active); destination.Followers = followRepository.GetAll().Count(x => x.ToId == source.OId); destination.Following = followRepository.GetAll().Count(x => x.FromId == source.OId); destination.FullName = $"{source.FirstName} {source.LastName}"; destination.FullAddress = $"{source.Address?.Detail}, {source.Address?.District}, {source.Address?.City}"; if (string.IsNullOrEmpty(source.AvatarHash)) { destination.AvatarHash = source.Avatar?.ImageHash; } var objectLevels = mapper.Map <IEnumerable <ObjectLevelViewModel> >(objectLevelRepository.GetAll().Where(x => x.ObjectId == source.OId && x.IsActive == true)); destination.Fields.AddRange(objectLevels); } catch (Exception e) { Console.WriteLine(e); } }
private bool IsMatch(PostViewModel post, Models.Request.LevelFilterItem levelFilterItem) { try { if (string.IsNullOrEmpty(levelFilterItem.FieldId)) { return(true); } var objlvls = objectLevelRepository.GetAll().Where(x => x.ObjectId == post.OId); foreach (var item in objlvls) { var lvlPost = levelRepository.GetAll().FirstOrDefault(x => x.OId == item.LevelId); if (item.FieldId == levelFilterItem.FieldId /*&& lvlFilter.Order <= lvlPost.Order*/) { return(true); } } return(false); } catch (Exception) { return(true); } }
public void Process(Post source, PostViewModel destination, ResolutionContext context) { try { var currentUser = Feature.CurrentUser(httpContextAccessor, userRepository); if (currentUser == null) { throw new UnauthorizedAccessException("Vui lòng đăng nhập. "); } var author = userRepository.GetById(ObjectId.Parse(source.AuthorId)); destination.AuthorName = $"{author?.FirstName} {author?.LastName}"; destination.AuthorAvatar = author?.AvatarHash; destination.AuthorEmail = author?.Email; destination.CommentCount = commentRepository.GetAll() .Where(x => x.Status == ItemStatus.Active && x.PostId == source.OId).Count(); var listUpVote = upVoteRepository.GetAll() .Where(x => x.ObjectVoteId == source.OId && x.IsDeleted == false); destination.Upvote = listUpVote.Count(); destination.IsVoteByCurrent = (listUpVote.FirstOrDefault(x => x.UpVoteBy == currentUser.OId) != null); var listDownVote = downVoteRepository.GetAll() .Where(x => x.ObjectVoteId == source.OId && x.IsDeleted == false); destination.Downvote = listDownVote.Count(); destination.IsDownVoteByCurrent = listDownVote.FirstOrDefault(x => x.DownVoteBy == currentUser.OId) != null; var objectLevels = objectLevelRepository.GetAll().Where(x => x.ObjectId == source.OId); var postObjecLevel = mapper.Map <IEnumerable <ObjectLevelViewModel> >(objectLevels); destination.IsSaveByCurrent = currentUser.PostSaved.Any(x => x == source.OId); destination.Field = postObjecLevel; switch (source.PostType) { case Common.Constants.PostType.Question: destination.PostTypeName = "Câu hỏi"; break; case Common.Constants.PostType.Sharing: destination.PostTypeName = "Chia sẻ"; break; default: destination.PostTypeName = "Câu hỏi"; break; } for (int i = 0; i < source.StringContents.Count(); i++) { if (source.StringContents[i].Content == null) { destination.StringContents[i].Content = String.Empty; } } var clientgroups = clientGroupRepository.GetAll().FirstOrDefault(x => x.Name == source.OId); if (clientgroups != null) { if (clientgroups.UserIds.Any(x => x == currentUser.OId)) { if (!currentUser.TurnOfNotification.Any(a => a == source.OId)) { destination.IsNotifyByCurrent = true; } else { destination.IsNotifyByCurrent = false; } } } } catch (Exception) { //Do nothing } }