This repository has been archived on 2025-05-14. You can view files and clone it, but cannot push or open issues or pull requests.
Pavel Vesely 5b3feaf26f Server naming fixes and cleanup
Server is now completely cleaned up and without warnings
2020-03-15 11:53:24 +01:00

57 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Oqtane.Models;
namespace Oqtane.Repository
{
public class JobRepository : IJobRepository
{
private MasterDBContext _db;
private readonly IMemoryCache _cache;
public JobRepository(MasterDBContext context, IMemoryCache cache)
{
_db = context;
_cache = cache;
}
public IEnumerable<Job> GetJobs()
{
return _cache.GetOrCreate("jobs", entry =>
{
entry.SlidingExpiration = TimeSpan.FromMinutes(30);
return _db.Job.ToList();
});
}
public Job AddJob(Job job)
{
_db.Job.Add(job);
_db.SaveChanges();
return job;
}
public Job UpdateJob(Job job)
{
_db.Entry(job).State = EntityState.Modified;
_db.SaveChanges();
return job;
}
public Job GetJob(int jobId)
{
return _db.Job.Find(jobId);
}
public void DeleteJob(int jobId)
{
Job job = _db.Job.Find(jobId);
_db.Job.Remove(job);
_db.SaveChanges();
}
}
}