Ejemplo n.º 1
0
        public async Task <PagedList <User> > GetUsers(UserSearchParameter userParam)
        {
            var userList = _context.User.Include(i => i.UserPhoto).AsQueryable();

            userList = userList.Where(i => i.Id != userParam.UserId && i.Gender == userParam.Gender);
            if (userParam.Like.HasValue)
            {
                var userLikeId = await GetUserLikes(userParam.UserId, userParam.Like.Value);

                userList = userList.Where(i => userLikeId.Contains(i.Id));
            }

            var minDateBirth = DateTime.Now.AddYears(-userParam.MaxAge - 1);
            var maxDateBirth = DateTime.Now.AddYears(-userParam.MinAge);

            userList = userList.Where(p => p.DateOfBirth.Year >= minDateBirth.Year && p.DateOfBirth.Year <= maxDateBirth.Year);

            if (userParam.OrderBy == "created")
            {
                userList = userList.OrderByDescending(i => i.RegisterDate);
            }
            else
            {
                userList = userList.OrderByDescending(i => i.ModifyDate);
            }

            return(await PagedList <User> .CreateAsync(userList, userParam.PageNumber, userParam.PageSize));
        }
Ejemplo n.º 2
0
        public async Task <PagingResult <TViewModel> > GetsAsync <TViewModel>(bool NeedDBCount, UserSearchParameter xParameters = null)
        {
            if (xParameters == null)
            {
                xParameters = new UserSearchParameter();
            }
            #region OrderBy
            Func <IQueryable <User>, IOrderedQueryable <User> > xOrderBy = p => p.OrderByDescending(x => x.Id);
            if (xParameters.xSortBy == "Date")
            {
                if (xParameters.xSortType == "Des")
                {
                    xOrderBy = p => p.OrderByDescending(x => x.Id);
                }
                else
                {
                    xOrderBy = p => p.OrderBy(x => x.Id);
                }
            }
            else if (xParameters.xSortBy == "xUsername")
            {
                if (xParameters.xSortType == "Des")
                {
                    xOrderBy = p => p.OrderByDescending(x => x.UserName);
                }
                else
                {
                    xOrderBy = p => p.OrderBy(x => x.UserName);
                }
            }
            else if (xParameters.xSortBy == "xEmail")
            {
                if (xParameters.xSortType == "Des")
                {
                    xOrderBy = p => p.OrderByDescending(x => x.Email);
                }
                else
                {
                    xOrderBy = p => p.OrderBy(x => x.Email);
                }
            }
            #endregion

            #region Filter
            Expression <Func <User, bool> > xFilter = p => p.xIsActive;
            if (!string.IsNullOrEmpty(xParameters.xUsername))
            {
                xFilter = xFilter.And(x => x.UserName.Contains(xParameters.xUsername));
            }
            if (xParameters.xIsActive != null)
            {
                xFilter = xFilter.And(x => x.xIsActive == xParameters.xIsActive);
            }

            #endregion

            return(await uow.UserRepository.GetAsync <TViewModel>(NeedDBCount, xFilter, xOrderBy, xParameters.xPage, xParameters.xPageSize));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetAll([FromQuery] UserSearchParameter userSearchParameter)
        {
            userSearchParameter.UserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var currentUser = await _DatingRepository.GetUser(userSearchParameter.UserId);

            if (string.IsNullOrWhiteSpace(userSearchParameter.Gender))
            {
                userSearchParameter.Gender = currentUser.Gender == "male" ? "female" : "male";
            }

            var users = await _DatingRepository.GetUsers(userSearchParameter);

            var userDtos = _mapper.Map <IEnumerable <UserForListDto> >(users);

            Response.AddPagination(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages);
            return(Ok(userDtos));
        }
 public async Task <IActionResult> Post([FromBody] UserSearchParameter searchParameters)
 {
     return(await ProcessSearchRequest(searchParameters.ClientId, searchParameters.UserIds).ConfigureAwait(false));
 }
Ejemplo n.º 5
0
 public async Task <GeneralResult> GetAll([FromQuery] UserSearchParameter xParams)
 {
     return(Ok(await _UserService.GetsAsync <UserListVM>(true, xParams)));
 }
Ejemplo n.º 6
0
 public JsonResult Search(UserSearchParameter parameter)
 {
     return(Json(""));
 }