using AutoMapper; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using skydiveLogs_api.DataContract; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; using System.Collections.Generic; using System.Linq; namespace skydiveLogs_api.Controllers { public class JumpController : Base { #region Public Constructors public JumpController(IJumpService jumpService, IMapper mapper) { _jumpService = jumpService; _mapper = mapper; } #endregion Public Constructors #region Public Methods // DELETE: api/Jump/5 [HttpDelete("{id}")] [EnableCors] public void Delete(int id) { _jumpService.DeleteJumpById(id); } // GET: api/Jump [HttpGet] [EnableCors] public JumpListResp Get() { var tmp = _jumpService.GetAllJumps(); var result = new JumpListResp { Rows = _mapper.Map>(tmp), Count = tmp.Count() }; return result; } // GET: api/Jump/5/10 [HttpGet("{beginJumpIndex}/{endJumpIndex}")] [EnableCors] public JumpListResp Get(int beginJumpIndex, int endJumpIndex) { var totalJumps = _jumpService.GetJumpCount(); var tmp = _jumpService.GetJumpsByIndexes(beginJumpIndex, endJumpIndex); var result = new JumpListResp { Rows = _mapper.Map>(tmp), Count = totalJumps }; return result; } // GET: api/Jump/5 [HttpGet("{id}")] [EnableCors] public JumpResp Get(int id) { var result = _jumpService.GetJumpById(id); return _mapper.Map(result); } // POST: api/Jump [HttpPost] [EnableCors] public void Post([FromBody] JumpReq value) { _jumpService.AddNewJump(value.AircraftId, value.DropZoneId, value.JumpTypeId, value.GearId, _mapper.Map(value)); } // PUT: api/Jump/5 [HttpPut("{id}")] [EnableCors] public void Put(int id, [FromBody] JumpReq value) { _jumpService.UpdateJump(id, _mapper.Map(value)); } #endregion Public Methods #region Private Fields private readonly IJumpService _jumpService; private readonly IMapper _mapper; #endregion Private Fields } }