Пример #1
0
        public async Task <Program> AddProgramAsync(Program program)
        {
            VerifyPermission(Permission.ManagePrograms);
            var siteId = GetCurrentSiteId();
            var filter = new BaseFilter()
            {
                SiteId = siteId
            };

            program.Position = await _programRepository.CountAsync(filter);

            program.SiteId = siteId;

            return(await _programRepository.AddSaveAsync(GetClaimId(ClaimType.UserId), program));
        }
Пример #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
            {
                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();
        }
Пример #3
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();
        }
        public async Task InsertAsync(int siteId, string initialAuthorizationCode)
        {
            int userId = Defaults.InitialInsertUserId;

            //_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",
                Address  = "The Geographic Center, Lebanon, KS 66952"
            };

            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);

            var programIds   = new List <int>();
            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);

            programIds.Add(program.Id);

            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);

            programIds.Add(program.Id);

            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);

            programIds.Add(program.Id);

            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);

            programIds.Add(program.Id);

            // insert system user
            userId = await _userRepository.GetSystemUserId();

            await _systemRepository.UpdateCreatedByAsync(userId, system.Id);

            await _branchRepository.UpdateCreatedByAsync(userId, branch.Id);

            await _pointTranslationRepository.UpdateCreatedByAsync(userId, pointTranslation.Id);

            await _programRepository.UpdateCreatedByAsync(userId, programIds.ToArray());

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

            // 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 = false,
                RoleId      = adminRole.Id,
                SiteId      = siteId
            });

            // set up system permissions and add to the admin role
            var permissionList = Enum.GetValues(typeof(Model.Permission))
                                 .Cast <Model.Permission>()
                                 .Select(_ => _.ToString());
            await _roleRepository.AddPermissionListAsync(userId, permissionList);

            await _roleRepository.SaveAsync();

            foreach (var value in Enum.GetValues(typeof(Model.ChallengeTaskType)))
            {
                await _challengeTaskRepository.AddChallengeTaskTypeAsync(userId,
                                                                         value.ToString());
            }
            await _challengeTaskRepository.SaveAsync();
        }
Пример #5
0
        public async Task InsertAsync(int siteId, string initialAuthorizationCode)
        {
            int userId = Defaults.InitialInsertUserId;
            //_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",
                Address  = "The Geographic Center, Lebanon, KS 66952"
            };

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

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

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

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

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

            // insert system user
            userId = await _userRepository.GetSystemUserId();

            await _systemRepository.UpdateCreatedByAsync(userId, system.Id);

            await _branchRepository.UpdateCreatedByAsync(userId, branch.Id);

            await _pointTranslationRepository.UpdateCreatedByAsync(userId, pointTranslation.Id);

            await _programRepository.UpdateCreatedByAsync(userId, new int[] { program.Id });

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

            // 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 = false,
                RoleId      = adminRole.Id,
                SiteId      = siteId
            });

            // set up system permissions and add to the admin role
            var permissionList = Enum.GetValues(typeof(Model.Permission))
                                 .Cast <Model.Permission>()
                                 .Select(_ => _.ToString());
            await _roleRepository.AddPermissionListAsync(userId, permissionList);

            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();
        }