From bd788697c71c340c99d1f37affc304115339f857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 3 May 2021 18:36:26 +0200 Subject: [PATCH] add controllers for crud --- HanyadikHetVan/Controllers/PauseController.cs | 65 +++++++++++++++++++ .../Controllers/WeeklyTimeSpanController.cs | 65 +++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/HanyadikHetVan/Controllers/PauseController.cs b/HanyadikHetVan/Controllers/PauseController.cs index cd4270d..3585199 100644 --- a/HanyadikHetVan/Controllers/PauseController.cs +++ b/HanyadikHetVan/Controllers/PauseController.cs @@ -2,6 +2,7 @@ using HanyadikHetVan.Interface; using HanyadikHetVan.Services; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; @@ -22,5 +23,69 @@ namespace HanyadikHetVan.Controllers _pauseService = pauseService; _pause = pause; } + [HttpPost] + public async Task AddPause([FromBody] Pause weeklytimespan) + { + try + { + await _pauseService.AddPause(weeklytimespan); + return true; + } + catch (Exception) + { + + return false; + } + } + [HttpDelete] + public bool DeletePause(int weeklyTimeSpanId) + { + try + { + _pauseService.DeletePause(weeklyTimeSpanId); + return true; + } + catch (Exception) + { + return false; + } + } + [HttpPut] + public bool UpdatePause(Pause Object) + { + try + { + _pauseService.UpdatePause(Object); + return true; + } + catch (Exception) + { + return false; + } + } + [HttpGet] + public Object GetAllPauses(DateTime UserEmail) + { + var data = _pauseService.GetPersonByUserName(UserEmail); + var json = JsonConvert.SerializeObject(data, Formatting.Indented, + new JsonSerializerSettings() + { + ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore + } + ); + return json; + } + [HttpGet] + public Object GetAllPauses() + { + var data = _pauseService.GetAllPauses(); + var json = JsonConvert.SerializeObject(data, Formatting.Indented, + new JsonSerializerSettings() + { + ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore + } + ); + return json; + } } } diff --git a/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs b/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs index d621080..faf83a4 100644 --- a/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs +++ b/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs @@ -2,6 +2,7 @@ using HanyadikHetVan.Interface; using HanyadikHetVan.Services; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; @@ -22,5 +23,69 @@ namespace HanyadikHetVan.Controllers _weeklytimespanService = weeklytimespanService; _weeklytimespan = weeklytimespan; } + [HttpPost] + public async Task AddWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan) + { + try + { + await _weeklytimespanService.AddWeeklyTimeSpan(weeklytimespan); + return true; + } + catch (Exception) + { + + return false; + } + } + [HttpDelete] + public bool DeleteWeeklyTimeSpan(int weeklyTimeSpanId) + { + try + { + _weeklytimespanService.DeleteWeeklyTimeSpan(weeklyTimeSpanId); + return true; + } + catch (Exception) + { + return false; + } + } + [HttpPut] + public bool UpdateWeeklyTimeSpan(WeeklyTimeSpan Object) + { + try + { + _weeklytimespanService.UpdateWeeklyTimeSpan(Object); + return true; + } + catch (Exception) + { + return false; + } + } + [HttpGet] + public Object GetAllWeeklyTimeSpanByStartdate(DateTime UserEmail) + { + var data = _weeklytimespanService.GetPersonByUserName(UserEmail); + var json = JsonConvert.SerializeObject(data, Formatting.Indented, + new JsonSerializerSettings() + { + ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore + } + ); + return json; + } + [HttpGet] + public Object GetAllWeeklyTimespans() + { + var data = _weeklytimespanService.GetAllWeeklyTimeSpans(); + var json = JsonConvert.SerializeObject(data, Formatting.Indented, + new JsonSerializerSettings() + { + ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore + } + ); + return json; + } } }