Esempio n. 1
0
        public async Task <IEnumerable <User> > GetByFilterLinqJoins(UsersFilter filter)
        {
            var filterSpec = await _userSpecFactory.GetFilterSpec(filter);

            var results = DbSet.Where(filterSpec.SatisfiedBy())
                          .GroupJoin(DbContext.Characters, u => u.Id, c => c.User.Id, (u, c) =>
                                     new User
            {
                Id             = u.Id,
                UserName       = u.UserName,
                UserMail       = u.UserMail,
                Country        = u.Country,
                CountryZone    = u.CountryZone,
                IsActive       = u.IsActive,
                EnrollmentDate = u.EnrollmentDate,
                DischargeDate  = u.DischargeDate,
                Characters     = c.GroupJoin(DbContext.Stats,
                                             chars => chars.Id,
                                             charStats => charStats.Character.Id,
                                             (chars, charStats) =>
                                             new Character
                {
                    Id           = chars.Id,
                    CharName     = chars.CharName,
                    CharType     = chars.CharType,
                    CharBaseType = chars.CharBaseType,
                    Faction      = chars.Faction,
                    PlayerStats  = charStats.ToList()
                })
                                 .ToList()
            })
                          .ToList();

            return(results);
        }
 public UserController(UserServices userServices, RoleServices roleServices, MessageServices messageServices, UsersFilter usersFilter)
 {
     this.roleServices = roleServices;
     this.userServices = userServices;
     this.messageServices = messageServices;
     this.usersFilter = usersFilter;
 }
Esempio n. 3
0
        private static IMongoQuery Filters(UsersFilter filter)
        {
            var list = new List <IMongoQuery> {
                Query <User> .EQ(x => x.Blocked, filter.Blocked)
            };

            if (filter == null)
            {
                return(Query.And(list));
            }

            if (!string.IsNullOrEmpty(filter.Name))
            {
                list.Add(Query <User> .Matches(x => x.Name, $"(?i).*{string.Join(".*", Regex.Split(filter.Name, @"\s+").Select(x => Regex.Escape(x)))}.*"));
            }

            if (!string.IsNullOrEmpty(filter.Email))
            {
                list.Add(Query <User> .Matches(x => x.Email, $"(?i).*{string.Join(".*", Regex.Split(filter.Email, @"\s+").Select(x => Regex.Escape(x)))}.*"));
            }

            if (!string.IsNullOrEmpty(filter.Cpf))
            {
                list.Add(Query <User> .EQ(x => x.Cpf, filter.Cpf));
            }

            return(Query.And(list));
        }
Esempio n. 4
0
        public async Task <(IList <BlogUser> users, int totalUsers)> GetUsers(UsersFilter filter)
        {
            var query = _context.Users
                        .AsNoTracking();

            query = QueryUsersBySearchText(query, filter.Search);

            List <User> users = null;

            var count = await query.CountAsync();

            if (count != 0)
            {
                var skip = (filter.Page - 1) * filter.PageSize;
                users = await query
                        .OrderBy(x => x.Id)
                        .Skip(skip)
                        .Take(filter.PageSize)
                        .ToListAsync();
            }

            var dtoUsers = users?.Select(x => Mapper.ConvertToModel(x))?.ToList();

            return(dtoUsers, count);
        }
Esempio n. 5
0
        public async Task<PageResultModel<UserModel>> GetList(UsersFilter filter)
        {
            var query = _db.Users.AsQueryable();

            if (filter.Type != null)
                query = query.Where(x =>
                    x.LoginId.HasValue && x.LoginId.Value == _db.Logins.FirstOrDefault(y => y.Type == filter.Type).Id);

            if (filter.UserName != null) query = query.Where(x => x.UserName == filter.UserName);

            var count = await query.CountAsync();

            query = query.OrderByDescending(x => x.Id)
                .Skip((filter.Page - 1) * filter.Size)
                .Take(filter.Size);

            var list = await MapQuery(query).ToListAsync();

            return new PageResultModel<UserModel>
            {
                Size = filter.Size,
                Page = filter.Page,
                TotalCount = count,
                List = list
            };
        }
