forked from MDCPS/DamageAssessment_Backend
Copy from old Repository
This commit is contained in:
@ -0,0 +1,85 @@
|
||||
using DamageAssesment.Api.Locations.Interfaces;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DamageAssesment.Api.Locations.Controllers
|
||||
{
|
||||
[Route("api")]
|
||||
[ApiController]
|
||||
public class LocationsController : ControllerBase
|
||||
{
|
||||
private ILocationsProvider LocationProvider;
|
||||
|
||||
public LocationsController(ILocationsProvider LocationsProvider)
|
||||
{
|
||||
this.LocationProvider = LocationsProvider;
|
||||
}
|
||||
// Get all Locations
|
||||
[HttpGet("Locations")]
|
||||
public async Task<ActionResult> GetLocationsAsync()
|
||||
{
|
||||
|
||||
var result = await LocationProvider.GetLocationsAsync();
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.locations);
|
||||
}
|
||||
return NotFound();
|
||||
|
||||
}
|
||||
// Get all Location based on Id
|
||||
[HttpGet("Locations/{id}")]
|
||||
public async Task<ActionResult> GetLocationByIdAsync(string id)
|
||||
{
|
||||
|
||||
var result = await LocationProvider.GetLocationByIdAsync(id);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.Location);
|
||||
}
|
||||
return NotFound();
|
||||
|
||||
}
|
||||
// Update Location entity
|
||||
[HttpPut("Locations")]
|
||||
public async Task<IActionResult> UpdateLocation(Db.Location Location)
|
||||
{
|
||||
if (Location != null)
|
||||
{
|
||||
var result = await this.LocationProvider.UpdateLocationAsync(Location);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.ErrorMessage);
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
//save new location
|
||||
[HttpPost("Locations")]
|
||||
public async Task<IActionResult> CreateLocation(Db.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 existing location
|
||||
[HttpDelete("Locations/{id}")]
|
||||
public async Task<IActionResult> DeleteLocation(string id)
|
||||
{
|
||||
var result = await this.LocationProvider.DeleteLocationAsync(id);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.ErrorMessage);
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
using DamageAssesment.Api.Locations.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DamageAssesment.Api.Locations.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class RegionsController : ControllerBase
|
||||
{
|
||||
private readonly IRegionsProvider regionProvider;
|
||||
|
||||
public RegionsController(IRegionsProvider regionProvider)
|
||||
{
|
||||
this.regionProvider = regionProvider;
|
||||
}
|
||||
|
||||
// Get all Regions
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> GetRegionsAsync()
|
||||
{
|
||||
var result = await regionProvider.GetRegionsAsync();
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.regions);
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("{Id}")]
|
||||
public async Task<ActionResult> GetRegionAsync(string Id)
|
||||
{
|
||||
var result = await this.regionProvider.GetRegionByIdAsync(Id);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.Region);
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> PostRegionAsync(Models.Region region)
|
||||
{
|
||||
var result = await this.regionProvider.PostRegionAsync(region);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.Region);
|
||||
}
|
||||
return BadRequest(result.ErrorMessage);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<ActionResult> PutRegionAsync(Models.Region region)
|
||||
{
|
||||
var result = await this.regionProvider.PutRegionAsync(region);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.Region);
|
||||
}
|
||||
if (result.ErrorMessage.Equals("Not Found"))
|
||||
return NotFound(result.ErrorMessage);
|
||||
|
||||
return BadRequest(result.ErrorMessage);
|
||||
}
|
||||
|
||||
[HttpDelete("{Id}")]
|
||||
public async Task<ActionResult> DeleteRegionAsync(string Id)
|
||||
{
|
||||
var result = await this.regionProvider.DeleteRegionAsync(Id);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.Region);
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user