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/weeklytimespans")] [ApiController] public class WeeklyTimeSpanController { private readonly WeeklyTimeSpanService _weeklytimespanService; public WeeklyTimeSpanController(WeeklyTimeSpanService weeklytimespanService) { _weeklytimespanService = weeklytimespanService; } [HttpPost] public async Task AddWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan) { try { await _weeklytimespanService.AddWeeklyTimeSpan(weeklytimespan); return true; } catch (Exception) { return false; } } [HttpDelete("{weeklyTimeSpanId}")] public bool DeleteWeeklyTimeSpan(int weeklyTimeSpanId) { try { _weeklytimespanService.DeleteWeeklyTimeSpan(weeklyTimeSpanId); return true; } catch (Exception) { return false; } } [HttpPut] public bool UpdateWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan) { try { _weeklytimespanService.UpdateWeeklyTimeSpan(weeklytimespan); return true; } catch (Exception) { return false; } } [HttpGet("date/{startTime}")] public Object GetAllWeeklyTimeSpanByStartdate(DateTime startTime) { var data = _weeklytimespanService.GetWeeklyTimeSpanByStartdate(startTime); var json = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore } ); return json; } [HttpGet] public Object GetAllWeeklyTimespans() { var data = _weeklytimespanService.GetAllWeeklyTimeSpans(); var json = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore } ); return json; } [HttpGet("{weeklytimespanId}")] public Object GetWeeklyTimeSpanById(int weeklytimespanId) { var data = _weeklytimespanService.GetWeeklyTimeSpan(weeklytimespanId); var json = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore } ); return json; } [HttpGet("pauses/{weeklytimespanId}")] public Object GetAllPausesOfTimeSpan(int weeklytimespanId) { var data = _weeklytimespanService.GetPausesOfWeeklyTimeSpan(weeklytimespanId); var json = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore } ); return json; } } }