|
|
@ -1,5 +1,6 @@
|
|
|
|
using System.Net;
|
|
|
|
using System.Net;
|
|
|
|
using DTO;
|
|
|
|
using DTO;
|
|
|
|
|
|
|
|
using Entity;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Shared;
|
|
|
|
using Shared;
|
|
|
|
|
|
|
|
|
|
|
@ -43,22 +44,59 @@ namespace WfApi.Controllers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*[HttpGet("all")]
|
|
|
|
[HttpGet("all")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
|
|
public async Task<IActionResult> GetAllSource(int index = 0, int count = 10)
|
|
|
|
public async Task<IActionResult> GetAllSource(int index = 0, int count = 10)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var result = await _source.GetSomesSource(index, count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
[HttpPost]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
public async Task<IActionResult> CreateSource([FromBody] SourceDTO newSource)
|
|
|
|
public async Task<IActionResult> CreateSource([FromBody] SourceDTO newSource)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(newSource == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return BadRequest(new { message = "Source data is required." });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var existingSource = await _source.GetSourceById(newSource.Id);
|
|
|
|
|
|
|
|
return Conflict(new { message = "A source with this ID already exists." });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(KeyNotFoundException e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await _source.AddSource(newSource);
|
|
|
|
|
|
|
|
return CreatedAtAction(nameof(GetAllSource), new { id = newSource.Id }, newSource);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPut()]
|
|
|
|
[HttpPut()]
|
|
|
@ -67,16 +105,21 @@ namespace WfApi.Controllers
|
|
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
|
|
public async Task<IActionResult> UpdateSource([FromQuery] int id, [FromBody] SourceDTO updatedSource)
|
|
|
|
public async Task<IActionResult> UpdateSource([FromQuery] int id, [FromBody] SourceDTO updatedSource)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (updatedSource == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return BadRequest(new { message = "new source data is required." });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpDelete("delete")]
|
|
|
|
var result = _source.UpdateSource(id, updatedSource);
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
|
|
|
|
|
|
public async Task<IActionResult> DeleteSource([FromQuery] int idSource)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
return Ok(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|