hanyadikhetvan-dotnethf/HanyadikHetVan/Controllers/PauseController.cs
Torma Kristóf 4b993aa4e8
Some checks failed
continuous-integration/drone/push Build is failing
asd
2021-05-17 22:53:27 +02:00

78 lines
1.9 KiB
C#

using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Interface;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
namespace HanyadikHetVan.Controllers
{
[Route("api/pause")]
[ApiController]
public class PauseController
{
private readonly PauseService _pauseService;
private readonly IRepository<Pause> _pause;
public PauseController(IRepository<Pause> pause, PauseService pauseService)
{
_pauseService = pauseService;
_pause = pause;
}
[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;
}
}
}