Exemplo n.º 1
0
        public Result <Select2Result <Select2ItemBase> > GetGlobalRoles(Select2Request select2Request)
        {
            ValidationResult validationResult = _select2RequestValidator.Validate(select2Request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(Select2Request)} model");
                return(Result.Fail <Select2Result <Select2ItemBase> >(validationResult.Errors));
            }

            SelectSpecification <RoleEntity, Select2ItemBase> selectSpecification =
                new SelectSpecification <RoleEntity, Select2ItemBase>();

            selectSpecification.AddFilter(x => x.Type == Core.Data.Enums.Entity.RoleTypes.Global);

            if (!string.IsNullOrEmpty(select2Request.Term))
            {
                selectSpecification.AddFilter(x => x.NormalizedName.Contains(select2Request.Term.ToUpper()));
            }

            selectSpecification.AddSelect(x => new Select2ItemBase(
                                              x.Id,
                                              x.Name));

            List <Select2ItemBase> roles = _roleRepository.GetList(selectSpecification);

            Select2Result <Select2ItemBase> select2Result = new Select2Result <Select2ItemBase>(
                results: roles);

            return(Result.Ok(select2Result));
        }
Exemplo n.º 2
0
        public Result <Select2Result <Select2ItemBase> > GetAvailable(Select2Request select2Request)
        {
            ValidationResult validationResult = _select2Validator.Validate(select2Request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(Select2Request)} model");
                return(Result.Fail <Select2Result <Select2ItemBase> >(validationResult.Errors));
            }

            SelectSpecification <AppUserEntity, Select2ItemBase> selectSpecification = new SelectSpecification <AppUserEntity, Select2ItemBase>();

            selectSpecification.AddFilter(x => x.Groups.Count == 0); // TODO: change this maybe

            if (!string.IsNullOrEmpty(select2Request.Term))
            {
                selectSpecification.AddFilter(x => x.NormalizedUserName.Contains(select2Request.Term));
            }

            selectSpecification.AddSelect(x => new Select2ItemBase(
                                              x.Id,
                                              x.UserName));

            List <Select2ItemBase> users = _userRepository.GetList(selectSpecification);

            Select2Result <Select2ItemBase> select2Result = new Select2Result <Select2ItemBase>(
                results: users);

            return(Result.Ok(select2Result));
        }
Exemplo n.º 3
0
        public Result <Select2Result <Select2ItemBase> > GetGroups(Select2Request select2Request)
        {
            ValidationResult validationResult = _select2RequestValidator.Validate(select2Request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(Select2Request)} model");
                return(Result.Fail <Select2Result <Select2ItemBase> >(validationResult.Errors));
            }

            SelectSpecification <GroupEntity, Select2ItemBase> selectSpecification =
                new SelectSpecification <GroupEntity, Select2ItemBase>();

            if (!string.IsNullOrEmpty(select2Request.Term))
            {
                selectSpecification.AddFilter(x => x.Name.ToUpper().Contains(select2Request.Term.ToUpper()));
            }

            selectSpecification.AddSelect(x => new Select2ItemBase(
                                              x.Id,
                                              x.Name));

            List <Select2ItemBase> groups = _groupRepository.GetList(selectSpecification);

            Select2Result <Select2ItemBase> select2Result = new Select2Result <Select2ItemBase>(
                results: groups);

            return(Result.Ok(select2Result));
        }
        public Result <Select2Result <Select2ItemBase> > GetAvailable(string roleId, Select2Request select2Request)
        {
            ValidationResult validationResult = _select2Validator.Validate(select2Request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(Select2Request)} model");
                return(Result.Fail <Select2Result <Select2ItemBase> >(validationResult.Errors));
            }

            SelectSpecification <PermissionEntity, Select2ItemBase> selectSpecification = new SelectSpecification <PermissionEntity, Select2ItemBase>();

            selectSpecification.AddFilter(x => !x.Roles.Select(c => c.RoleId).Contains(roleId));
            if (!string.IsNullOrEmpty(select2Request.Term))
            {
                selectSpecification.AddFilter(x => x.Name.ToUpper().Contains(select2Request.Term.ToUpper()));
            }

            selectSpecification.AddSelect(x => new Select2ItemBase(
                                              x.Id,
                                              x.Name));

            List <Select2ItemBase> availableRoles = _permissionRepository.GetList(selectSpecification);

            Select2Result <Select2ItemBase> select2Result = new Select2Result <Select2ItemBase>(
                results: availableRoles);

            return(Result.Ok(select2Result));
        }
