using DamageAssesment.Api.Locations.Interfaces; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace DamageAssesment.Api.Locations.Controllers { [Route("Locations")] //[Route("[controller]")] [ApiController] public class LocationsController : ControllerBase { private ILocationsProvider LocationProvider; public LocationsController(ILocationsProvider LocationsProvider) { this.LocationProvider = LocationsProvider; } /// /// Get all locations. /// //[HttpGet("locations")] [HttpGet] public async Task GetLocationsAsync() { var result = await LocationProvider.GetLocationsAsync(); if (result.IsSuccess) { return Ok(result.locations); } return NotFound(); } /// /// Get all locations based on locationdId. /// [HttpGet("{id}")] public async Task GetLocationByIdAsync(string id) { var result = await LocationProvider.GetLocationByIdAsync(id); if (result.IsSuccess) { return Ok(result.Location); } return NotFound(); } /// /// Update a Location. /// [HttpPut("{locations}")] public async Task UpdateLocation(Models.Location location) { if (location != null) { var result = await this.LocationProvider.UpdateLocationAsync(location); if (result.IsSuccess) { return Ok(result.ErrorMessage); } return NotFound(); } return NotFound(); } /// /// Save a new location. /// [HttpPost("{locations}")] public async Task CreateLocation(Models.Location Location) { if (Location != null) { var result = await this.LocationProvider.PostLocationAsync(Location); if (result.IsSuccess) { return Ok(result.Question); } return NotFound(); } return CreatedAtRoute("DefaultApi", new { id = Location.Id }, Location); } /// /// Delete an existing location. /// [HttpDelete("{id}")] public async Task DeleteLocation(string id) { var result = await this.LocationProvider.DeleteLocationAsync(id); if (result.IsSuccess) { return Ok(result.ErrorMessage); } return NotFound(); } } }