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 Parking_space_WebAPI.Services; using Parking_space_WebAPI.Authorization; using WebApi_data_value.Models; namespace WebApi_data_value.Controllers { [Route("api/[controller]")] [ApiController] [Authorize] [ApiExplorerSettings(GroupName = "校園大內網")] public class El125_car_tableController : ControllerBase { private readonly SqlContext _context; public El125_car_tableController(SqlContext context) { _context = context; } // GET: api/El125_car_table [HttpGet] public async Task>> Getel125_car_table() { if (_context.el125_car_table == null) { return NotFound(); } return await _context.el125_car_table.ToListAsync(); } // GET: api/El125_car_table/5 [HttpGet("{id}")] public async Task> GetEl125_car_table(string id) { if (_context.el125_car_table == null) { return NotFound(); } var el125_car_table = await _context.el125_car_table.FindAsync(id); if (el125_car_table == null) { return NotFound(); } return el125_car_table; } // PUT: api/El125_car_table/5 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPut("{id}")] public async Task PutEl125_car_table(string id, El125_car_table el125_car_table) { if (id != el125_car_table.license_plate_number) { return BadRequest(); } _context.Entry(el125_car_table).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!El125_car_tableExists(id)) { return NotFound(); } else { throw; } } return NoContent(); } // POST: api/El125_car_table // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPost] public async Task> PostEl125_car_table(El125_car_table el125_car_table) { if (_context.el125_car_table == null) { return Problem("Entity set 'SqlContext.el125_car_table' is null."); } var license_plate_number = el125_car_table.license_plate_number; var data = await (from c in _context.el125_car_table where c.license_plate_number == license_plate_number select c ).FirstOrDefaultAsync(); if (data == null) { _context.el125_car_table.Add(el125_car_table); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (El125_car_tableExists(el125_car_table.license_plate_number)) { return Conflict(); } else { throw; } } return Ok("ok"); } return Ok("車牌重複"); } // DELETE: api/El125_car_table/5 [HttpDelete("{id}")] public async Task DeleteEl125_car_table(string id) { if (_context.el125_car_table == null) { return NotFound(); } var el125_car_table = await _context.el125_car_table.FindAsync(id); if (el125_car_table == null) { return NotFound(); } _context.el125_car_table.Remove(el125_car_table); await _context.SaveChangesAsync(); return NoContent(); } private bool El125_car_tableExists(string id) { return (_context.el125_car_table?.Any(e => e.license_plate_number == id)).GetValueOrDefault(); } } }