Esempio n. 6
0
 public async Task <IPagedResult <UserModel> > Get([FromQuery] UsersFilter filter)
 {
     using (_context.Scope())
     {
         return(await _usersDataProvider.Get().Where(x => x.Id != HttpContext.User.GetUserId())
                .Select(x => new UserModel(x)).GetPagedResultAsync(filter));
     }
 }
Esempio n. 7
0
        public void FilterByValueTest(string value, int[] userIds)
        {
            var filter = new UsersFilter {
                Value = value
            };
            var result = filter.Filter(_users).ToList();

            AssertOnlyConatainsItems(result, userIds);
        }
Esempio n. 8
0
        public async Task <IEnumerable <User> > GetByFilterSpecification(UsersFilter filter)
        {
            var filterSpec = await _userSpecFactory.GetFilterSpec(filter);

            return(DbSet.Include(u => u.Characters)
                   .ThenInclude(c => c.PlayerStats)
                   .Where(filterSpec.SatisfiedBy())
                   .AsEnumerable());
        }
        public PaginatedResults <AppUserDTO> GetUsers(UsersFilter filter)
        {
            filter.NormalizeValues();
            var query = filter.Apply(ERSAIDB.Users);

            query = query.OrderBy(u => u.UserName);
            var result = filter.ApplyPagination(query, ef => new AppUserDTO(ef));

            return(result);
        }
        public async Task <IActionResult> GetByLinqAndFilter([FromBody] UsersFilter filter)
        {
            var response = await _userService.GetByFilterAndLinqJoins(filter);

            if (response != null)
            {
                return(Ok(response));
            }

            return(BadRequest());
        }
Esempio n. 11
0
        public ResultMessage GetAll(UsersFilter filter)
        {
            PagedResult <User> result = new PagedResult <User>();
            var users = _unitOfWork.UsersRepository.Get().ApplyFilter(filter).OrderBy(c => c.UserName).GetPaged(filter.PageNo, filter.PageSize).Adapt(result);

            return(new ResultMessage()
            {
                Data = users,
                Status = HttpStatusCode.OK
            });
        }
Esempio n. 12
0
        public async Task <List <User> > List(UsersFilter model)
        {
            this.SetHeaders();
            var url = QueryStringBuilder.BuildUrl("users", model);

            var response = await Client.GetAsync(url);

            HandleResponse(response);
            var result = await response.Content.ReadAsAsync <List <User> >();

            return(result);
        }
Esempio n. 13
0
        public async Task ListAllUsers()
        {
            var filters = new UsersFilter()
            {
                Page    = 2,
                PerPage = 5
            };

            var users = await new UserService().List(filters);

            Assert.IsNotNull(users[0]?.Id);
        }
        public UsersModel GetUsers(UsersFilter filter)
        {
            string searchTextQuery = "";
            string subquery        = "";
            string filterQuery     = "";
            string CountTextQuery  = "";

            if (!string.IsNullOrWhiteSpace(filter.SearchText))
            {
                searchTextQuery = " c.Name like '%" + filter.SearchText + "%' or c.Mobile like '%" + filter.SearchText + "%' or c.Email like '%" + filter.SearchText + "%' or c.Address like '%" + filter.SearchText + "%' and ";
                CountTextQuery  = " where c.Name like '%" + filter.SearchText + "%' or c.Mobile like '%" + filter.SearchText + "%' or c.Email like '%" + filter.SearchText + "%' or c.Address like '%" + filter.SearchText + "%' and ";
            }

            List <Users> OpportunityList = new List <Users>();

            string rawQuery = @"  
                                declare @pagesize int
                                declare @pageno int 
                                set @pagesize = " + filter.UnitPerPage + @"
                                set @pageno = " + filter.PageNumber + @"
                                declare @pagestart int
                                set @pagestart=(@pageno-1)* @pagesize  
                                select  TOP (@pagesize) c.* FROM Users c
                           
                                where {1}{2}  c.Id NOT IN(Select TOP (@pagestart) Id from Users {0})
                                {0}
                               ";

            string CountQuery = string.Format("Select * from Users c {0}", CountTextQuery);

            rawQuery = string.Format(rawQuery, subquery, searchTextQuery, filterQuery);
            int          TotalCount = 0;
            List <Users> dsResult   = new List <Users>();

            try
            {
                var ctx = DataContext.getInstance();
                dsResult   = ctx.Users.SqlQuery(rawQuery).ToList();
                TotalCount = ctx.Users.SqlQuery(CountQuery).ToList().Count;
            }
            catch (Exception ex)
            {
            }

            UsersModel usersModel = new UsersModel();

            usersModel.UsersList = dsResult;

            //context.Dispose();
            usersModel.TotalCount = TotalCount;
            return(usersModel);
        }
