using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace jobApi.Controllers
public class JobController : ControllerBase
private readonly JobContext _context;
public JobController(JobContext context)
if (_context.JobItems.Count() == 0)
_context.JobItems.Add(new JobItem { Name = "Item1" });
public async Task<ActionResult<IEnumerable<JobItem>>> GetJobItems()
return await _context.JobItems.ToListAsync();
public async Task<ActionResult<JobItem>> GetJobItem(long id)
var jobItem = await _context.JobItems.FindAsync(id);
public async Task<ActionResult<IEnumerable<JobItem>>> GetScheduledJobs()
return await _context.JobItems.ToListAsync();
public async Task<ActionResult<JobItem>> GetScheduledJobs(long id)
var jobItem = await _context.JobItems.FindAsync(id);
public IEnumerable<string> Get()
return new string[] { "value1", "value2" };
public string Get(int id)
public void Post([FromBody]string value)
public async Task<ActionResult<JobItem>> CreateNewBatchJob(JobItem item)
_context.JobItems.Add(item);
await _context.SaveChangesAsync();
return CreatedAtAction(nameof(GetJobItem), new { id = item.Id }, item);
public void Put(int id, [FromBody]string value)
public void DisableJob(int id, [FromBody]string value)
public void DisableSpecificJob(int id, [FromBody]string value)
public void UpdateJob(int id, [FromBody]string value)
public async Task<IActionResult> PutJobItem(long id, JobItem item)
_context.Entry(item).State = EntityState.Modified;
await _context.SaveChangesAsync();
public void Delete(int id)
public async Task<IActionResult> DeleteJobItem(long id)
var todoItem = await _context.JobItems.FindAsync(id);
_context.JobItems.Remove(jobItem);
await _context.SaveChangesAsync();