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.Models; using Parking_space_WebAPI.Services; using Parking_space_WebAPI.Authorization; namespace Parking_space_WebAPI.Controllers { [Route("api/[controller]")] [ApiController] [Authorize] [ApiExplorerSettings(GroupName = "校園外網")] public class Parking_spaces_lcd_instandController : ControllerBase { private readonly SqlContext _context; public Parking_spaces_lcd_instandController(SqlContext context) { _context = context; } #region 取出所有字幕機資料 // GET: api/Parking_spaces_lcd_instand /// /// 取出字幕機所有資料(URL 區域 顯示數量) /// [HttpGet] public async Task>> Getparking_spaces_lcd_instand() { if (_context.parking_spaces_lcd_instand == null) { return NotFound(); } return await _context.parking_spaces_lcd_instand.ToListAsync(); } #endregion #region 從區域名稱抓字幕機資料 // GET: api/Parking_spaces_lcd_instand/5 /// /// 從區域名稱抓字幕機資料 /// [HttpGet("parking_space_area-{id}")] public async Task> GetParking_spaces_lcd_instand(string id) { var parking_spaces_lcd_instand = await(from c in _context.parking_spaces_lcd_instand where c.parking_spaces_name ==id select new Parking_spaces_lcd_instand { lcd_ip=c.lcd_ip, parking_spaces_name=c.parking_spaces_name, parking_space_amount=c.parking_space_amount, }).ToArrayAsync(); return parking_spaces_lcd_instand; } #endregion #region 更新字幕機資料 /// /// 更新字幕機資料 /// // PUT: api/Parking_spaces_lcd_instand/5 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPut("{id}")] public async Task PutParking_spaces_lcd_instand(string id, Parking_spaces_lcd_instand parking_spaces_lcd_instand) { if (id != parking_spaces_lcd_instand.lcd_ip) { return BadRequest(); } _context.Entry(parking_spaces_lcd_instand).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Parking_spaces_lcd_instandExists(id)) { return NotFound(); } else { throw; } } return NoContent(); } #endregion #region 新增字幕機資料 /// /// 新增字幕機資料(URL 區域 顯示數量) /// // POST: api/Parking_spaces_lcd_instand // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPost] public async Task> PostParking_spaces_lcd_instand(Parking_spaces_lcd_instand parking_spaces_lcd_instand) { if (_context.parking_spaces_lcd_instand == null) { return Problem("Entity set 'SqlContext.parking_spaces_lcd_instand' is null."); } _context.parking_spaces_lcd_instand.Add(parking_spaces_lcd_instand); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (Parking_spaces_lcd_instandExists(parking_spaces_lcd_instand.lcd_ip)) { return Conflict(); } else { throw; } } return CreatedAtAction("GetParking_spaces_lcd_instand", new { id = parking_spaces_lcd_instand.lcd_ip }, parking_spaces_lcd_instand); } #endregion #region 刪除字幕機資料 /// /// 刪除字幕機資料 /// // DELETE: api/Parking_spaces_lcd_instand/5 [HttpDelete("{id}")] public async Task DeleteParking_spaces_lcd_instand(string id) { if (_context.parking_spaces_lcd_instand == null) { return NotFound(); } var parking_spaces_lcd_instand = await _context.parking_spaces_lcd_instand.FindAsync(id); if (parking_spaces_lcd_instand == null) { return NotFound(); } _context.parking_spaces_lcd_instand.Remove(parking_spaces_lcd_instand); await _context.SaveChangesAsync(); return NoContent(); } #endregion private bool Parking_spaces_lcd_instandExists(string id) { return (_context.parking_spaces_lcd_instand?.Any(e => e.lcd_ip == id)).GetValueOrDefault(); } } }