예제 #1
0
        public AdminUser Login(string username, string password)
        {
            AdminUser model = new AdminUser();
            ISpecification <AdminUser> spec = SpecificationBuilder.Create <AdminUser>();

            spec.Equals(m => m.Password, ITOrm.Utility.Encryption.SecurityHelper.GetMD5String(password));
            spec.Equals(m => m.UserName, username);
            model = AdminUser.Single(spec);
            return(model);
        }
예제 #2
0
        public Task <Result <GroupUserEntity> > SingleOrDefault(long id)
        {
            IBaseSpecification <GroupUserEntity, GroupUserEntity> specification = SpecificationBuilder
                                                                                  .Create <GroupUserEntity>()
                                                                                  .Where(x => x.Id == id)
                                                                                  .Select()
                                                                                  .Build();

            return(SingleOrDefault(specification));
        }
        public async Task Should_find_a_person_by_the_name(string name)
        {
            var peopleRepository = new ReadPeopleRepository(_mockDbContext.DbContext);
            var specification    = SpecificationBuilder <Person> .Create()
                                   .WithName(name);

            var result = await peopleRepository.SearchAsync(specification, CancellationToken.None);

            result.Should().HaveCount(1);
        }
예제 #4
0
        public Task <Result <GroupEntity> > SingleOrDefault(string id)
        {
            IBaseSpecification <GroupEntity, GroupEntity> specification = SpecificationBuilder
                                                                          .Create <GroupEntity>()
                                                                          .WithId(id)
                                                                          .Select()
                                                                          .Build();

            return(SingleOrDefault(specification));
        }
예제 #5
0
        public Task <Result <GroupUserEntity> > SingleOrDefault(string userId, string groupId)
        {
            IBaseSpecification <GroupUserEntity, GroupUserEntity> specification = SpecificationBuilder
                                                                                  .Create <GroupUserEntity>()
                                                                                  .Where(x => x.UserId == userId)
                                                                                  .Where(x => x.GroupId == groupId)
                                                                                  .Select()
                                                                                  .Build();

            return(SingleOrDefault(specification));
        }
예제 #6
0
파일: ModulesBll.cs 프로젝트: chenmsg/sujin
        /// <summary>
        /// 后台根据请求控制器与action查询模块实体
        /// </summary>
        /// <param name="controllers"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static Modules Single(string controllers, string action)
        {
            Modules model = new Modules();
            ISpecification <Modules> spec = SpecificationBuilder.Create <Modules>();
            string path = "/" + controllers + "/" + action;

            spec.Equals(m => m.LinkPath, path);
            //spec.Equals(m => m.UserName, username);
            model = Modules.Single(spec);
            return(model);
        }
예제 #7
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));
        }
예제 #8
0
        public async Task Should_find_all_people_by_the_list_name(string name, int expectedListSize)
        {
            var peopleRepository = new ReadSocialListsRepository(_mockDbContext.DbContext);
            var specification    = SpecificationBuilder <SocialList> .Create()
                                   .WithName(name);

            var result = await peopleRepository.Where(specification, x => x.SocialListPerson, y => y.Person)
                         .ToListAsync(CancellationToken.None);

            result.Should().HaveCount(1);
            result.First().SocialListPerson.Count.Should().Be(expectedListSize);
        }
예제 #9
0
        public async Task <Menu> SingleAsync(string areaName, string controllerName, string actionName)
        {
            var query = SpecificationBuilder.Create <Menu>();

            if (!string.IsNullOrEmpty(areaName))
            {
                query.Equals(a => a.AreaName.ToUpper(), areaName.ToUpper());
            }
            query.Equals(a => a.ActionName.ToUpper(), actionName.ToUpper());
            query.Equals(a => a.ControllerName.ToUpper(), controllerName.ToUpper());
            return(await SingleAsync(query));
        }
        public async Task AlterarAsync(string codigoIcao, string nome, string descricao, CancellationToken cancellationToken)
        {
            var spec = SpecificationBuilder <Aeroporto> .Create()
                       .ComCodigoIcao(codigoIcao)
                       .Ativo();

            var aeroporto = await _aeroportoRepository.FirstOrDefaultAsync(spec, cancellationToken);

            aeroporto.Alterar(nome, descricao);

            _aeroportoRepository.Update(aeroporto);
        }