Esempio n. 15
0
        public async Task <ActionResult> Get([FromQuery] UsersFilter filter)
        {
            var model = new UserDto
            {
                Id        = filter.Id,
                FirstName = filter.FirstName,
                LastName  = filter.LastName
            };

            var users = await _usersQuery.FindBy(model);

            return(Ok(users));
        }
Esempio n. 16
0
        public async Task <IActionResult> Filter(UsersFilter filter)
        {
            bool includeDeleted = filter.IncludeDeleted && ClaimsExtension.IsAdmin(HttpContext);
            var  users          = (
                from u in _context.User
                where u.FirstName.Contains(filter.FirstName ?? "") &&
                u.LastName.Contains(filter.LastName ?? "") &&
                u.UserName.Contains(filter.UserName ?? "") &&
                (includeDeleted || !u.IsDeleted)
                select new { u.Id, u.UserName, u.FullName, u.EMail, u.IsAdmin, u.IsDeleted }
                );

            return(Json(users));
        }
Esempio n. 17
0
        public async Task <IActionResult> Authors([FromQuery] UsersFilter filter)
        {
            filter = filter ?? new UsersFilter();

            var result = await _usersService.GetUsers(filter);

            var usersVM      = result.Elements?.Select(x => (UserViewModel)x)?.ToList() ?? Enumerable.Empty <UserViewModel>();
            var pagedUsersVM = new StaticPagedList <UserViewModel>(usersVM, filter.Page, filter.PageSize, result.TotalElements);

            return(View(new UsersListViewModel
            {
                Filter = filter,
                Users = pagedUsersVM
            }));
        }
Esempio n. 18
0
        public async Task <UserListModel> GetUsers([FromBody] AllUserRequestModel options)
        {
            _identityService.RetrieveUserAsync().Wait();

            var userQuery = _userManager.Users
                            .Where(UsersFilter.AllUsersFilter(_identityService.User, _identityService.Groups, DATABASE_OPERATION.READ, _serviceProvider))
                            .AddConditionalWhereFilter(options.SearchConditions)
                            .AddOrderBys(options.SortConditions);

            return(new UserListModel
            {
                countUsers = await userQuery.CountAsync(),
                Users = userQuery
                        .AddPagination(new Pagination(options.PaginationOptions))
                        .ToList()
                        .Select(u => new UserDto(u))
            });
        }
Esempio n. 19
0
        public async Task <IActionResult> DeactivateUser([FromBody] UsernameModel deactivateUser)
        {
            _identityService.RetrieveUserAsync().Wait();

            var user = _userManager.Users
                       .Where(UsersFilter.AllUsersFilter(_identityService.User, _identityService.Groups, DATABASE_OPERATION.UPDATE, _serviceProvider))
                       .FirstOrDefault(u => u.UserName == deactivateUser.Username);

            if (user == null)
            {
                return(BadRequest("The user does not exist or you do not have permission to deactivate the user"));
            }

            user.EmailConfirmed = false;
            await _userManager.UpdateAsync(user);

            return(Ok());
        }
        public ActionResult LoadUsersList(UsersFilter filter)
        {
            if (filter.PageNumber == 0)
            {
                filter.PageNumber = 1;
            }
            filter.UnitPerPage = 12;

            if (filter.PageNumber == null || filter.PageNumber == 0)
            {
                filter.PageNumber = 1;
            }
            UsersModel UsersList = usersFacade.GetUsers(filter);

            ViewBag.OutOfNumber = UsersList.TotalCount;
            if ((int)ViewBag.OutOfNumber == 0)
            {
                ViewBag.Message = "No Content Available !";
            }
            if (@ViewBag.OutOfNumber == 0)
            {
                filter.PageNumber = 1;
            }
            ViewBag.PageNumber = filter.PageNumber;

            if ((int)ViewBag.PageNumber * filter.UnitPerPage > (int)ViewBag.OutOfNumber)
            {
                ViewBag.CurrentNumber = (int)ViewBag.OutOfNumber;
            }
            else
            {
                ViewBag.CurrentNumber = (int)ViewBag.PageNumber * filter.UnitPerPage;
            }

            ViewBag.PageCount = Math.Ceiling((double)ViewBag.OutOfNumber / filter.UnitPerPage.Value);
            return(View(UsersList.UsersList));
        }
