74 lines
1.8 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|