76 lines
2.2 KiB
C#
76 lines
2.2 KiB
C#
using DamageAssesment.Api.Surveys.Interfaces;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace DamageAssesment.Api.Surveys.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class SurveysController : ControllerBase
|
|
{
|
|
private ISurveyProvider surveyProvider;
|
|
|
|
public SurveysController(ISurveyProvider surveyProvider)
|
|
{
|
|
this.surveyProvider = surveyProvider;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult> GetSurveysAsync()
|
|
{
|
|
var result = await this.surveyProvider.GetSurveysAsync();
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.Surveys);
|
|
}
|
|
return NoContent();
|
|
}
|
|
[HttpGet("{Id}")]
|
|
public async Task<ActionResult> GetSurveysAsync(int Id)
|
|
{
|
|
var result = await this.surveyProvider.GetSurveysAsync(Id);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.Surveys);
|
|
}
|
|
return NotFound();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<ActionResult> PostSurveysAsync(Models.Survey survey)
|
|
{
|
|
var result = await this.surveyProvider.PostSurveyAsync(survey);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.Survey);
|
|
}
|
|
return BadRequest(result.ErrorMessage);
|
|
}
|
|
|
|
[HttpPut("{Id}")]
|
|
public async Task<ActionResult> PutSurveysAsync(int Id, Models.Survey survey)
|
|
{
|
|
var result = await this.surveyProvider.PutSurveyAsync(Id,survey);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.Survey);
|
|
}
|
|
if (result.ErrorMessage == "Not Found")
|
|
return NotFound(result.ErrorMessage);
|
|
|
|
return BadRequest(result.ErrorMessage);
|
|
}
|
|
|
|
[HttpDelete("{Id}")]
|
|
public async Task<ActionResult> DeleteSurveysAsync(int Id)
|
|
{
|
|
var result = await this.surveyProvider.DeleteSurveyAsync(Id);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.Survey);
|
|
}
|
|
return NotFound();
|
|
}
|
|
}
|
|
}
|