Пример #1
0
        public async Task GetUsers_Success()
        {
            UserParams userParams = new UserParams
            {
                UserId     = _dataContext.Users.First(x => x.Gender == "female").Id,
                PageNumber = 1,
                PageSize   = 5,
                Gender     = "female"
            };

            var result = await _datingRepository.GetUsers(userParams);

            Assert.IsNotNull(result);
            // check that the users returned do not include the current user
            Assert.AreEqual(_dataContext.Users.Count(x => x.Gender == userParams.Gender) - 1, result.TotalCount);
            Assert.IsNull(result.FirstOrDefault(x => x.Id == userParams.UserId));
        }
Пример #2
0
        public async Task <IActionResult> GetUsers([FromQuery] UserParams userParams)
        {
            // List<User> a = new List<User>();
            // Console.WriteLine(a.Count());

            // if(HttpContext.Session.GetInt32("id") != null)
            // {
            //     var i = HttpContext.Session.GetInt32("id");
            //     return Ok(i);
            // }

            DatingRepository _rrepo = new DatingRepository(this._options);

            var currentUserId = int.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);

            // var userFromRepo = await _repo.GetUser(currentUserId);
            userParams.UserId = currentUserId;
            // if(string.IsNullOrEmpty(userParams.Gender))
            // {
            //     userParams.Gender = userFromRepo.Gender == "male" ? "female" : "male";
            // }

            var users = await _rrepo.GetUsers(userParams);

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

            // var a = userToReturn.AsQueryable().OrderBy(u => u.Gender);
            Response.AddPagination(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPage);
            var page = new PaginationHeader(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPage);

            // return Ok(userToReturn);
            return(Ok(new
            {
                page,
                userToReturn
            }));
        }