Exemplo n.º 5
0
        public Task <Result <Select2Result <Select2Item> > > GetObjectIdentifiers(Select2Request select2Request, string objectType)
        {
            ValidationResult validationResult = _select2RequestValidator.Validate(select2Request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {typeof(Select2Request).Name} model");
                return(Task.FromResult(Result.Fail <Select2Result <Select2Item> >(validationResult.ToResultError())));
            }


            if (string.IsNullOrEmpty(objectType))
            {
                return(Task.FromResult(Result.Fail <Select2Result <Select2Item> >("invalid_model", "Invalid Model")));
            }

            var specificationBuilder = SpecificationBuilder
                                       .Create <AuditEntity>()
                                       .WithObjectType(objectType)
                                       .SearchByObjectIdentifier(select2Request.Term)
                                       .Select(x => x.ObjectIdentifier)
                                       .Distinct()
                                       .OrderByAssending(x => x);

            return(GetPaginatedSelect2Result(specificationBuilder, select2Request));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> GetSubjectIdentifiers(
            [FromRoute] string groupId,
            [FromQuery] Select2Request select2Request,
            [FromQuery] SubjectTypes?subjectType)
        {
            Result <Select2Result <Select2Item> > result = await _groupAdminAuditDataService.GetSubjectIdentifiers(
                groupId,
                select2Request,
                subjectType);

            return(result.ToApiResult());
        }
Exemplo n.º 7
0
        public JsonResult GetTransferMoneyToCompanies(Select2Request request, int countryID)
        {
            string query = (request.Query ?? "").Trim().ToLower();

            var companies = companyRepository.Where(company => company.Entity.Name.ToLower().Contains(query))
                            .OrderBy(company => company.Entity.Name)
                            .Select(company => new Select2Item()
            {
                id   = company.ID,
                text = company.Entity.Name
            });

            return(Select2Response(companies, request));
        }
Exemplo n.º 8
0
        public JsonResult GetCitizens(Select2Request request)
        {
            string query = request.Query.Trim().ToLower();

            var citizens = citizenRepository
                           .Where(citizen => citizen.Entity.Name.ToLower().Contains(query))
                           .OrderBy(citizen => citizen.Entity.Name)
                           .Select(citizen => new Select2Item()
            {
                id   = citizen.ID,
                text = citizen.Entity.Name
            });

            return(Select2Response(citizens, request));
        }
Exemplo n.º 9
0
        public JsonResult GetEntitiesToTrade(Select2Request request)
        {
            string search = request.Query.Trim().ToLower();

            var query = entityRepository
                        .Where(entity => entity.Name.ToLower().Contains(search))
                        .OrderBy(entity => entity.Name)
                        .Select(entity => new Select2Item()
            {
                id   = entity.EntityID,
                text = entity.Name
            });

            return(Select2Response(query, request));
        }
Exemplo n.º 10
0
        public IActionResult GetRoles([FromQuery] Select2Request select2Request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            Result <Select2Result <Select2ItemBase> > result = _inviteDataService.GetGlobalRoles(select2Request);

            if (result.Failure)
            {
                ModelState.AddErrors(result);
                return(BadRequest(ModelState));
            }

            return(Ok(result.Value));
        }
Exemplo n.º 11
0
        public IActionResult GetAvailable([FromQuery] Select2Request select2Request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Result <Select2Result <Select2ItemBase> > result = _groupUserDataService.GetAvailable(select2Request);

            if (result.Failure)
            {
                ModelState.AddErrors(result.Errors);
                return(BadRequest(ModelState));
            }

            return(Ok(result.Value));
        }
Exemplo n.º 12
0
        public JsonResult GetEligibleRecipients(Select2Request request)
        {
            var currentEntityID = SessionHelper.CurrentEntity.EntityID;

            var query = request.Query?.Trim();

            var entities = entityRepository.Where(entity => entity.EntityID != currentEntityID)
                           .Where(entity => entity.Name.ToLower().Contains(query))
                           .OrderBy(entity => entity.Name)
                           .Select(entity => new Select2Item()
            {
                id   = entity.EntityID,
                text = entity.Name
            });

            return(Response(entities, request));
        }
Exemplo n.º 13
0
        public IActionResult GetUnassigned([FromRoute] string roleId, [FromQuery] Select2Request select2Request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Result <Select2Result <Select2ItemBase> > result = _roleAssignmentDataService.GetUnassigned(roleId, select2Request);

            if (result.Failure)
            {
                ModelState.AddErrors(result.Errors);
                return(BadRequest(ModelState));
            }

            return(Ok(result.Value));
        }
Exemplo n.º 14
0
        public IActionResult GetAvailable([FromRoute] string roleId, [FromQuery] Select2Request select2Request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Result <Select2Result <Select2ItemBase> > result = _groupRolePermissionsDataService.GetAvailable(roleId, select2Request);

            if (result.Failure)
            {
                ModelState.AddErrors(result);
                return(BadRequest(ModelState));
            }

            return(Ok(result.Value));
        }
Exemplo n.º 15
0
        public Task <Result <Select2Result <Select2Item> > > GetResourceNames(Select2Request select2Request)
        {
            ValidationResult validationResult = _select2RequestValidator.Validate(select2Request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {typeof(Select2Request).Name} model");
                return(Task.FromResult(Result.Fail <Select2Result <Select2Item> >(validationResult.ToResultError())));
            }

            var specificationBuilder = SpecificationBuilder
                                       .Create <AuditEntity>()
                                       .SearchByResourceName(select2Request.Term)
                                       .Select(x => x.ResourceName)
                                       .Distinct()
                                       .OrderByAssending(x => x);

            return(GetPaginatedSelect2Result(specificationBuilder, select2Request));
        }
Exemplo n.º 16
0
        public JsonResult GetEligibleEntitiesForOwnershipChange(Select2Request request)
        {
            string search = request.Query.Trim().ToLower();
            var    eligibleEntityTypesIDs = newspaperService.GetEligibleEntityTypeForOwnership()
                                            .Select(c => (int)c);


            var query = entityRepository
                        .Where(entity => entity.Name.ToLower().Contains(search) &&
                               eligibleEntityTypesIDs.Contains(entity.EntityTypeID))
                        .OrderBy(entity => entity.Name)
                        .Select(entity => new Select2Item()
            {
                id   = entity.EntityID,
                text = entity.Name
            });

            return(Select2Response(query, request));
        }
Exemplo n.º 17
0
        public JsonResult GetHotels(Select2Request request, int?regionID)
        {
            string search = request.Query.Trim().ToLower();

            var query = hotelRepository
                        .Where(h => h.Entity.Name.ToLower().Contains(search));

            if (regionID.HasValue)
            {
                query = query.Where(h => h.RegionID == regionID);
            }

            var retQuery = query.OrderBy(h => h.Entity.Name)
                           .Select(h => new Select2Item()
            {
                id   = h.ID,
                text = h.Entity.Name
            });

            return(Select2Response(retQuery, request));
        }
        private async Task <Result <Select2Result <Select2Item> > > GetPaginatedSelect2Result <TResult>(
            ISelectSpecificationBuilder <AuditEntity, TResult> specificationBuilder,
            Select2Request select2Request)
        {
            int count = await _auditDAO.Count(specificationBuilder.Build());

            var selectSpecification = specificationBuilder
                                      .Paginate(select2Request.GetPageStart(), select2Request.GetPageLenght())
                                      .Build();

            List <TResult> objectTypes = await _auditDAO.Get(selectSpecification);

            Select2Result <Select2Item> select2Result = new Select2Result <Select2Item>(
                objectTypes
                .Select(x => new Select2Item(
                            id: x?.ToString(),
                            text: x?.ToString()))
                .ToList(),
                pagination: select2Request.IsMore(count));

            return(Result.Ok(select2Result));
        }
Exemplo n.º 19
0
        public JsonResult GetMPPAvailableCountries(Select2Request request, int countryID)
        {
            string search = request.Query.Trim().ToLower();

            var query = countryRepository
                        .Where(country =>
                               country.ID != countryID &&
                               country.MPPOffersFirstCountry.Any(o => o.SecondCountryID == countryID) == false &&
                               country.MPPOffersSecondCountry.Any(o => o.FirstCountryID == countryID) == false &&
                               country.MPPsFirstCountry.Any(mpp => mpp.FirstCountryID == countryID && mpp.Active) == false &&
                               country.MPPsSecondCountry.Any(mpp => mpp.SecondCountryID == countryID && mpp.Active) == false &&
                               country.Entity.Name.ToLower().Contains(search) &&
                               country.AttackerWars.Any(w => w.DefenderCountryID == countryID && w.Active) == false &&
                               country.DefenderWars.Any(w => w.AttackerCountryID == countryID && w.Active) == false)
                        .OrderBy(c => c.Entity.Name)
                        .Select(c => new Select2Item()
            {
                id   = c.ID,
                text = c.Entity.Name
            });

            return(Select2Response(query, request));
        }
Exemplo n.º 20
0
        public async Task <IActionResult> GetSubjectIdentifiers([FromQuery] Select2Request select2Request, [FromQuery] SubjectTypes?subjectType)
        {
            Result <Select2Result <Select2Item> > result = await _auditDataService.GetSubjectIdentifiers(select2Request, subjectType);

            return(result.ToApiResult());
        }
Exemplo n.º 21
0
        public async Task <IActionResult> GetResourceNames([FromQuery] Select2Request select2Request)
        {
            Result <Select2Result <Select2Item> > result = await _auditDataService.GetResourceNames(select2Request);

            return(result.ToApiResult());
        }
Exemplo n.º 22
0
        public async Task <Result <Select2Result <Select2ItemBase> > > GetAvailableUsers(Select2Request select2Request)
        {
            ValidationResult validationResult = _select2Validator.Validate(select2Request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(Select2Request)} model");
                return(Result.Fail <Select2Result <Select2ItemBase> >(validationResult.ToResultError()));
            }

            IBaseSpecification <AppUserEntity, Select2ItemBase> specification = SpecificationBuilder
                                                                                .Create <AppUserEntity>()
                                                                                .Where(x => x.Groups.Count == 0)
                                                                                .SearchByUsername(select2Request.Term)
                                                                                .Select(x => new Select2ItemBase(
                                                                                            x.Id,
                                                                                            x.UserName))
                                                                                .Build();

            List <Select2ItemBase> users = await _appUserDAO.Get(specification);

            Select2Result <Select2ItemBase> select2Result = new Select2Result <Select2ItemBase>(
                results: users);

            return(Result.Ok(select2Result));
        }
