Beispiel #1
0
 public MainWindow()
 {
     InitializeComponent();
     mSys = bSys.Select().Single();
     bSys.Initialize(mSys);
     bSys.Update(mSys);
     Main.NavigationService.Navigate(new HomePage());
 }
        public async Task <Model.System> Edit(Model.System model)
        {
            var result = await _systemRepository.Update(model);

            if (result)
            {
                return(await _systemRepository.Read(model.Id));
            }

            throw new ArgumentException();
        }
Beispiel #3
0
        public async Task UpdateSystemAsync(Model.System system)
        {
            VerifyPermission(Permission.ManageSystems);
            var currentSystem = await _systemRepository.GetByIdAsync(system.Id);

            if (currentSystem.SiteId != GetCurrentSiteId())
            {
                throw new GraException($"Permission denied - system belongs to site id {currentSystem.SiteId}.");
            }
            currentSystem.Name = system.Name;
            await _systemRepository.UpdateSaveAsync(GetClaimId(ClaimType.UserId), currentSystem);
        }
Beispiel #4
0
        public void LogOut()
        {
            var result = MessageBox.Show("Você realmente deseja sair?", "Log out", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                mSys = bSys.Select().Single();
                bSys.Initialize(mSys);
                bSys.Update(mSys);
                UpdateHeaderText(loginBtn, registerBtn, logoutBtn, wMessageTxt);
            }
        }
Beispiel #5
0
 public void Initialize(Model.System sys)
 {
     sys.UserLoged   = false;
     sys.CurrentUser = new Model.User()
     {
         Id       = -1,
         Name     = "visitante",
         Password = null,
         Admin    = false
     };
     sys.Id = 0;
 }
Beispiel #6
0
 public async Task <Model.System> AddSystemAsync(Model.System system)
 {
     VerifyPermission(Permission.ManageSystems);
     system.SiteId = GetCurrentSiteId();
     return(await _systemRepository.AddSaveAsync(GetClaimId(ClaimType.UserId), system));
 }
        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();
        }
        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();
        }
