public IActionResult GetAll(string userName, string userMail, bool?isValid, uint skip, uint limit)
        {
            var criterias = new AdminUserSearchDto()
            {
                UserName = userName,
                Email    = userMail,
                IsValid  = isValid,
                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 <AdminUsrDto>(currentUrl, count, criterias)));
            }
        }
Esempio n. 2
0
        public int SearchCount(AdminUserSearchDto criterias)
        {
            Validate(criterias, ExtendValidationSearchCriterias);

            using (var c = RepositoriesFactory.CreateContext())
            {
                var userRepo = RepositoriesFactory.GetUserRepository(c);
                return(userRepo.GetAllByCriteriasCount(criterias.UserName, criterias.Email, criterias.IsValid));
            }
        }
Esempio n. 3
0
        private IList <ValidationResult> ExtendValidationSearchCriterias(AdminUserSearchDto c)
        {
            var resource = this.GetErrorStringLocalizer();
            IList <ValidationResult> result = new List <ValidationResult>();

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

            return(result);
        }
Esempio n. 4
0
        public IEnumerable <AdminUsrDto> Search(AdminUserSearchDto criterias)
        {
            Validate(criterias, ExtendValidationSearchCriterias);

            IList <User> users = null;

            using (var context = RepositoriesFactory.CreateContext())
            {
                var userRepo = RepositoriesFactory.GetUserRepository(context);

                users = userRepo.GetAllByCriterias(criterias.UserName, criterias.Email, criterias.IsValid,
                                                   criterias.Skip, criterias.Limit).ToList();
            }

            if (users != null)
            {
                return(users.ToAdminDto());
            }

            return(new List <AdminUsrDto>());
        }