using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using StudyLib.API.Data; using StudyLib.Models; namespace StudyLib.API.Controllers { [Route("api/[controller]")] [ApiController] public class TestController : ControllerBase { private readonly StudyLibContext _context; public TestController(StudyLibContext context) { _context = context; } // GET: api/MinorExams [HttpGet] public async Task>> GetMinorExams() { return await _context.Tests.ToListAsync(); } // GET: api/MinorExams/5 [HttpGet("{id}")] public async Task> GetMinorExam(long id) { var minorExam = await _context.Tests.FindAsync(id); if (minorExam == null) { return NotFound(); } return minorExam; } // PUT: api/MinorExams/5 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPut("{id}")] public async Task PutMinorExam(long id, Test minorExam) { if (id != minorExam.ID) { return BadRequest(); } _context.Entry(minorExam).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MinorExamExists(id)) { return NotFound(); } else { throw; } } return NoContent(); } // POST: api/MinorExams // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPost] public async Task> PostMinorExam(Test minorExam) { _context.Tests.Add(minorExam); await _context.SaveChangesAsync(); return CreatedAtAction("GetMinorExam", new { id = minorExam.ID }, minorExam); } // DELETE: api/MinorExams/5 [HttpDelete("{id}")] public async Task DeleteMinorExam(long id) { var minorExam = await _context.Tests.FindAsync(id); if (minorExam == null) { return NotFound(); } _context.Tests.Remove(minorExam); await _context.SaveChangesAsync(); return NoContent(); } private bool MinorExamExists(long id) { return _context.Tests.Any(e => e.ID == id); } } }