using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Cors; using AutoMapper; using skydiveLogs_api.Domain; using skydiveLogs_api.Business.Interfaces; using skydiveLogs_api.DataContract; namespace skydiveLogs_api.Controllers { public class AircraftController : Base { public AircraftController(IAircraftService aircraftService, IMapper mapper) { _aircraftService = aircraftService; _mapper = mapper; } // GET: api/Aircraft [HttpGet] [EnableCors] public IEnumerable Get() { var result = _aircraftService.GetAllAircrafts(); return _mapper.Map>(result); } // GET: api/Aircraft/5 [HttpGet("{id}")] [EnableCors] public AircraftResp Get(int id) { var result = _aircraftService.GetAircraftById(id); return _mapper.Map(result); } // POST: api/Aircraft [HttpPost] [EnableCors] public void Post([FromBody] AircraftReq value) { _aircraftService.AddNewAircraft(_mapper.Map(value)); } // PUT: api/Aircraft/5 [HttpPut("{id}")] [EnableCors] public void Put(int id, [FromBody] AircraftReq value) { _aircraftService.UpdateAircraft(id, _mapper.Map(value)); } // DELETE: api/ApiWithActions/5 [HttpDelete("{id}")] [EnableCors] public void Delete(int id) { _aircraftService.DeleteAircraftById(id); } private readonly IAircraftService _aircraftService; private readonly IMapper _mapper; } }