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; public PauseController(IRepository pause, PauseService pauseService) { _pauseService = pauseService; _pause = pause; } [HttpPost] public async Task 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; } } }