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 Assignment3.Data; using Assignment3.Models; using NuGet.Packaging.Signing; namespace Assignment3.Controllers { [Route("api/[controller]")] [ApiController] public class ProvidersController : ControllerBase { private readonly Assignment3Context _context; public ProvidersController(Assignment3Context context) { _context = context; } // GET: api/Providers [HttpGet] public async Task>> GetProvider() { if (_context.Provider == null) { return NotFound(); } return await _context.Provider.ToListAsync(); } // GET: api/Providers/5 [HttpGet("{id}")] public async Task> GetProvider(Guid id) { if (_context.Provider == null) { return NotFound(); } var provider = await _context.Provider.FindAsync(id); if (provider == null) { return NotFound(); } return provider; } // PUT: api/Providers/5 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPut("{id}")] public async Task PutProvider(Guid id, Provider provider) { if (id != provider.Id) { return BadRequest(); } _context.Entry(provider).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProviderExists(id)) { return NotFound(); } else { throw; } } return NoContent(); } // POST: api/Providers // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPost] public async Task> PostProvider(Provider provider) { if (_context.Provider == null) { return Problem("Entity set 'Assignment3Context.Provider' is null."); } _context.Provider.Add(provider); await _context.SaveChangesAsync(); return CreatedAtAction("GetProvider", new { id = provider.Id }, provider); } // DELETE: api/Providers/5 [HttpDelete("{id}")] public async Task DeleteProvider(Guid id) { if (_context.Provider == null) { return NotFound(); } var provider = await _context.Provider.FindAsync(id); if (provider == null) { return NotFound(); } _context.Provider.Remove(provider); await _context.SaveChangesAsync(); return NoContent(); } [HttpGet("firstName={value}")] public async Task> GetProviderFirstName(string firstName) { if (_context.Provider == null) { return NotFound(); } var provider = await _context.Provider.FirstOrDefaultAsync(i => i.FirstName == firstName); if (provider == null) { return NotFound(); } return provider; } [HttpGet("lastName={value}")] public async Task> GetProviderLastName(string lastname) { if (_context.Provider == null) { return NotFound(); } var provider = await _context.Provider.FirstOrDefaultAsync(i => i.LastName == lastname); if (provider == null) { return NotFound(); } return provider; } [HttpGet("licenseNumber={value}")] public async Task> GetProviderlicenseNumber(long number) { if (_context.Provider == null) { return NotFound(); } var provider = await _context.Provider.FirstOrDefaultAsync(i => i.LicenseNumber == number); if (provider == null) { return NotFound(); } return provider; } private bool ProviderExists(Guid id) { return (_context.Provider?.Any(e => e.Id == id)).GetValueOrDefault(); } } }