Ejemplo n.º 1
0
        public async Task InsertAsync(int siteId, string initialAuthorizationCode, int userId = -1)
        {
            //_config[ConfigurationKey.InitialAuthorizationCode]
            // this is the data required for a user to register
            var system = new Model.System
            {
                SiteId = siteId,
                Name   = "Library District"
            };

            system = await _systemRepository.AddSaveAsync(userId, system);

            var branch = new Model.Branch
            {
                SystemId = system.Id,
                Name     = "Main Library",
            };

            branch = await _branchRepository.AddSaveAsync(userId, branch);

            var pointTranslation = new Model.PointTranslation
            {
                ActivityAmount            = 1,
                ActivityDescription       = "minute",
                ActivityDescriptionPlural = "minutes",
                IsSingleEvent             = false,
                PointsEarned    = 1,
                SiteId          = siteId,
                TranslationName = "One minute, one point",
                TranslationDescriptionPastTense    = "read {0}",
                TranslationDescriptionPresentTense = "reading {0}"
            };

            pointTranslation = await _pointTranslationRepository.AddSaveAsync(userId,
                                                                              pointTranslation);

            int programCount = 0;
            var program      = new Model.Program
            {
                SiteId = siteId,
                AchieverPointAmount = 1000,
                Name               = "Prereaders (ages 4 and below)",
                Position           = programCount++,
                AgeRequired        = true,
                AskAge             = true,
                SchoolRequired     = false,
                AskSchool          = false,
                AgeMaximum         = 4,
                PointTranslationId = pointTranslation.Id
            };

            program = await _programRepository.AddSaveAsync(userId, program);

            program = new Model.Program
            {
                SiteId = siteId,
                AchieverPointAmount = 1000,
                Name               = "Kids (ages 5 to 11)",
                Position           = programCount++,
                AgeRequired        = true,
                AskAge             = true,
                SchoolRequired     = true,
                AskSchool          = true,
                AgeMaximum         = 11,
                AgeMinimum         = 5,
                PointTranslationId = pointTranslation.Id
            };
            program = await _programRepository.AddSaveAsync(userId, program);

            program = new Model.Program
            {
                SiteId = siteId,
                AchieverPointAmount = 1000,
                Name               = "Teens (ages 12 to 17)",
                Position           = programCount++,
                AgeRequired        = true,
                AskAge             = true,
                SchoolRequired     = false,
                AskSchool          = true,
                AgeMaximum         = 17,
                AgeMinimum         = 12,
                PointTranslationId = pointTranslation.Id
            };
            program = await _programRepository.AddSaveAsync(userId, program);

            program = new Model.Program
            {
                SiteId = siteId,
                AchieverPointAmount = 1000,
                Name               = "Adults (ages 18 and up)",
                Position           = programCount,
                AgeRequired        = false,
                AskAge             = false,
                SchoolRequired     = false,
                AskSchool          = false,
                AgeMinimum         = 18,
                PointTranslationId = pointTranslation.Id
            };
            program = await _programRepository.AddSaveAsync(userId, program);

            // required for a user to be an administrator
            var adminRole = await _roleRepository.AddSaveAsync(userId, new Model.Role
            {
                Name = "System Administrator"
            });

            // add code to make first user system administrator
            await _authorizationCodeRepository.AddSaveAsync(userId, new Model.AuthorizationCode
            {
                Code        = initialAuthorizationCode.Trim().ToLower(),
                Description = "Initial code to grant system administrator status.",
                IsSingleUse = true,
                RoleId      = adminRole.Id,
                SiteId      = siteId
            });

            // system permissions
            foreach (var value in Enum.GetValues(typeof(Model.Permission)))
            {
                await _roleRepository.AddPermissionAsync(userId, value.ToString());
            }
            await _roleRepository.SaveAsync();

            // add permissions to the admin role
            foreach (var value in Enum.GetValues(typeof(Model.Permission)))
            {
                await _roleRepository.AddPermissionToRoleAsync(userId,
                                                               adminRole.Id,
                                                               value.ToString());
            }
            await _roleRepository.SaveAsync();

            foreach (var value in Enum.GetValues(typeof(Model.ChallengeTaskType)))
            {
                await _challengeTaskRepository.AddChallengeTaskTypeAsync(userId,
                                                                         value.ToString());
            }
            await _challengeTaskRepository.SaveAsync();
        }
Ejemplo n.º 2
0
        public async Task InsertAsync(int siteId, string initialAuthorizationCode, int userId = -1)
        {
            //_config[ConfigurationKey.InitialAuthorizationCode]
            // this is the data required for a user to register
            var system = new Model.System
            {
                SiteId = siteId,
                Name   = "Library District"
            };

            system = await _systemRepository.AddSaveAsync(userId, system);

            var branch = new Model.Branch
            {
                SiteId   = siteId,
                SystemId = system.Id,
                Name     = "Main Library",
            };

            branch = await _branchRepository.AddSaveAsync(userId, branch);

            var program = new Model.Program
            {
                SiteId = siteId,
                AchieverPointAmount = 100,
                Name = "Reading Program",
            };

            program = await _programRepository.AddSaveAsync(userId, program);

            var pointTranslation = new Model.PointTranslation
            {
                ActivityAmount            = 1,
                ActivityDescription       = "book",
                ActivityDescriptionPlural = "books",
                IsSingleEvent             = true,
                PointsEarned    = 10,
                ProgramId       = program.Id,
                TranslationName = "One book, ten points",
                TranslationDescriptionPastTense    = "read {0}",
                TranslationDescriptionPresentTense = "reading {0}"
            };

            pointTranslation = await _pointTranslationRepository.AddSaveAsync(userId,
                                                                              pointTranslation);

            // required for a user to be an administrator
            var adminRole = await _roleRepository.AddSaveAsync(userId, new Model.Role
            {
                Name = "System Administrator"
            });

            // add code to make first user system administrator
            await _authorizationCodeRepository.AddSaveAsync(userId, new Model.AuthorizationCode
            {
                Code        = initialAuthorizationCode.Trim().ToLower(),
                Description = "Initial code to grant system administrator status.",
                IsSingleUse = true,
                RoleId      = adminRole.Id,
                SiteId      = siteId
            });

            // system permissions
            foreach (var value in Enum.GetValues(typeof(Model.Permission)))
            {
                await _roleRepository.AddPermissionAsync(userId, value.ToString());
            }
            await _roleRepository.SaveAsync();

            // add permissions to the admin role
            foreach (var value in Enum.GetValues(typeof(Model.Permission)))
            {
                await _roleRepository.AddPermissionToRoleAsync(userId,
                                                               adminRole.Id,
                                                               value.ToString());
            }
            await _roleRepository.SaveAsync();

            foreach (var value in Enum.GetValues(typeof(Model.ChallengeTaskType)))
            {
                if ((Model.ChallengeTaskType)value == Model.ChallengeTaskType.Book)
                {
                    await _challengeTaskRepository.AddChallengeTaskTypeAsync(userId,
                                                                             value.ToString(),
                                                                             1,
                                                                             pointTranslation.Id);
                }
                else
                {
                    await _challengeTaskRepository.AddChallengeTaskTypeAsync(userId,
                                                                             value.ToString());
                }
            }
            await _challengeTaskRepository.SaveAsync();
        }