示例#1
0
        public async Task <IActionResult> GetAsync([FromQuery] UserQueryParameters userQueryParameters)
        {
            var response = HttpContext.ValidateUserWithJWTClaim();

            if (response.errorMsg != null)
            {
                return(Unauthorized(new { message = "Invalid Token" }));
            }
            userQueryParameters.Id = int.Parse(response.id);
            userQueryParameters.loggedInUserGender = response.Gender;
            (IEnumerable <UserListDto> userLists, PagingMetadata data)result = await userService.GetAllUsersAsync(userQueryParameters);

            if (result.userLists == null)
            {
                return(BadRequest(new { message = "No user" }));
            }

            HttpContext.Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.data));
            HttpContext.Response.Headers.Add("X-Total-Count", result.data.TotalCount.ToString());

            return(Ok(new
            {
                data = result.userLists,
                CurrentPage = result.data.CurrentPage,
                TotalPages = result.data.TotalPages,
                PageSize = result.data.PageSize,
                TotalCount = result.data.TotalCount,
                HasPrevious = result.data.HasPrevious,
                HasNext = result.data.HasNext
            }));

            //  return Ok(result.userLists);
        }
示例#2
0
        public PagedList <Users> GetUsers(UserQueryParameters userQuery)
        {
            var collection = context.Users.AsQueryable();

            if (!string.IsNullOrWhiteSpace(userQuery.UserId) && int.TryParse(userQuery.UserId, out var intId))
            {
                collection = collection.Where(u => u.UserId == intId);
            }
            if (!string.IsNullOrWhiteSpace(userQuery.UserName))
            {
                collection = collection.Where(u => u.UserName.Contains(userQuery.UserName));
            }
            if (userQuery.IsLogged != null)
            {
                collection = collection.Where(u => u.IsLogged == true);
            }

            if (userQuery.TeacherId != null)
            {
                collection = collection.Where(u => u.TeacherId == userQuery.TeacherId);
            }
            if (userQuery.StudentId != null)
            {
                collection = collection.Where(u => u.StudentId == userQuery.StudentId);
            }
            if (userQuery.ParentId != null)
            {
                collection = collection.Where(u => u.ParentId == userQuery.ParentId);
            }

            collection = ReflectionHelper.PerformSorting <Users>(userQuery.OrderBy, collection);

            return(PagedList <Users> .Create(collection, userQuery.PageNumber, userQuery.PageSize));
        }
示例#3
0
        public ILabUser GetUser(UserQueryParameters query)
        {
            ILabService            labService     = new LabService();
            IEnumerable <ILabUser> availableUsers = labService.GetUsers(query).ToList();

            Assert.AreNotEqual(0, availableUsers.Count(), "Found no users for the given query.");
            return(availableUsers.First());
        }
