Exemplo n.º 1
0
        public IActionResult GetAll(string name, string publicId, string clientType, uint skip, uint limit)
        {
            var criterias = new ClientSearchDto()
            {
                Name       = name,
                PublicId   = publicId,
                ClientType = clientType,
                Skip       = skip,
                Limit      = limit
            };

            var count = _service.SearchCount(criterias);

            Request.HttpContext.Response.Headers.Add("X-Total-Count", count.ToString());
            if (Request.Method.Equals("head", StringComparison.OrdinalIgnoreCase))
            {
                return(Ok());
            }
            else
            {
                var clients    = _service.Search(criterias);
                var currentUrl = UriHelper.GetDisplayUrl(Request);
                return(Ok(clients.ToSearchResult <ClientDto>(currentUrl, count, criterias)));
            }
        }
Exemplo n.º 2
0
        private IList <ValidationResult> ExtendValidationSearchCriterias(ClientSearchDto c)
        {
            var resource = this.GetErrorStringLocalizer();
            IList <ValidationResult> result = new List <ValidationResult>();

            if (c.Limit - c.Skip > 50)
            {
                result.Add(new ValidationResult(String.Format(resource["SearchClientAskTooMuch"], c)));
            }

            return(result);
        }
Exemplo n.º 3
0
        public int SearchCount(ClientSearchDto criterias)
        {
            Validate(criterias, ExtendValidationSearchCriterias);

            var count = 0;

            using (var c = RepositoriesFactory.CreateContext())
            {
                var userClientRepo = RepositoriesFactory.GetClientRepository(c);
                count = userClientRepo.GetAllByCriteriasCount(criterias.Name, criterias.PublicId, true, GetClientTypeId(criterias.ClientType));
            }

            return(count);
        }
Exemplo n.º 4
0
        public async Task <PagingViewModel> Search(int page, int pageSize, ClientSearchDto dto)
        {
            var clientsCount = await _dbContext.Clients.CountAsync(x =>
                                                                   (dto.IdentityNo == null || x.IdentityNo == dto.IdentityNo) &&
                                                                   (string.IsNullOrEmpty(dto.Address) || x.Address.Contains(dto.Address)) &&
                                                                   (string.IsNullOrEmpty(dto.Name) || x.Address.Contains(dto.Name)) &&
                                                                   (string.IsNullOrEmpty(dto.PhoneNumber) || x.Address.Contains(dto.PhoneNumber)) &&
                                                                   (string.IsNullOrEmpty(dto.Mediator) || x.Mediator.Contains(dto.Mediator)));


            var pagesCount = (int)Math.Ceiling(clientsCount / (double)pageSize);

            if (page > pagesCount || page < 1)
            {
                page = 1;
            }


            var skipVal = (page - 1) * pageSize;

            var clients = await _dbContext.Clients.Where(x =>
                                                         (dto.IdentityNo == null || x.IdentityNo == dto.IdentityNo) &&
                                                         (string.IsNullOrEmpty(dto.Address) || x.Address.Contains(dto.Address)) &&
                                                         (string.IsNullOrEmpty(dto.Name) || x.Address.Contains(dto.Name)) &&
                                                         (string.IsNullOrEmpty(dto.PhoneNumber) || x.Address.Contains(dto.PhoneNumber)) &&
                                                         (string.IsNullOrEmpty(dto.Mediator) || x.Mediator.Contains(dto.Mediator)))
                          .Skip(skipVal).Take(pageSize).ToListAsync();

            var clientsViewModel = _mapper.Map <List <ClientViewModel> >(clients);


            return(new PagingViewModel()
            {
                CurrentPage = page,
                Data = clientsViewModel,
                PagesCount = pagesCount
            });
        }
Exemplo n.º 5
0
        public IEnumerable <ClientDto> Search(ClientSearchDto criterias)
        {
            Logger.LogInformation("Search clients");

            Validate(criterias, ExtendValidationSearchCriterias);

            IList <Client> clients = null;

            var clientTypeId = GetClientTypeId(criterias.ClientType);

            using (var context = RepositoriesFactory.CreateContext())
            {
                var clientRepo = RepositoriesFactory.GetClientRepository(context);

                clients = clientRepo.GetAllByCriterias(
                    criterias.Name,
                    criterias.PublicId,
                    true,
                    clientTypeId,
                    criterias.Skip,
                    criterias.Limit
                    ).ToList();

                var invalidsRs = ExtractInvalidRessourceServerIds(context);

                foreach (var c in clients)
                {
                    if (c.ClientsScopes != null && c.ClientsScopes.Count() > 0)
                    {
                        c.ClientsScopes = c.ClientsScopes.ToList().Where(cs => !invalidsRs.Contains(cs.Scope.RessourceServerId)).ToList();
                    }
                }
            }

            return(clients != null?clients.ToDto() : new List <ClientDto>());
        }