hanyadikhetvan-dotnethf/HanyadikHetVan/Controllers/PauseController.cs

74 lines
1.8 KiB
C#
Raw Normal View History

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