add controllers for crud

This commit is contained in:
Torma Kristóf 2021-05-03 18:36:26 +02:00
parent 1d61c35126
commit bd788697c7
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
2 changed files with 130 additions and 0 deletions

View File

@ -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<Object> 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;
}
}
}

View File

@ -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<Object> 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;
}
}
}