예제 #11
0
        // GET: AspNetUsers
        public ActionResult Index(int pageIndex = 1, string keyword = "")
        {
            var spec = SpecificationBuilder.Create <Manager>();

            if (keyword != "")
            {
                spec.Like(a => a.FullName, keyword);
            }
            var pagelist = _managerService.GetPaged(spec.Predicate, a => a.AddDate, pageIndex, 20);
            var models   = pagelist.Select(a => { return(a.ToModel()); }).ToPagedList(pageIndex, 20, pagelist.TotalCount);

            return(View(models));
        }
예제 #12
0
        public async Task <IActionResult> Index(string queryString, Guid?ParentID = null, int page = 1)
        {
            var query = SpecificationBuilder.Create <User>();

            if (!string.IsNullOrEmpty(queryString))
            {
                query.StartWith(a => a.Name, queryString);
                query.Predicate.Or(a => a.LoginName.StartsWith(queryString));
            }
            var entityList = await _userService.GetPagedAsync(page, _setting.PageSize, a => a.CreateDate, query, true);

            return(PartialView("AjaxTable", entityList));
        }
        public ActionResult Index(int pageIndex = 1, string keyword = "")
        {
            var spec = SpecificationBuilder.Create <NewsArticle>();

            if (keyword != "")
            {
                spec.Like(a => a.Title, keyword);
            }
            var pagelist = _newsArticlesRepository.GetPaged(spec.Predicate, a => a.CreateDate, pageIndex, 20);
            var models   = pagelist.Select(a => { return(a.ToModel()); }).ToPagedList(pageIndex, 20, pagelist.TotalCount);

            return(View(models));
        }
예제 #14
0
        // GET: Nav
        public ActionResult Index(int pageIndex = 1, string keyword = "")
        {
            var spec = SpecificationBuilder.Create <Nav>();

            spec.Equals(a => a.State, 1);
            if (keyword != "")
            {
                spec.Like(a => a.NavName, keyword);
            }
            var pagelist = _navService.GetPaged(spec.Predicate, a => a.NavId, pageIndex, 20);
            var models   = pagelist.Select(a => { return(a.ToModel()); }).ToPagedList(pageIndex, 20, pagelist.TotalCount);

            return(View(models));
        }
예제 #15
0
        // GET: Area
        public ActionResult Index(AreaSearchModel model, int pageIndex = 1, string keyword = "")
        {
            var forms = HttpContext.Request.QueryString.AllKeys;
            var spec  = SpecificationBuilder.Create <Area>();

            model.Expression(spec);
            var pagedList = _areaService.GetPaged(spec.Predicate, a => a.AreaId, pageIndex, 20);
            var models    = pagedList.Select(x =>
            {
                var m = x.ToModel();
                return(m);
            }).ToPagedList(pageIndex, 20, pagedList.TotalCount);

            return(View(models));
        }
예제 #16
0
        public virtual async Task <Result> ValidateGroup(string groupId)
        {
            IBaseSpecification <GroupEntity, GroupEntity> specification = SpecificationBuilder
                                                                          .Create <GroupEntity>()
                                                                          .WithId(groupId)
                                                                          .Build();

            bool exists = await _groupDAO.Exist(specification);

            if (!exists)
            {
                _logger.LogError($"No group. GroupId {groupId}");
                return(Result.Fail(GROUP_NOT_FOUND));
            }

            return(Result.Ok());
        }
예제 #17
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));
        }
예제 #18
0
        public async Task <Result> Start(long groupUserId)
        {
            var specification = SpecificationBuilder
                                .Create <GroupUserEntity>()
                                .Where(x => x.Id == groupUserId)
                                .Include(x => x.User)
                                .Build();

            Result <GroupUserEntity> getGroupUserResult = await _groupUserStore.SingleOrDefault(specification);

            if (getGroupUserResult.Failure)
            {
                return(Result.Fail(getGroupUserResult));
            }

            return(await Start(getGroupUserResult.Value.User));
        }
