Esempio n. 1
0
        private static void ConfigureSystemPositions(IBaseRepository repository)
        {
            var positionService = new PositionService(repository);
            var systemRoles = EnumExtensions.GetTypedValues<SystemRole>().ToList();
            var positionSearchCriteria = new PositionsSearchCriteria
                                             {
                                                 WithRoles = systemRoles,
                                                 OnlySystemPositions = true
                                             };

            var systemPositions = positionService.FindPositions(positionSearchCriteria);
            foreach (var role1 in systemRoles.Where(role1 => !systemPositions.Any(x => x.SystemRole == role1)))
                positionService.SavePosition(new Position { Name = role1.ToString(), SystemRole = role1, SystemPosition = true });
            SystemEntitiesStore.Positions = positionService.FindPositions(positionSearchCriteria).ToList();
        }
Esempio n. 2
0
        private static void ConfigureSystemAccounts(IBaseRepository repository)
        {
            var imageService = new ImageService(repository);
            var positionService = new PositionService(repository);
            var accountService = new AccountService(repository, imageService, positionService);

            User adminAccount;

            if (accountService.DefaultSystemAccount == null)
            {
                adminAccount = SystemEntitiesStore.SystemUserTemplate;
                adminAccount.ProfilePicture = imageService.DefaultUserProfileImage ?? SystemEntitiesStore.SystemUserProfileImageTemplate;
                adminAccount.ProfilePicture.Owner = adminAccount;
                if (accountService.SaveUser(adminAccount).InvalidValues.Any())
                    throw new Exception("Default system user was not created successfully");
            }

            adminAccount = accountService.GetUserByEmailAddress(SystemEntitiesStore.SystemUserTemplate.Email);
            SystemEntitiesStore.User = adminAccount;
            SystemEntitiesStore.Address = adminAccount.Address;
            if (!adminAccount.Positions.Any(x => x.Position.SystemRole == SystemRole.Admin))
            {

                var adminPositionSearchCriteria = new PositionsSearchCriteria
                                                 {
                                                     WithRoles = new List<SystemRole> { SystemRole.Admin },
                                                     OnlySystemPositions = true
                                                 };

                var adminPosition = positionService.FindPositions(adminPositionSearchCriteria).First();
                positionService.SaveUserPosition(new UserPosition { Position = adminPosition, User = adminAccount });
            }
        }