Exemple #1
0
        public async override Task Execute(SagaContext context)
        {
            var proRole = await repo.FindByName("Pro");

            if (proRole == null)
            {
                await repo.Add(new Role("Pro"));
            }

            var expiredRole = await repo.FindByName("Free");

            if (expiredRole == null)
            {
                await repo.Add(new Role("Free"));
            }
        }
Exemple #2
0
        public async override Task Execute(SagaContext context)
        {
            var adminRole = await roleRepo.FindByName("Admin") ?? throw new EntityNotFoundException("No admin role?");

            var allPermissions = await permissionRepo.FindAll();

            if (adminRole.PermissionIds.Count < allPermissions.Count)
            {
                adminRole.PermissionIds = allPermissions.Select(p => p.Id).ToList();

                await roleRepo.Update(adminRole);
            }
        }
Exemple #3
0
        protected async override Task <SpecificationResult> IsSatisfied(Role entity)
        {
            var existing = await repo.FindByName(entity.Name);

            if (existing == null || existing.Id == entity.Id)
            {
                return(new SpecificationResult(true));
            }
            else
            {
                return(new SpecificationResult(false, $"Role {entity.Name} is already defined."));
            }
        }
Exemple #4
0
        public async override Task Execute(SagaContext context)
        {
            var user = await userRepo.FindByEmail(config.Email);

            if (user != null)
            {
                await userGateway.UpdatePassword(user, config.Password);

                Log.Information("Updated admin password");
            }
            else
            {
                user = await userGateway.CreateUser(config.Email, config.Password);

                await userRepo.Add(user);

                var adminRole = await roleRepo.FindByName("Admin");

                await roleRepo.AddToUser(user, adminRole !);

                Log.Information("Created new admin user");
            }
        }
Exemple #5
0
        public async Task ReplaceRoles(User user, string roleName)
        {
            var role = await roleRepo.FindByName(roleName) ?? throw new EntityNotFoundException();

            await roleRepo.AddToUser(user, role, true);
        }