@namespace Oqtane.Modules.Admin.Jobs @inherits ModuleBase @inject NavigationManager NavigationManager @inject IJobService JobService
Cancel @code { public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } int _jobId; string _name = ""; string _jobType = ""; string _isEnabled = "True"; string _interval = ""; string _frequency = ""; string _startDate = ""; string _endDate = ""; string _retentionHistory = ""; protected override async Task OnInitializedAsync() { try { _jobId = Int32.Parse(PageState.QueryString["id"]); Job job = await JobService.GetJobAsync(_jobId); if (job != null) { _name = job.Name; _jobType = job.JobType; _isEnabled = job.IsEnabled.ToString(); _interval = job.Interval.ToString(); _frequency = job.Frequency; _startDate = (job.StartDate != null) ? job.StartDate.ToString() : ""; _endDate = (job.EndDate != null) ? job.EndDate.ToString() : ""; _retentionHistory = job.RetentionHistory.ToString(); } } catch (Exception ex) { await logger.LogError(ex, "Error Loading Job {JobId} {Error}", _jobId, ex.Message); AddModuleMessage("Error Loading Job", MessageType.Error); } } private async Task SaveJob() { if (_name != "" && !string.IsNullOrEmpty(_jobType) && _frequency != "" && _interval != "" && _retentionHistory != "") { Job job = await JobService.GetJobAsync(_jobId); job.Name = _name; job.JobType = _jobType; job.IsEnabled = Boolean.Parse(_isEnabled); job.Frequency = _frequency; job.Interval = int.Parse(_interval); if (_startDate == "") { job.StartDate = null; } else { job.StartDate = DateTime.Parse(_startDate); } if (_endDate == "") { job.EndDate = null; } else { job.EndDate = DateTime.Parse(_endDate); } job.RetentionHistory = int.Parse(_retentionHistory); try { job = await JobService.UpdateJobAsync(job); await logger.LogInformation("Job Updated {Job}", job); NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { await logger.LogError(ex, "Error Udate Job {Job} {Error}", job, ex.Message); AddModuleMessage("Error Updating Job", MessageType.Error); } } else { AddModuleMessage("You Must Provide The Job Name, Type, Frequency, and Retention", MessageType.Warning); } } }