Example #1
0
        public async Task <Result <DataTableResult <AuditAdminTableModel> > > Get(DataTableRequest dataTableRequest, AuditTableRequest auditTableRequest)
        {
            ValidationResult dataTableValidationResult = _dataTableRequestValidator.Validate(dataTableRequest);

            if (!dataTableValidationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(DataTableRequest)} model");
                return(Result.Fail <DataTableResult <AuditAdminTableModel> >(dataTableValidationResult.ToResultError()));
            }

            if (auditTableRequest == null)
            {
                _logger.LogWarning($"AuditTable request can not be null");
                return(Result.Fail <DataTableResult <AuditAdminTableModel> >("can_not_be_null", "Can not be null"));
            }

            ValidationResult auditTableRequestValidationResult = _auditTableRequestValidator.Validate(auditTableRequest);

            if (!auditTableRequestValidationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(AuditTableRequest)} model");
                return(Result.Fail <DataTableResult <AuditAdminTableModel> >(auditTableRequestValidationResult.ToResultError()));
            }

            IBaseSpecificationBuilder <AuditEntity> baseSpecification = SpecificationBuilder
                                                                        .Create <AuditEntity>()
                                                                        .WithActionType(auditTableRequest.ActionType)
                                                                        .WithObjectType(auditTableRequest.ObjectType)
                                                                        .WithObjectIdentifier(auditTableRequest.ObjectIdentifier)
                                                                        .WithSubjectType(auditTableRequest.SubjectType)
                                                                        .WithSubjectIdentifier(auditTableRequest.SubjectIdentifier)
                                                                        .WithResourceName(auditTableRequest.ResourceName)
                                                                        .InRange(auditTableRequest.From, auditTableRequest.To);

            IBaseSpecification <AuditEntity, AuditAdminTableModel> selectSpecification = baseSpecification
                                                                                         .OrderBy(x => x.Created, auditTableRequest.OrderBy.Value)
                                                                                         .Paginate(dataTableRequest.Start, dataTableRequest.Length)
                                                                                         .Select(x => new AuditAdminTableModel(
                                                                                                     x.Id,
                                                                                                     x.ActionType.GetDescription(),
                                                                                                     x.ObjectType,
                                                                                                     x.ResourceName,
                                                                                                     x.SubjectType.GetDescription(),
                                                                                                     x.SubjectIdentifier,
                                                                                                     x.Created.ToString("o")))
                                                                                         .Build();

            int auditCount = await _auditDAO.Count(baseSpecification.Build());

            List <AuditAdminTableModel> audits = await _auditDAO.Get(selectSpecification);

            DataTableResult <AuditAdminTableModel> dataTableResult = new DataTableResult <AuditAdminTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: auditCount,
                recordsFiltered: auditCount,
                error: null,
                data: audits);

            return(Result.Ok(dataTableResult));
        }
        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));
        }
 public T GetItem(int id)
 {
     if (id <= 0)
     {
         return(default(T));
     }
     return(_db.Get(id));
 }
Example #4
0
        public async Task <Result <List <TimeRangeStatisticsModel> > > GetActivityStatistics(string groupId, TimeRangeRequest timeRangeRequest)
        {
            ValidationResult validationResult = _timeRangeRequestValidator.Validate(timeRangeRequest);

            if (!validationResult.IsValid)
            {
                _logger.LogError($"Invalid {typeof(TimeRangeRequest).Name} model");
                return(Result.Fail <List <TimeRangeStatisticsModel> >(validationResult.ToResultError()));
            }

            IBaseSpecification <AuditEntity, DateTime> specification = SpecificationBuilder
                                                                       .Create <AuditEntity>()
                                                                       .Where(x => x.Created >= timeRangeRequest.From.UtcDateTime)
                                                                       .Where(x => x.Created < timeRangeRequest.To.UtcDateTime)
                                                                       .WithGroupIdentifier(groupId)
                                                                       .Select(x => x.Created)
                                                                       .Build();

            List <DateTime> dateTimes = await _auditDAO.Get(specification);

            List <TimeRangeStatisticsModel> viewModel = dateTimes
                                                        .GroupBy(x => new { x.Year, x.Month, x.Day })
                                                        .Select(x => new TimeRangeStatisticsModel(
                                                                    dateTime: new DateTime(x.Key.Year, x.Key.Month, x.Key.Day, 0, 0, 0, DateTimeKind.Utc),
                                                                    value: x.Count()))
                                                        .ToList();

            DateTime dateTime = new DateTime(
                timeRangeRequest.From.UtcDateTime.Year,
                timeRangeRequest.From.UtcDateTime.Month,
                timeRangeRequest.From.UtcDateTime.Day,
                0,
                0,
                0,
                DateTimeKind.Utc);

            for (; dateTime < timeRangeRequest.To; dateTime = dateTime.AddDays(1))
            {
                bool exists = viewModel
                              .Where(x => x.DateTime == dateTime)
                              .Any();

                if (!exists)
                {
                    viewModel.Add(new TimeRangeStatisticsModel(
                                      dateTime: dateTime,
                                      value: 0));
                }
            }

            viewModel = viewModel
                        .OrderBy(x => x.DateTime)
                        .ToList();

            return(Result.Ok(viewModel));
        }
