diff --git a/HanyadikHetVan/Controllers/PauseController.cs b/HanyadikHetVan/Controllers/PauseController.cs new file mode 100644 index 0000000..cd4270d --- /dev/null +++ b/HanyadikHetVan/Controllers/PauseController.cs @@ -0,0 +1,26 @@ +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.Interface; +using HanyadikHetVan.Services; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +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; + } + } +} diff --git a/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs b/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs new file mode 100644 index 0000000..d621080 --- /dev/null +++ b/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs @@ -0,0 +1,26 @@ +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.Interface; +using HanyadikHetVan.Services; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Controllers +{ + [Route("api/weeklytimespan")] + [ApiController] + public class WeeklyTimeSpanController + { + private readonly WeeklyTimeSpanService _weeklytimespanService; + + private readonly IRepository _weeklytimespan; + + public WeeklyTimeSpanController(IRepository weeklytimespan, WeeklyTimeSpanService weeklytimespanService) + { + _weeklytimespanService = weeklytimespanService; + _weeklytimespan = weeklytimespan; + } + } +} diff --git a/HanyadikHetVan/HanyadikHetVan.csproj b/HanyadikHetVan/HanyadikHetVan.csproj index a4fa2af..679145a 100644 --- a/HanyadikHetVan/HanyadikHetVan.csproj +++ b/HanyadikHetVan/HanyadikHetVan.csproj @@ -15,6 +15,10 @@ + + + + diff --git a/HanyadikHetVan/Interface/IRepository.cs b/HanyadikHetVan/Interface/IRepository.cs index fc45c14..545d485 100644 --- a/HanyadikHetVan/Interface/IRepository.cs +++ b/HanyadikHetVan/Interface/IRepository.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using System.Threading.Tasks; namespace HanyadikHetVan.Interface diff --git a/HanyadikHetVan/Services/PauseService.cs b/HanyadikHetVan/Services/PauseService.cs new file mode 100644 index 0000000..8ba0d18 --- /dev/null +++ b/HanyadikHetVan/Services/PauseService.cs @@ -0,0 +1,60 @@ +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Services +{ + public class PauseService + { + private readonly IRepository _pause; + + public PauseService(IRepository pause) + { + _pause = pause ?? throw new ArgumentNullException(nameof(pause)); + } + + public IEnumerable GetAllPauses() + { + return _pause.GetAll().ToList(); + } + + public async Task AddPause(Pause pause) + { + return await _pause.Create(pause); + } + + public bool DeletePause(int pauseId) + { + try + { + var item = _pause.GetAll().Where(x => x.Id == pauseId).FirstOrDefault(); + _pause.Delete(item); + return true; + } + catch (Exception) + { + return false; + } + } + + public bool UpdatePause(Pause pause) + { + try + { + var DataList = _pause.GetAll().ToList(); + foreach (var item in DataList) + { + _pause.Update(item); + } + return true; + } + catch (Exception) + { + return true; + } + } + } +} diff --git a/HanyadikHetVan/Services/WeeklyTimeSpanService.cs b/HanyadikHetVan/Services/WeeklyTimeSpanService.cs new file mode 100644 index 0000000..07e977d --- /dev/null +++ b/HanyadikHetVan/Services/WeeklyTimeSpanService.cs @@ -0,0 +1,60 @@ +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Services +{ + public class WeeklyTimeSpanService + { + private readonly IRepository _weeklytimespan; + + public WeeklyTimeSpanService(IRepository weeklytimespan) + { + _weeklytimespan = weeklytimespan ?? throw new ArgumentNullException(nameof(weeklytimespan)); + } + + public IEnumerable GetAllWeeklyTimeSpans() + { + return _weeklytimespan.GetAll().ToList(); + } + + public async Task AddWeeklyTimeSpan(WeeklyTimeSpan weeklytimespan) + { + return await _weeklytimespan.Create(weeklytimespan); + } + + public bool DeleteWeeklyTimeSpan(int weeklytimespanId) + { + try + { + var item = _weeklytimespan.GetAll().Where(x => x.Id == weeklytimespanId).FirstOrDefault(); + _weeklytimespan.Delete(item); + return true; + } + catch (Exception) + { + return false; + } + } + + public bool UpdateWeeklyTimeSpan(WeeklyTimeSpan weeklytimespan) + { + try + { + var DataList = _weeklytimespan.GetAll().ToList(); + foreach (var item in DataList) + { + _weeklytimespan.Update(item); + } + return true; + } + catch (Exception) + { + return true; + } + } + } +} diff --git a/HanyadikHetVan/Startup.cs b/HanyadikHetVan/Startup.cs index a890d96..1d05e8a 100644 --- a/HanyadikHetVan/Startup.cs +++ b/HanyadikHetVan/Startup.cs @@ -1,4 +1,7 @@ using HanyadikHetVan.Data; +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.Interface; +using HanyadikHetVan.Repository; using HanyadikHetVan.Services; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; @@ -8,6 +11,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.OpenApi.Models; namespace HanyadikHetVan { @@ -26,6 +30,10 @@ namespace HanyadikHetVan services.AddDbContext(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); + services.AddTransient, PauseRepository>(); + services.AddTransient, WeeklyTimeSpanRepository>(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddDatabaseDeveloperPageExceptionFilter(); @@ -61,6 +69,11 @@ namespace HanyadikHetVan services.AddRazorPages(); services.AddControllers(); + + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hanyadik Het Van API", Version = "v1" }); + }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -70,6 +83,8 @@ namespace HanyadikHetVan { app.UseDeveloperExceptionPage(); app.UseMigrationsEndPoint(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "HanyadikHetVan v1")); } else {