예제 #19
0
        public async Task <IActionResult> Index(string queryString, int queryLogLevel, int page = 1)
        {
            var query = SpecificationBuilder.Create <PermissionSystemLogs>();

            if (!string.IsNullOrEmpty(queryString))
            {
                query.StartWith(a => a.KeyWord, queryString);
                query.Predicate.Or(a => a.ShortMessage.StartsWith(queryString));
            }
            if (queryLogLevel != -1)
            {
                query.Equals(a => a.LogLeve, queryLogLevel);
            }
            var model = await _logService.GetPagedAsync(page, _setting.PageSize, a => a.CreateDate, query, true);

            return(PartialView("AjaxTable", model));
        }
예제 #20
0
        private async Task <Result> UserAlreadyExist(string email)
        {
            IBaseSpecification <AppUserEntity, AppUserEntity> specification = SpecificationBuilder
                                                                              .Create <AppUserEntity>()
                                                                              .Where(x => x.NormalizedEmail == email.ToUpper())
                                                                              .Build();

            bool userExist = await _userDAO.Exist(specification);

            if (userExist)
            {
                _logger.LogError($"User with the same email already exists");
                //return Result.Fail(USER_WITH_SAME_EMAIL_ALREADY_EXIST); //TODO: dont expose all users to everybody
                return(Result.Fail(FAILED_TO_ADD_INVITE));
            }

            return(Result.Ok());
        }
예제 #21
0
        public async Task <Result> Remove(string groupId, string inviteId)
        {
            IBaseSpecification <InviteEntity, InviteEntity> specification = SpecificationBuilder
                                                                            .Create <InviteEntity>()
                                                                            .Where(x => x.Id == inviteId)
                                                                            .Where(x => x.GroupId == groupId)
                                                                            .Build();

            InviteEntity invite = await _inviteDAO.SingleOrDefault(specification);

            if (invite == null)
            {
                _logger.LogError($"Invite not found. InviteId {inviteId}, GroupId {groupId}");
                return(Result.Fail(INVITE_NOT_FOUND));
            }

            return(await Remove(invite));
        }
예제 #22
0
        private async Task <Result> GlobalRoleExists(string globalRoleId)
        {
            IBaseSpecification <RoleEntity, RoleEntity> specification = SpecificationBuilder
                                                                        .Create <RoleEntity>()
                                                                        .Where(x => x.Id == globalRoleId)
                                                                        .Where(x => x.Type == Data.Enums.Entity.RoleTypes.Global)
                                                                        .Build();

            bool globalRoleExists = await _roleDAO.Exist(specification);

            if (!globalRoleExists)
            {
                _logger.LogError($"No GlobalRole. RoleId {globalRoleId}");
                return(Result.Fail(GLOBAL_ROLE_NOT_FOUND));
            }

            return(Result.Ok());
        }
예제 #23
0
        public Core.Models.Result.Result Remove(string id)
        {
            _logger.LogInformation($"Removing Invite. InviteId {id}");

            IBaseSpecification <InviteEntity, InviteEntity> specification = SpecificationBuilder
                                                                            .Create <InviteEntity>()
                                                                            .Where(x => x.Id == id)
                                                                            .Build();

            InviteEntity invite = _inviteDAO.SingleOrDefault(specification).Result;

            if (invite == null)
            {
                _logger.LogError($"No Invite. InviteId {id}");
                return(Result.Fail(INVITE_NOT_FOUND).ToOldResult());
            }

            return(Remove(invite).Result.ToOldResult());
        }
예제 #24
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));
        }
예제 #25
0
        public async Task <CommonUtils.Result.Result> EditUser(long groupUserId, EditUserRequest editUserRequest)
        {
            IBaseSpecification <GroupUserEntity, GroupUserEntity> specification = SpecificationBuilder
                                                                                  .Create <GroupUserEntity>()
                                                                                  .Where(x => x.Id == groupUserId)
                                                                                  .Include(x => x.User)
                                                                                  .Build();

            CommonUtils.Result.Result <GroupUserEntity> getGroupUserResult = await _groupUserStore.SingleOrDefault(specification);

            if (getGroupUserResult.Failure)
            {
                return(CommonUtils.Result.Result.Fail(getGroupUserResult));
            }

            //TODO: change so that Edit takes AppUserEntity as parameter
            Core.Models.Result.Result updateResult = await EditUser(getGroupUserResult.Value.UserId, editUserRequest, "");

            return(updateResult.ToNewResult());
        }
