123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
-
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using WCS.Entitys;
- using WCS.Common;
- namespace WCS.Controllers;
- [ApiController]
- [Route("api/[controller]")]
- public class WcsDeviceController : ControllerBase
- {
- private readonly ApplicationDbContext _context;
- public WcsDeviceController(ApplicationDbContext context)
- {
- _context = context;
- }
- [HttpGet]
- public async Task<ActionResult<IEnumerable<WcsDevice>>> Get()
- {
- return await _context.WcsDevices.ToListAsync();
- }
- [HttpGet("{id}")]
- public async Task<ActionResult<WcsDevice>> Get(int id)
- {
- var device = await _context.WcsDevices.FindAsync(id);
- if (device == null)
- {
- return NotFound();
- }
- return device;
- }
- [HttpPost]
- public async Task<ActionResult<WcsDevice>> Post(WcsDevice device)
- {
- _context.WcsDevices.Add(device);
- await _context.SaveChangesAsync();
- return CreatedAtAction(nameof(Get), new { id = device.Id }, device);
- }
- [HttpPut("{id}")]
- public async Task<IActionResult> Put(int id, WcsDevice device)
- {
- if (id != device.Id)
- {
- return BadRequest();
- }
- _context.Entry(device).State = EntityState.Modified;
- try
- {
- await _context.SaveChangesAsync();
- }
- catch (DbUpdateConcurrencyException)
- {
- if (!_context.WcsDevices.Any(e => e.Id == id))
- {
- return NotFound();
- }
- else
- {
- throw;
- }
- }
- return NoContent();
- }
- [HttpDelete("{id}")]
- public async Task<IActionResult> Delete(int id)
- {
- var device = await _context.WcsDevices.FindAsync(id);
- if (device == null)
- {
- return NotFound();
- }
- _context.WcsDevices.Remove(device);
- await _context.SaveChangesAsync();
- return NoContent();
- }
- }
|