using Microsoft.AspNetCore.Mvc; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace Aufgabe19.Controllers { [Route("api/[controller]")] [ApiController] public class CustomerController : ControllerBase { private List mCustomers = new List { new Customer(1, "Jens", "Mander"), new Customer(2, "Hans", "Wurst"), new Customer(3, "Guybrush", "Threepwod") }; // GET: api/ [HttpGet] public IEnumerable Get() { return mCustomers; } // GET api//5 [HttpGet("{id}")] public Customer Get(int id) { return mCustomers.FirstOrDefault(customer => customer.Id == id); } // POST api/ [HttpPost] public void Post([FromBody] Customer value) { if (!mCustomers.Any(c => c.Id == value.Id && c.FirstName == value.FirstName && c.LastName == value.LastName)) { mCustomers.Add(value); } } // DELETE api//5 [HttpDelete("{id}")] public void Delete(int id) { mCustomers.Remove(mCustomers.FirstOrDefault(customer => customer.Id == id)); } } }