From 67dafc115010a642424dbf163b46c29b8443907e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 3 May 2021 15:56:38 +0200 Subject: [PATCH] add previous functionality --- .../Controllers/HanyadikHetVanController.cs | 35 +++++++++++++++++++ HanyadikHetVan/Controllers/TestController.cs | 8 ++--- HanyadikHetVan/DTO/HanyadikHetVanDTO.cs | 16 +++++++++ HanyadikHetVan/Program.cs | 4 --- .../Services/HanyadikHetVanJsonService.cs | 23 ++++++++++++ .../Services/HanyadikHetVanService .cs | 23 ++++++++++++ HanyadikHetVan/Startup.cs | 10 ++---- HanyadikHetVan/appsettings.json | 3 ++ 8 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 HanyadikHetVan/Controllers/HanyadikHetVanController.cs create mode 100644 HanyadikHetVan/DTO/HanyadikHetVanDTO.cs create mode 100644 HanyadikHetVan/Services/HanyadikHetVanJsonService.cs create mode 100644 HanyadikHetVan/Services/HanyadikHetVanService .cs diff --git a/HanyadikHetVan/Controllers/HanyadikHetVanController.cs b/HanyadikHetVan/Controllers/HanyadikHetVanController.cs new file mode 100644 index 0000000..ab95a28 --- /dev/null +++ b/HanyadikHetVan/Controllers/HanyadikHetVanController.cs @@ -0,0 +1,35 @@ +using HanyadikHetVan.DTO; +using HanyadikHetVan.Services; +using Microsoft.AspNetCore.Mvc; + +namespace HanyadikHetVan.Controllers +{ + [ApiController] + [Route("api/hanyadikhetvan")] + public class HanyadikHetVanController : ControllerBase + { + + private readonly HanyadikHetVanJsonService _jsonservice; + private readonly HanyadikHetVanService _service; + + + public HanyadikHetVanController(HanyadikHetVanJsonService jsonservice, HanyadikHetVanService service) + { + _jsonservice = jsonservice; + _service = service; + } + + [HttpGet] + [Consumes("application/json")] + public HanyadikHetVanDTO GetJson() + { + return _jsonservice.HanyadikHetVan(); + } + + [HttpGet] + public int Get() + { + return _service.HanyadikHetVan(); + } + } +} diff --git a/HanyadikHetVan/Controllers/TestController.cs b/HanyadikHetVan/Controllers/TestController.cs index 05fe95f..f62c482 100644 --- a/HanyadikHetVan/Controllers/TestController.cs +++ b/HanyadikHetVan/Controllers/TestController.cs @@ -1,9 +1,5 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace HanyadikHetVan.Controllers { @@ -15,7 +11,7 @@ namespace HanyadikHetVan.Controllers public string Unprotected() { - return "Geci"; + return "Unprotected"; } [Authorize] @@ -23,7 +19,7 @@ namespace HanyadikHetVan.Controllers public string Protected() { - return "Gecijo"; + return "Protected"; } } } diff --git a/HanyadikHetVan/DTO/HanyadikHetVanDTO.cs b/HanyadikHetVan/DTO/HanyadikHetVanDTO.cs new file mode 100644 index 0000000..8bebe9f --- /dev/null +++ b/HanyadikHetVan/DTO/HanyadikHetVanDTO.cs @@ -0,0 +1,16 @@ +using System; + +namespace HanyadikHetVan.DTO +{ + public class HanyadikHetVanDTO + { + private readonly DateTime startdate; + + public HanyadikHetVanDTO(string startdate) + { + this.startdate = DateTime.Parse(startdate); + } + + public int HanyadikHet => (DateTime.Now - startdate).Days / 7; + } +} diff --git a/HanyadikHetVan/Program.cs b/HanyadikHetVan/Program.cs index 66d3c66..c24d010 100644 --- a/HanyadikHetVan/Program.cs +++ b/HanyadikHetVan/Program.cs @@ -12,10 +12,6 @@ namespace HanyadikHetVan { public static async Task Main(string[] args) { - var secret = new Secret("cunci".Sha256()); - System.Console.WriteLine(secret.Value); - - var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) diff --git a/HanyadikHetVan/Services/HanyadikHetVanJsonService.cs b/HanyadikHetVan/Services/HanyadikHetVanJsonService.cs new file mode 100644 index 0000000..8a9d91c --- /dev/null +++ b/HanyadikHetVan/Services/HanyadikHetVanJsonService.cs @@ -0,0 +1,23 @@ +using HanyadikHetVan.DTO; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace HanyadikHetVan.Services +{ + public class HanyadikHetVanJsonService + { + private readonly ILogger _logger; + private IConfiguration _configuration; + + public HanyadikHetVanJsonService(ILogger logger, IConfiguration configuration) + { + _configuration = configuration; + _logger = logger; + } + + public HanyadikHetVanDTO HanyadikHetVan() + { + return new HanyadikHetVanDTO(_configuration["HanyadikHetVan:StartDate"]); + } + } +} diff --git a/HanyadikHetVan/Services/HanyadikHetVanService .cs b/HanyadikHetVan/Services/HanyadikHetVanService .cs new file mode 100644 index 0000000..37394e2 --- /dev/null +++ b/HanyadikHetVan/Services/HanyadikHetVanService .cs @@ -0,0 +1,23 @@ +using HanyadikHetVan.DTO; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace HanyadikHetVan.Services +{ + public class HanyadikHetVanService + { + private readonly ILogger _logger; + private IConfiguration _configuration; + + public HanyadikHetVanService(ILogger logger, IConfiguration configuration) + { + _configuration = configuration; + _logger = logger; + } + + public int HanyadikHetVan() + { + return new HanyadikHetVanDTO(_configuration["HanyadikHetVan:StartDate"]).HanyadikHet; + } + } +} diff --git a/HanyadikHetVan/Startup.cs b/HanyadikHetVan/Startup.cs index b29d5aa..a890d96 100644 --- a/HanyadikHetVan/Startup.cs +++ b/HanyadikHetVan/Startup.cs @@ -1,18 +1,13 @@ using HanyadikHetVan.Data; +using HanyadikHetVan.Services; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.UI; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace HanyadikHetVan { @@ -31,7 +26,8 @@ namespace HanyadikHetVan services.AddDbContext(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); - + services.AddTransient(); + services.AddTransient(); services.AddDatabaseDeveloperPageExceptionFilter(); services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores(); diff --git a/HanyadikHetVan/appsettings.json b/HanyadikHetVan/appsettings.json index 1febc65..68fffd4 100644 --- a/HanyadikHetVan/appsettings.json +++ b/HanyadikHetVan/appsettings.json @@ -2,6 +2,9 @@ "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-HanyadikHetVan-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true" }, + "HanyadikHetVan": { + "StartDate": "2021-02-01" + }, "Logging": { "LogLevel": { "Default": "Information",