Example #5
0
        private Task <List <RoleListData> > GetAllGroupRolesAsync()
        {
            IBaseSpecification <RoleEntity, RoleListData> specification = SpecificationBuilder
                                                                          .Create <RoleEntity>()
                                                                          .Where(x => x.Type == Data.Enums.Entity.RoleTypes.Group)
                                                                          .Select(x => new RoleListData(
                                                                                      x.Id,
                                                                                      x.Name))
                                                                          .Build();

            return(_roleDAO.Get(specification));
        }
        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));
        }
Example #7
0
        public async Task <Result <DataTableResult <AuditTableModel> > > Get(DataTableRequest dataTableRequest, AuditTableRequest auditTableRequest)
        {
            ValidationResult validationResult = _dataTableRequestValidator.Validate(dataTableRequest);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(DataTableRequest)} model");
                return(Result.Fail <DataTableResult <AuditTableModel> >(validationResult.ToResultError()));
            }

            ValidationResult auditTabeValidationResult = _auditTableRequestValidator.Validate(auditTableRequest);

            if (!auditTabeValidationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {typeof(AuditTableRequest).Name} model");
                return(Result.Fail <DataTableResult <AuditTableModel> >(validationResult.ToResultError()));
            }

            IBaseSpecificationBuilder <AuditEntity> baseSpecification = SpecificationBuilder
                                                                        .Create <AuditEntity>()
                                                                        .WithActionType(auditTableRequest.ActionType)
                                                                        .InRange(auditTableRequest.From?.UtcDateTime, auditTableRequest.To?.UtcDateTime)
                                                                        .WithUser(_httpContextAccessor.HttpContext.User.GetUserId());

            IBaseSpecification <AuditEntity, AuditTableModel> selectSpecification = baseSpecification
                                                                                    .OrderBy(x => x.Created, auditTableRequest.OrderBy.Value)
                                                                                    .Paginate(dataTableRequest.Start, dataTableRequest.Length)
                                                                                    .Select(x => new AuditTableModel(
                                                                                                x.Id,
                                                                                                x.ActionType.GetDescription(),
                                                                                                x.ResourceName,
                                                                                                x.Created.ToString("o")))
                                                                                    .Build();

            int auditsCount = await _auditDAO.Count(baseSpecification.Build());

            List <AuditTableModel> audits = await _auditDAO.Get(selectSpecification);

            DataTableResult <AuditTableModel> dataTableResult = new DataTableResult <AuditTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: auditsCount,
                recordsFiltered: auditsCount,
                data: audits);

            return(Result.Ok(dataTableResult));
        }
        public async Task <Result <DataTableResult <GroupUserTableModel> > > Get(string groupId, DataTableRequest request)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid DataTableRequest model");
                return(Result.Fail <DataTableResult <GroupUserTableModel> >(validationResult.ToResultError()));
            }

            ISelectSpecificationBuilder <GroupUserEntity, GroupUserTableModel> specificationBuilder = SpecificationBuilder
                                                                                                      .Create <GroupUserEntity>()
                                                                                                      .Where(x => x.GroupId == groupId)
                                                                                                      .SearchByUsernameEmailId(request.Search)
                                                                                                      .OrderByDessending(x => x._CreatedDate)
                                                                                                      .Select(x => new GroupUserTableModel(
                                                                                                                  x.Id,
                                                                                                                  x.UserId,
                                                                                                                  x.User.UserName,
                                                                                                                  x.User.Email,
                                                                                                                  x.RoleId,
                                                                                                                  x.Role.Name));

            IBaseSpecification <GroupUserEntity, GroupUserTableModel> countSpecification = specificationBuilder.Build();
            IBaseSpecification <GroupUserEntity, GroupUserTableModel> dataSpecification  = specificationBuilder
                                                                                           .Paginate(request.Start, request.Length)
                                                                                           .Build();

            int count = await _groupUserDAO.Count(countSpecification);

            List <GroupUserTableModel> groupUsers = await _groupUserDAO.Get(dataSpecification);

            DataTableResult <GroupUserTableModel> dataTableResult = new DataTableResult <GroupUserTableModel>(
                draw: request.Draw,
                recordsTotal: count,
                recordsFiltered: count,
                data: groupUsers);

            return(Result.Ok(dataTableResult));
        }
        public async Task <Result <DataTableResult <GroupInviteTableModel> > > Get(string groupId, DataTableRequest dataTableRequest)
        {
            ValidationResult validationResult = _dataTableRequestValidator.Validate(dataTableRequest);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(DataTableRequest)} model");
                return(Result.Fail <DataTableResult <GroupInviteTableModel> >(validationResult.ToResultError()));
            }

            ISelectSpecificationBuilder <InviteEntity, GroupInviteTableModel> specificationBuilder = SpecificationBuilder
                                                                                                     .Create <InviteEntity>()
                                                                                                     .Where(x => x.GroupId == groupId)
                                                                                                     .SearchByEmail(dataTableRequest.Search)
                                                                                                     .OrderByDessending(x => x._CreatedDate)
                                                                                                     .Select(x => new GroupInviteTableModel(
                                                                                                                 x.Id,
                                                                                                                 x.Email,
                                                                                                                 x.GroupRole.Name,
                                                                                                                 x.Status.GetDescription(),
                                                                                                                 x.ExpiresAt.ToString("o")));

            IBaseSpecification <InviteEntity, GroupInviteTableModel> countSpecification = specificationBuilder.Build();
            IBaseSpecification <InviteEntity, GroupInviteTableModel> dataSpecification  = specificationBuilder
                                                                                          .Paginate(dataTableRequest.Start, dataTableRequest.Length)
                                                                                          .Build();

            int count = await _inviteDAO.Count(countSpecification);

            var data = await _inviteDAO.Get(dataSpecification);


            DataTableResult <GroupInviteTableModel> dataTableResult = new DataTableResult <GroupInviteTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: count,
                recordsFiltered: count,
                data: data);

            return(Result.Ok(dataTableResult));
        }