Beispiel #9
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 <JobStatus> RunImportJobAsync(int jobId,
                                                        CancellationToken token,
                                                        IProgress <JobStatus> progress = null)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            var job = await _jobRepository.GetByIdAsync(jobId);

            var jobDetails
                = JsonConvert.DeserializeObject <JobBranchImport>(job.SerializedParameters);

            _logger.LogInformation("Job {JobId}: {JobType} to import {Filename}",
                                   job.Id,
                                   job.JobType,
                                   jobDetails.Filename);

            ICollection <Branch> importBranches = null;
            ICollection <string> importSystems  = null;

            token.Register(() =>
            {
                _logger.LogWarning("Job {JobId}: {ImportType} of {Filename} was cancelled after {Elapsed} ms.",
                                   job.Id,
                                   jobDetails.DoImport ? "Import" : "Test run",
                                   jobDetails.Filename,
                                   sw?.Elapsed.TotalMilliseconds);
            });

            string fullPath = _pathResolver.ResolvePrivateTempFilePath(jobDetails.Filename);

            if (!System.IO.File.Exists(fullPath))
            {
                _logger.LogError("Could not find {Filename}", fullPath);
                return(new JobStatus
                {
                    PercentComplete = 0,
                    Status = "Could not find the import file.",
                    Error = true,
                    Complete = true
                });
            }

            int importedCount  = 0;
            int processedCount = 0;

            int systemAdd  = 0;
            int systemEdit = 0;
            int branchAdd  = 0;
            int branchEdit = 0;

            int geocodingIssues = 0;

            var createdAt = _dateTimeProvider.Now;

            try
            {
                _logger.LogInformation("Job {JobId}: {ImportType} reading in CSV file: {Filename}",
                                       job.Id,
                                       jobDetails.DoImport ? "Import" : "Test run",
                                       jobDetails.Filename);

                progress?.Report(new JobStatus
                {
                    Status = "Reading in CSV file..."
                });

                try
                {
                    importBranches = await ReadBranchesAsync(fullPath);
                }
                catch (System.IO.IOException ioex)
                {
                    _logger.LogError(ioex,
                                     "Job {JobId}: Error reading CSV file {Filename}: {ErrorMessage}",
                                     job.Id,
                                     jobDetails.Filename,
                                     ioex.Message);
                    return(new JobStatus
                    {
                        Error = true,
                        Complete = true,
                        Status = $"Error reading records from the CSV file: {ioex.Message}"
                    });
                }

                if (importBranches?.Count == 0)
                {
                    return(new JobStatus
                    {
                        Error = true,
                        Complete = true,
                        Status = "No records found in the CSV file."
                    });
                }

                importSystems = importBranches.Select(_ => _.SystemName)
                                .OrderBy(_ => _)
                                .Distinct()
                                .ToList();

                _logger.LogInformation("Job {JobId}: {ImportType} found {SystemCount} systems, {BranchCount} branches",
                                       job.Id,
                                       jobDetails.DoImport ? "Import" : "Test run",
                                       importSystems?.Count,
                                       importBranches?.Count);

                await _jobRepository.UpdateStatusAsync(jobId,
                                                       $"Found {importSystems?.Count} systems and {importBranches?.Count} branches in the CSV file");

                progress?.Report(new JobStatus
                {
                    Status = $"Found {importSystems?.Count} systems and {importBranches?.Count} branches in the uploaded file..."
                });
                var lastUpdate = sw.Elapsed.TotalSeconds;

                var totalRecords = importSystems?.Count + importBranches?.Count;

                var softwareSystems = await _siteService.GetSystemList();

                var systemIndex = softwareSystems.ToDictionary(k => k.Id, v => v.Name);

                if (importSystems?.Count > 0)
                {
                    foreach (var importSystem in importSystems)
                    {
                        processedCount++;
                        var alreadyPresent = softwareSystems
                                             .FirstOrDefault(_ => _.Name == importSystem);

                        if (alreadyPresent != null)
                        {
                            _logger.LogInformation("Job {JobId}: Not creating system {SystemName}, already present as id {SystemId}",
                                                   job.Id,
                                                   importSystem,
                                                   alreadyPresent.Id);
                        }
                        else
                        {
                            Model.System existingSystem = null;
                            if (systemAdd + systemEdit == 0)
                            {
                                existingSystem = softwareSystems.SingleOrDefault();
                            }
                            if (existingSystem == null)
                            {
                                // add
                                systemAdd++;
                                if (jobDetails.DoImport)
                                {
                                    var addedSystem
                                        = await _siteService.AddSystemAsync(new Model.System
                                    {
                                        CreatedAt = createdAt,
                                        CreatedBy = jobDetails.UserId,
                                        Name      = importSystem,
                                        SiteId    = job.SiteId
                                    });

                                    systemIndex.Add(addedSystem.Id, importSystem);
                                    importedCount++;
                                }
                                else
                                {
                                    var fauxKey = systemAdd;
                                    while (systemIndex.ContainsKey(fauxKey))
                                    {
                                        fauxKey++;
                                    }
                                    systemIndex.Add(fauxKey, importSystem);
                                }
                            }
                            else
                            {
                                // edit
                                systemEdit++;
                                systemIndex[existingSystem.Id] = importSystem;
                                if (jobDetails.DoImport)
                                {
                                    _logger.LogInformation("Job {JobId}: Repurposing system {OldSystemName} as {NewSystemName}",
                                                           job.Id,
                                                           existingSystem.Name,
                                                           importSystem);
                                    existingSystem.CreatedAt = createdAt;
                                    existingSystem.CreatedBy = jobDetails.UserId;
                                    existingSystem.Name      = importSystem;
                                    await _siteService.UpdateSystemAsync(existingSystem);

                                    importedCount++;
                                }
                            }
                        }

                        if (sw.Elapsed.TotalSeconds > lastUpdate + 5)
                        {
                            progress?.Report(new JobStatus
                            {
                                PercentComplete = processedCount * 100 / totalRecords,
                                Status          = $"Processed {processedCount}, imported {importedCount} records; on system: {importSystem}"
                            });
                            lastUpdate = sw.Elapsed.TotalSeconds;
                        }
                    }
                }

                var status = new JobStatus
                {
                    Status = $"Processed {processedCount}, imported {importedCount} records; now importing branches..."
                };

                if (totalRecords > 0)
                {
                    status.PercentComplete = processedCount * 100 / totalRecords;
                }

                progress?.Report(status);
                lastUpdate = sw.Elapsed.TotalSeconds;

                if (importBranches?.Count > 0)
                {
                    var softwareBranches = await _siteService.GetAllBranches();

                    foreach (var branch in importBranches)
                    {
                        processedCount++;
                        var alreadyPresent = softwareBranches
                                             .FirstOrDefault(_ => _.Name == branch.Name &&
                                                             _.SystemName == branch.SystemName);

                        if (alreadyPresent != null)
                        {
                            _logger.LogInformation("Job {JobId}: Not creating branch {BranchName}, already present as id {BranchId}",
                                                   job.Id,
                                                   branch.Name,
                                                   alreadyPresent.Id);
                        }
                        else
                        {
                            Model.Branch existingBranch = null;
                            int?         systemId       = null;

                            if (systemIndex.ContainsValue(branch.SystemName))
                            {
                                systemId = systemIndex
                                           .Single(_ => _.Value == branch.SystemName)
                                           .Key;
                            }

                            if (systemId == null)
                            {
                                _logger.LogInformation("Job {JobId}: Couldn't find system named {SystemName} for branch {BranchName} in the database.",
                                                       job.Id,
                                                       branch.SystemName,
                                                       branch.Name);
                                return(new JobStatus
                                {
                                    Error = true,
                                    Complete = true,
                                    Status = $"Could not find system {branch.SystemName} for branch {branch.Name}."
                                });
                            }
                            if (branchAdd + branchEdit == 0)
                            {
                                existingBranch = softwareBranches.SingleOrDefault();
                            }

                            //geolocation
                            string geocode = null;
                            if (!string.IsNullOrEmpty(branch.Address))
                            {
                                geocode = await GeocodeAsync(job.SiteId, branch.Address);

                                if (string.IsNullOrEmpty(geocode))
                                {
                                    geocodingIssues++;
                                }
                            }

                            if (existingBranch == null)
                            {
                                // add
                                branchAdd++;
                                if (jobDetails.DoImport)
                                {
                                    await _siteService.AddBranchAsync(new Model.Branch
                                    {
                                        Address     = branch.Address,
                                        CreatedAt   = createdAt,
                                        CreatedBy   = jobDetails.UserId,
                                        Geolocation = geocode,
                                        Name        = branch.Name,
                                        SystemId    = (int)systemId,
                                        Telephone   = branch.Telephone,
                                        Url         = branch.Url
                                    });

                                    importedCount++;
                                }
                            }
                            else
                            {
                                // edit
                                branchEdit++;
                                if (jobDetails.DoImport)
                                {
                                    _logger.LogInformation("Job {JobId}: Repurposing branch {OldBranchName} as {NewBranchName}",
                                                           job.Id,
                                                           existingBranch.Name,
                                                           branch.Name);
                                    existingBranch.Address     = branch.Address;
                                    existingBranch.CreatedAt   = createdAt;
                                    existingBranch.CreatedBy   = jobDetails.UserId;
                                    existingBranch.Geolocation = geocode;
                                    existingBranch.Name        = branch.Name;
                                    existingBranch.SystemId    = (int)systemId;
                                    existingBranch.Telephone   = branch.Telephone;
                                    existingBranch.Url         = branch.Url;
                                    await _siteService.UpdateBranchAsync(existingBranch);

                                    importedCount++;
                                }
                            }
                        }

                        if (sw.Elapsed.TotalSeconds > lastUpdate + 5)
                        {
                            progress?.Report(new JobStatus
                            {
                                PercentComplete = processedCount * 100 / totalRecords,
                                Status          = $"Processed {processedCount}, imported {importedCount} records; on branch: {branch.Name}"
                            });
                            lastUpdate = sw.Elapsed.TotalSeconds;
                        }
                    }
                }
            }
            finally
            {
                System.IO.File.Delete(fullPath);
            }
            sw.Stop();

            // get result, return new JobStatus (percent = 100, complete = tru, status = whatever, error = true/false
            if (token.IsCancellationRequested)
            {
                _logger.LogWarning("Job {JobId}: Cancelled after importing {ImportedCount} records and {Elapsed} ms",
                                   job.Id,
                                   importedCount,
                                   sw.ElapsedMilliseconds);

                return(new JobStatus
                {
                    Complete = true,
                    Status = $"Import cancelled after {importedCount} records and {sw.Elapsed:c} seconds."
                });
            }

            await _jobRepository.UpdateStatusAsync(jobId,
                                                   $"Imported {systemAdd + systemEdit} systems and {branchAdd + branchEdit} branches.");

            _logger.LogInformation("Job {JobId}: {ImportType} added {SystemsAdded}, edited {SystemsEdited} systems; added {BranchesAdded}, edited {BranchesEdited} branches; {GeocodingIssues} geocoding issues",
                                   job.Id,
                                   jobDetails.DoImport ? "Import" : "Test run",
                                   systemAdd,
                                   systemEdit,
                                   branchAdd,
                                   branchEdit,
                                   geocodingIssues);

            var importType = jobDetails.DoImport ? "Imported" : "Test run imported";

            _logger.LogInformation("Job {JobId}: {ImportType} {importedCount} records in {Elapsed} ms",
                                   job.Id,
                                   importType,
                                   importedCount,
                                   sw.ElapsedMilliseconds);

            return(new JobStatus
            {
                PercentComplete = 100,
                Complete = true,
                Status = $"{importType} {importedCount} records (systems: {systemAdd} added, {systemEdit} updated; branches: {branchAdd} added, {branchEdit} updated) with {geocodingIssues} geocoding issues in {sw.Elapsed:c} seconds."
            });
        }
 public void SelectionChanged(CheckBox sender, Model.System dataContext)
 {
     dataContext.IsSelected = sender.IsChecked == true;
 }
        public async Task <Model.System> Create(Model.System model)
        {
            var createdId = await _systemRepository.Create(model);

            return(await _systemRepository.Read(createdId));
        }
Beispiel #13
0
 public void Initialize(Model.System sys)
 {
     pSys.Initialize(sys);
 }
Beispiel #14
0
 public void Update(Model.System sys)
 {
     pSys.Update(sys);
 }
Beispiel #15
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();
        }
Beispiel #16
0
 public void Update(Model.System sys)
 {
     File <Model.System> .Update(file, sys);
 }