Exemplo n.º 23
0
        public async Task <IActionResult> GetAvailable([FromRoute] string groupId, [FromQuery] Select2Request select2Request)
        {
            Result <Select2Result <Select2ItemBase> > result = await _groupUserDataService.GetAvailableUsers(select2Request);

            return(result.ToApiResult());
        }
        public Task <Result <Select2Result <Select2Item> > > GetSubjectIdentifiers(string groupId, Select2Request select2Request, SubjectTypes?subjectType)
        {
            ValidationResult validationResult = _select2RequestValidator.Validate(select2Request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {typeof(Select2Request).Name} model");
                return(Task.FromResult(Result.Fail <Select2Result <Select2Item> >(validationResult.ToResultError())));
            }

            var specificationBuilder = SpecificationBuilder
                                       .Create <AuditEntity>()
                                       .WithSubjectType(subjectType)
                                       .SearchBySubjectIdentifier(select2Request.Term)
                                       .WithGroupIdentifier(groupId)
                                       .Select(x => x.SubjectIdentifier)
                                       .Distinct()
                                       .OrderByAssending(x => x);

            return(GetPaginatedSelect2Result(specificationBuilder, select2Request));
        }
        public Result <Select2Result <Select2ItemBase> > GetUnassigned(string roleId, Select2Request select2Request)
        {
            ValidationResult validationResult = _select2Validator.Validate(select2Request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid Select2Request model");
                return(Result.Fail <Select2Result <Select2ItemBase> >(validationResult.Errors));
            }

            SelectSpecification <RoleEntity, Select2ItemBase> selectSpecification =
                new SelectSpecification <RoleEntity, Select2ItemBase>();

            selectSpecification.AddFilter(x => x.Id != roleId);
            selectSpecification.AddFilter(x => x.Type == Core.Data.Enums.Entity.RoleTypes.Group);
            selectSpecification.AddFilter(x => !x.CanBeAssignedBy.Select(c => c.RoleId).Contains(roleId)); //TODO: check this
            selectSpecification.AddSelect(x => new Select2ItemBase(
                                              x.Id,
                                              x.Name));

            List <Select2ItemBase> unassignedRoles = _roleRepository.GetList(selectSpecification);

            Select2Result <Select2ItemBase> select2Result = new Select2Result <Select2ItemBase>(
                unassignedRoles, false);

            return(Result.Ok(select2Result));
        }
Exemplo n.º 26
0
        public async Task <IActionResult> GetResourceNames([FromRoute] string groupId, [FromQuery] Select2Request select2Request)
        {
            Result <Select2Result <Select2Item> > result = await _groupAdminAuditDataService.GetResourceNames(
                groupId,
                select2Request);

            return(result.ToApiResult());
        }