2021-05-03 18:15:26 +02:00
|
|
|
|
using HanyadikHetVan.Data.Entities;
|
|
|
|
|
using HanyadikHetVan.Interface;
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
[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;
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|