示例#4
0
        public async Task <PagedList <User> > GetUsersAsync(UserQueryParameters userQueryParameters)
        {
            var columnMap = new Dictionary <string, Expression <Func <User, object> > >
            {
                ["username"]   = u => u.Username,
                ["city"]       = u => u.City,
                ["id"]         = u => u.Id,
                ["country"]    = u => u.Country,
                ["lastActive"] = u => u.LastActive,
            };

            var query = Get(includeProperties: new Expression <Func <User, object> > [] { p => p.PhotoSet }, filter: x => x.Id != userQueryParameters.Id);

            query = query.ApplyOrdering(userQueryParameters, columnMap);

            var filterArray = new  List <Expression <Func <User, bool> > >();

            if (string.IsNullOrEmpty(userQueryParameters.gender))
            {
                Gender y;
                if (userQueryParameters.loggedInUserGender.ToLowerInvariant() == "female")
                {
                    y = Gender.Male;
                }
                else
                {
                    y = Gender.Female;
                }

                filterArray.Add(x => x.Gender == y);
            }
            else
            {
                Gender y;
                if (userQueryParameters.gender.ToLowerInvariant() == "female")
                {
                    y = Gender.Female;
                }
                else
                {
                    y = Gender.Male;
                }
                filterArray.Add(x => x.Gender == y);
            }

            if (userQueryParameters.minAge != 18 || userQueryParameters.minAge != 99)
            {
                var minDob = DateTime.Today.AddYears(-userQueryParameters.maxAge - 1);
                var maxDob = DateTime.Today.AddYears(-userQueryParameters.minAge);

                filterArray.Add(x => x.DateOfBirth >= minDob && x.DateOfBirth <= maxDob);
            }

            query = query.ApplyFiltering(userQueryParameters, filterArray.ToArray());
            return(await PagedList <User> .CreateAsync(query, userQueryParameters.PageNumber, userQueryParameters.PageSize));
        }
        public PagedResponse <User> GetUsers(UserQueryParameters userQuery)
        {
            var x      = _dbContext.Users as IQueryable <User>;
            var result = new PagedResponse <User>
            {
                TotalItems = x.Count(),
                Items      = x.Skip(userQuery.PageSize * (userQuery.PageNumber - 1)).Take(userQuery.PageSize).Include(x => x.Tasks).ToList <User>()
            };

            return(result);
        }
        public ActionResult <PagedResponse <UserDto> > GetUsers([FromQuery] UserQueryParameters userQuery)
        {
            var users  = _repository.GetUsers(userQuery);
            var result = new PagedResponse <UserDto>
            {
                TotalItems = users.TotalItems,
                Items      = _mapper.Map <IEnumerable <UserDto> >(users.Items)
            };

            return(Ok(result));
        }
示例#7
0
        public async Task <IActionResult> GetUser([FromRoute] Guid id, UserQueryParameters parameters)
        {
            var userDto = await _userQuery.ExecuteGetResourceByIdAsync(id);

            if (userDto is null)
            {
                return(NotFound());
            }

            var links = CreateLinks(id, parameters.Fields);

            var outerFacingModel = userDto.ShapeData(parameters.Fields);

            outerFacingModel.TryAdd("Links", links);


            return(Ok(outerFacingModel));
        }
示例#8
0
        public async Task <IActionResult> GetUsers(UserQueryParameters parameters, [FromHeader(Name = "Accept")] string mediaType)
        {
            _logger.LogInformation("Querying for users");
            var userDtos = await _userQuery.ExecuteGetResourcesAsync(parameters);

            _logger.LogInformation($"Shaping user resource based of off field(s): {parameters.Fields}");
            var expandoObjects = userDtos.ShapeData(parameters.Fields);

            if (mediaType == "application/vnd.marvin.hateoas+json")
            {
                var outerFacingModels = CreateUsersWithLinks(userDtos, expandoObjects, parameters);

                _logger.LogInformation($"returning users resource");

                return(Ok(outerFacingModels));
            }

            _logger.LogInformation($"returning users resource");

            return(Ok(expandoObjects));
        }
示例#9
0
 public List <DTO_XYFUser> List(UserQueryParameters query)
 {
     return(this.UserRepository.List(query));
 }
示例#10
0
 public List <DTO_XYFUser> Get([FromUri] UserQueryParameters query)
 {
     return(this.UserManager.List(query ?? new UserQueryParameters()));
 }
示例#11
0
        private IEnumerable <ExpandoObject> CreateUsersWithLinks(IEnumerable <UserDto> userDtos, IEnumerable <ExpandoObject> expandoObjects, UserQueryParameters parameters)
        {
            var outerFacingModels = new List <ExpandoObject>();

            foreach (ExpandoObject user in expandoObjects)
            {
                foreach (UserDto dto in userDtos)
                {
                    user.TryAdd("Links", CreateLinks(dto.Id, parameters.Fields));
                    outerFacingModels.Add(user);
                }
            }

            return(outerFacingModels);
        }