예제 #26
0
        public async Task <Result <IdStringModel> > AddAsync(AddGroupRequest addGroup)
        {
            ValidationResult validationResult = _addGroupValidator.Validate(addGroup);

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

            addGroup.Name = addGroup.Name.Trim();

            IBaseSpecification <GroupEntity, GroupEntity> groupExistSpecification = SpecificationBuilder
                                                                                    .Create <GroupEntity>()
                                                                                    .WithName(addGroup.Name)
                                                                                    .Build();

            bool groupExist = await _groupDAO.Exist(groupExistSpecification);

            if (groupExist)
            {
                _logger.LogError($"Group with the same name already exist. GroupName {addGroup.Name}");
                return(Result.Fail <IdStringModel>(GROUP_WITH_NAME_ALREADY_EXIST));
            }

            GroupEntity group = new GroupEntity(
                name: addGroup.Name);

            bool addResult = await _groupDAO.Add(group);

            if (!addResult)
            {
                _logger.LogError($"Failed to add group");
                return(Result.Fail <IdStringModel>(FAILED_TO_ADD_GROUP));
            }

            IdStringModel idStringModel = new IdStringModel(
                id: group.Id);

            return(Result.Ok(idStringModel));
        }
        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));
        }
예제 #28
0
        private async Task <Result> InviteAlreadyExits(string email)
        {
            DateTimeOffset now = DateTimeOffset.UtcNow;

            IBaseSpecification <InviteEntity, InviteEntity> specification = SpecificationBuilder
                                                                            .Create <InviteEntity>()
                                                                            .Where(x => x.Email.ToUpper() == email.ToUpper())
                                                                            .Where(x => x.Status == Data.Enums.Entity.InviteStatuses.Pending)
                                                                            .Where(x => x.ExpiresAt > now)
                                                                            .Build();

            bool inviteExists = await _inviteDAO.Exist(specification);

            if (inviteExists)
            {
                _logger.LogError($"Valid invite already exists");
                return(Result.Fail(INVITE_ALREADY_EXISTS));
            }

            return(Result.Ok());
        }
예제 #29
0
        public async Task <CommonUtils.Result.Result> SendEmilVerificationMail(long groupUserId)
        {
            IBaseSpecification <GroupUserEntity, GroupUserEntity> specification = SpecificationBuilder
                                                                                  .Create <GroupUserEntity>()
                                                                                  .Where(x => x.Id == groupUserId)
                                                                                  .Include(x => x.User)
                                                                                  .Build();

            CommonUtils.Result.Result <GroupUserEntity> getGroupUserResult = await _groupUserStore.SingleOrDefault(specification);

            if (getGroupUserResult.Failure)
            {
                return(CommonUtils.Result.Result.Fail(getGroupUserResult));
            }

            SendEmailVerificationMailRequest sendEmailVerificationMailRequest = new SendEmailVerificationMailRequest(
                userId: getGroupUserResult.Value.UserId);

            Core.Models.Result.Result result = await SendEmilVerificationMail(sendEmailVerificationMailRequest, "");

            return(result.ToNewResult());
        }
예제 #30
0
        public async Task <CommonUtils.Result.Result> UserExists(BaseRegisterRequest baseRegisterRequest)
        {
            string username = baseRegisterRequest.Username;

            if (_identityUIEndpoints.UseEmailAsUsername)
            {
                username = baseRegisterRequest.Email;
            }

            IBaseSpecification <AppUserEntity, AppUserEntity> specification = SpecificationBuilder
                                                                              .Create <AppUserEntity>()
                                                                              .WithUsername(username)
                                                                              .Build();

            bool userExists = await _userDAO.Exist(specification);

            if (!userExists)
            {
                return(CommonUtils.Result.Result.Fail(USER_NOT_FOUND));
            }

            return(CommonUtils.Result.Result.Ok());
        }