hanyadikhetvan-dotnethf/HanyadikHetVan/Controllers/PauseController.cs
Torma Kristóf 0bba2d2faf
Some checks failed
continuous-integration/drone/push Build is failing
refactor db access
2021-05-18 00:53:29 +02:00

74 lines
1.8 KiB
C#

using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
namespace HanyadikHetVan.Controllers
{
[Route("api/pauses")]
[ApiController]
public class PauseController
{
private readonly PauseService _pauseService;
public PauseController(PauseService pauseService)
{
_pauseService = pauseService;
}
[HttpPost]
public async Task<Object> AddPause([FromBody] Pause pause)
{
try
{
await _pauseService.AddPause(pause);
return true;
}
catch (Exception)
{
return false;
}
}
[HttpDelete("{pauseId}")]
public bool DeletePause(int pauseId)
{
try
{
_pauseService.DeletePause(pauseId);
return true;
}
catch (Exception)
{
return false;
}
}
[HttpPut]
public bool UpdatePause([FromBody] Pause pause)
{
try
{
_pauseService.UpdatePause(pause);
return true;
}
catch (Exception)
{
return false;
}
}
[HttpGet]
public Object GetAllPauses()
{
var data = _pauseService.GetAllPauses();
var json = JsonConvert.SerializeObject(data, Formatting.Indented,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}
);
return json;
}
}
}