Example #10
0
        public async Task <Result <DataTableResult <GroupAttributeTableModel> > > Get(string groupId, DataTableRequest dataTableRequest)
        {
            ValidationResult validationResult = _dataTableValidator.Validate(dataTableRequest);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid {nameof(dataTableRequest)} model");
                return(Result.Fail <DataTableResult <GroupAttributeTableModel> >(validationResult.ToResultError()));
            }

            ISelectSpecificationBuilder <GroupAttributeEntity, GroupAttributeTableModel> specificationBuilder = SpecificationBuilder
                                                                                                                .Create <GroupAttributeEntity>()
                                                                                                                .Where(x => x.GroupId == groupId)
                                                                                                                .SearchByKey(dataTableRequest.Search)
                                                                                                                .OrderByDessending(x => x._CreatedDate)
                                                                                                                .Select(x => new GroupAttributeTableModel(
                                                                                                                            x.Id,
                                                                                                                            x.Key,
                                                                                                                            x.Value));

            IBaseSpecification <GroupAttributeEntity, GroupAttributeTableModel> countSpecification = specificationBuilder.Build();
            IBaseSpecification <GroupAttributeEntity, GroupAttributeTableModel> dataSpecification  = specificationBuilder
                                                                                                     .Paginate(dataTableRequest.Start, dataTableRequest.Length)
                                                                                                     .Build();

            int count = await _groupAttributeDAO.Count(countSpecification);

            List <GroupAttributeTableModel> data = await _groupAttributeDAO.Get(countSpecification);

            DataTableResult <GroupAttributeTableModel> dataTableResult = new DataTableResult <GroupAttributeTableModel>(
                draw: dataTableRequest.Draw,
                recordsTotal: count,
                recordsFiltered: count,
                data: data);

            return(Result.Ok(dataTableResult));
        }
Example #11
0
        private async Task <List <RoleListData> > GetRoleAssignments(string userId, string groupId)
        {
            IBaseSpecification <GroupUserEntity, RoleListData> getGroupRoleSpecification = SpecificationBuilder
                                                                                           .Create <GroupUserEntity>()
                                                                                           .Where(x => x.UserId == userId)
                                                                                           .Where(x => x.GroupId == groupId)
                                                                                           .Select(x => new RoleListData(
                                                                                                       x.Role.Id,
                                                                                                       x.Role.Name))
                                                                                           .Build();

            RoleListData role = await _groupUserDAO.SingleOrDefault(getGroupRoleSpecification);

            if (role == null)
            {
                _logger.LogInformation($"User has no groupRole. UserId {userId}, GroupId {groupId}");
                return(new List <RoleListData>());
            }

            IBaseSpecification <RoleAssignmentEntity, RoleListData> getRoleAssigmentsSpecification = SpecificationBuilder
                                                                                                     .Create <RoleAssignmentEntity>()
                                                                                                     .Where(x => x.RoleId == role.Id)
                                                                                                     .Select(x => new RoleListData(
                                                                                                                 x.CanAssigneRole.Id,
                                                                                                                 x.CanAssigneRole.Name))
                                                                                                     .Build();

            List <RoleListData> canAssigneRoles = await _roleAssignmentDAO.Get(getRoleAssigmentsSpecification);

            if (!canAssigneRoles.Any(x => x.Id == role.Id))
            {
                canAssigneRoles.Add(role);
            }

            return(canAssigneRoles);
        }
 public List <RoleDTO> GetRole(int userID)
 {
     return(userDAO.Get(userID).UserRoles.Select(x => new RoleDTO(x.Role)).ToList());
 }
Example #13
0
        public Task <List <TData> > Get <TData>(IBaseSpecification <GroupUserEntity, TData> specification)
        {
            specification = ApplayGroupUserFilter(specification);

            return(_groupUserDAO.Get(specification));
        }