Esempio n. 21
0
 public Task <(IList <BlogUser> users, int totalUsers)> GetUsers(UsersFilter filter)
 {
     return(_userRepository.GetUsers(filter));
 }
        public async Task <IActionResult> GetAllUsers([FromQuery] PaginationQuery paginationQuery, [FromQuery] UsersFilter filter)
        {
            var usersResponse = await _accountService.GetUsersAsync();

            if (paginationQuery is null || paginationQuery.PageSize < 1 || paginationQuery.PageNumber < 1)
            {
                return(Ok(new PagedResponse <UserModel>(usersResponse)));
            }

            usersResponse = await _accountService.GetUsersAsync(paginationQuery, filter);

            var paginationResponse = PaginationProvider.CreatePaginatedResponse(_uriService,
                                                                                $"api/{ControllerContext.ActionDescriptor.ControllerName}/{Constants.Routes.USERS_GET_ALL_ROUTE}",
                                                                                paginationQuery, filter, usersResponse);

            return(Ok(paginationResponse));
        }
 public UsersModel GetUsers(UsersFilter filter)
 {
     return(userRepository.GetUsers(filter));
 }
Esempio n. 24
0
 public IEnumerable <UserAdminView> GetAllUsersForAdmin(ObjectForUsersFilter objectForUsersFilter)
 {
     return(UsersFilter.GetFilteredUsers(objectForUsersFilter));
 }
Esempio n. 25
0
 public UsersFilterSpecification(UsersFilter usersFilter)
 {
     _usersFilter = usersFilter;
 }
Esempio n. 26
0
 public IEnumerable <User> List(UsersFilter filter) => Collection.Find(Filters(filter));
Esempio n. 27
0
 public IActionResult Users([FromBody] UsersFilter filter) => Ok(_blUsers.List(filter));
Esempio n. 28
0
        public async Task <IActionResult> Get([FromQuery] PaginationQuery paginationQuery, [FromQuery] UsersFilter filters)
        {
            var paginationFilter = this.mapper.Map <PaginationFilter>(paginationQuery);
            var model            = this.mapper.Map <ListAllUsersQuery>(paginationFilter);

            model.Filters = this.mapper.Map <ListAllUsersQueryFilter>(filters);
            var result = await this.Mediator.Send(model);

            return(this.Ok(result));
        }
Esempio n. 29
0
        public static IQueryable <Shared.Core.Models.AspNetUsers> ApplyFilter(this IQueryable <Shared.Core.Models.AspNetUsers> users, UsersFilter filter)
        {
            if (filter == null)
            {
                return(users);
            }

            if (!string.IsNullOrEmpty(filter.Role))
            {
                users = users.Where(c => c.AspNetUserRoles.Any(r => r.Role.Name == filter.Role));
            }

            if (filter.IsBlocked.HasValue)
            {
                users = users.Where(c => c.IsBlocked == filter.IsBlocked);
            }

            if (!string.IsNullOrEmpty(filter.SearchText))
            {
                users = users.Where(p => p.FullName.ToLower().Contains(filter.SearchText.ToLower()) || p.Email.ToLower().Contains(filter.SearchText.ToLower()));
            }

            return(users);
        }
 public async Task <UsersFilterSpecification> GetFilterSpec(UsersFilter filter)
 {
     return(new UsersFilterSpecification(filter));
 }
Esempio n. 31
0
        public async Task <PagedResult <BlogUser> > GetUsers(UsersFilter filter)
        {
            var(users, totalUsers) = await _userRepository.GetUsers(filter);

            return(new PagedResult <BlogUser>(users, totalUsers));
        }
 public UserController(IUserServices userServices, IRoleServices roleServices, IMessageServices messageServices, UsersFilter usersFilter)
     :base(userServices, messageServices, roleServices)
 {
     this.usersFilter = usersFilter;
 }