hanyadikhetvan-dotnethf/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs

110 lines
3.5 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/weeklytimespans")]
2021-05-03 18:15:26 +02:00
[ApiController]
public class WeeklyTimeSpanController
{
private readonly WeeklyTimeSpanService _weeklytimespanService;
2021-05-18 00:53:29 +02:00
public WeeklyTimeSpanController(WeeklyTimeSpanService weeklytimespanService)
2021-05-03 18:15:26 +02:00
{
_weeklytimespanService = weeklytimespanService;
}
2021-05-03 18:36:26 +02:00
[HttpPost]
public async Task<Object> AddWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan)
{
try
{
await _weeklytimespanService.AddWeeklyTimeSpan(weeklytimespan);
return true;
}
catch (Exception)
{
return false;
}
}
2021-05-17 22:53:27 +02:00
[HttpDelete("{weeklyTimeSpanId}")]
2021-05-03 18:36:26 +02:00
public bool DeleteWeeklyTimeSpan(int weeklyTimeSpanId)
{
try
{
_weeklytimespanService.DeleteWeeklyTimeSpan(weeklyTimeSpanId);
return true;
}
catch (Exception)
{
return false;
}
}
[HttpPut]
2021-05-17 22:53:27 +02:00
public bool UpdateWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan)
2021-05-03 18:36:26 +02:00
{
try
{
2021-05-17 22:53:27 +02:00
_weeklytimespanService.UpdateWeeklyTimeSpan(weeklytimespan);
2021-05-03 18:36:26 +02:00
return true;
}
catch (Exception)
{
return false;
}
}
2021-05-18 00:53:29 +02:00
[HttpGet("date/{startTime}")]
2021-05-17 22:53:27 +02:00
public Object GetAllWeeklyTimeSpanByStartdate(DateTime startTime)
2021-05-03 18:36:26 +02:00
{
2021-05-17 22:53:27 +02:00
var data = _weeklytimespanService.GetWeeklyTimeSpanByStartdate(startTime);
2021-05-03 18:36:26 +02:00
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;
}
[HttpGet]
public Object GetAllWeeklyTimespans()
{
var data = _weeklytimespanService.GetAllWeeklyTimeSpans();
var json = JsonConvert.SerializeObject(data, Formatting.Indented,
new JsonSerializerSettings()
{
2021-05-17 22:53:27 +02:00
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}
);
return json;
}
[HttpGet("{weeklytimespanId}")]
2021-05-18 00:53:29 +02:00
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}")]
2021-05-17 22:53:27 +02:00
public Object GetAllPausesOfTimeSpan(int weeklytimespanId)
{
var data = _weeklytimespanService.GetPausesOfWeeklyTimeSpan(weeklytimespanId);
var json = JsonConvert.SerializeObject(data, Formatting.Indented,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
2021-05-03 18:36:26 +02:00
}
);
return json;
}
2021-05-03 18:15:26 +02:00
}
}