add previous functionality

This commit is contained in:
Torma Kristóf 2021-05-03 15:56:38 +02:00
parent a0ce1669ae
commit 67dafc1150
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
8 changed files with 105 additions and 17 deletions

View File

@ -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();
}
}
}

View File

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

View File

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

View File

@ -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())

View File

@ -0,0 +1,23 @@
using HanyadikHetVan.DTO;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace HanyadikHetVan.Services
{
public class HanyadikHetVanJsonService
{
private readonly ILogger<HanyadikHetVanJsonService> _logger;
private IConfiguration _configuration;
public HanyadikHetVanJsonService(ILogger<HanyadikHetVanJsonService> logger, IConfiguration configuration)
{
_configuration = configuration;
_logger = logger;
}
public HanyadikHetVanDTO HanyadikHetVan()
{
return new HanyadikHetVanDTO(_configuration["HanyadikHetVan:StartDate"]);
}
}
}

View File

@ -0,0 +1,23 @@
using HanyadikHetVan.DTO;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace HanyadikHetVan.Services
{
public class HanyadikHetVanService
{
private readonly ILogger<HanyadikHetVanService> _logger;
private IConfiguration _configuration;
public HanyadikHetVanService(ILogger<HanyadikHetVanService> logger, IConfiguration configuration)
{
_configuration = configuration;
_logger = logger;
}
public int HanyadikHetVan()
{
return new HanyadikHetVanDTO(_configuration["HanyadikHetVan:StartDate"]).HanyadikHet;
}
}
}

View File

@ -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<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddTransient<HanyadikHetVanJsonService>();
services.AddTransient<HanyadikHetVanService>();
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();

View File

@ -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",