Пример #1
0
        private static void ConfigureSystemImages(IBaseRepository repository)
        {
            var imageService = new ImageService(repository);
            var accountService = new AccountService(repository, imageService, null);
            var defaultAdmin = accountService.DefaultSystemAccount;

            #region User Profile Image

            var defaultUserProfileImage = imageService.DefaultUserProfileImage;
            if (defaultUserProfileImage == null)
            {
                defaultUserProfileImage = SystemEntitiesStore.SystemUserProfileImageTemplate;
                defaultUserProfileImage.Owner = defaultAdmin;
                defaultUserProfileImage = imageService.SaveImage(defaultUserProfileImage);
                if (defaultUserProfileImage.InvalidValues.Any())
                    throw new Exception("Default user profile image was not created successfully");
            }

            SystemEntitiesStore.ProfileImage = imageService.DefaultUserProfileImage;

            #endregion

            #region Event Flyer Image

            var defaultEventFlyerImage = imageService.DefaultEventFlyerImage;
            if (defaultEventFlyerImage == null)
            {
                defaultEventFlyerImage = SystemEntitiesStore.SystemEventFlyerTemplate;
                defaultEventFlyerImage.Owner = defaultAdmin;
                imageService.SaveImage(defaultEventFlyerImage);
                if (defaultEventFlyerImage.InvalidValues.Any())
                    throw new Exception("Default user profile image was not created successfully");
            }

            SystemEntitiesStore.EventFlyerImage = defaultEventFlyerImage;

            #endregion
        }
Пример #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 });
            }
        }