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