@namespace Oqtane.Modules.Admin.Jobs @inherits ModuleBase @inject NavigationManager NavigationManager @inject IJobService JobService @inject IStringLocalizer Localizer
@Localizer["Cancel"] @code { private string _name = string.Empty; private string _jobType = string.Empty; private string _isEnabled = "True"; private string _interval = string.Empty; private string _frequency = string.Empty; private string _startDate = string.Empty; private string _endDate = string.Empty; private string _retentionHistory = "10"; public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; private async Task SaveJob() { if (_name != string.Empty && !string.IsNullOrEmpty(_jobType) && _frequency != string.Empty && _interval != string.Empty && _retentionHistory != string.Empty) { var job = new Job(); job.Name = _name; job.JobType = _jobType; job.IsEnabled = Boolean.Parse(_isEnabled); job.Frequency = _frequency; job.Interval = int.Parse(_interval); if (_startDate == string.Empty) { job.StartDate = null; } else { job.StartDate = DateTime.Parse(_startDate); } if (_endDate == string.Empty) { job.EndDate = null; } else { job.EndDate = DateTime.Parse(_endDate); } job.RetentionHistory = int.Parse(_retentionHistory); job.IsStarted = false; job.IsExecuting = false; job.NextExecution = null; try { job = await JobService.AddJobAsync(job); await logger.LogInformation("Job Added {Job}", job); NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { await logger.LogError(ex, "Error Adding Job {Job} {Error}", job, ex.Message); AddModuleMessage(Localizer["Error Adding Job"], MessageType.Error); } } else { AddModuleMessage(Localizer["You Must Provide The Job Name, Type, Frequency, and Retention"], MessageType.Warning); } } }