Modernized
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.0.78" />
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.2" />
|
||||
<PackageReference Include="Dapper" Version="2.1.72" />
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
@@ -1,46 +1,39 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace CPATapi.Server.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
public class AvailabilityController : ControllerBase
|
||||
public class AvailabilityController(IConfiguration config) : ControllerBase
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
public AvailabilityController(IConfiguration config) => _config = config;
|
||||
|
||||
[HttpGet, Route("users")]
|
||||
public async Task<IEnumerable<string>> GetUsers()
|
||||
{
|
||||
await using var con = new SqlConnection(_config["Db:ConnectionStringZc"]);
|
||||
await using var con = new SqlConnection(config["Db:ConnectionStringZc"]);
|
||||
await con.OpenAsync();
|
||||
return await con.QueryAsync<string>(@"
|
||||
SELECT DISTINCT MA_USER_NAME
|
||||
FROM dbo.MA_DATEN
|
||||
WHERE MA_USER_NAME IS NOT NULL AND MA_USER_AKTIV = 1
|
||||
ORDER BY MA_USER_NAME");
|
||||
return await con.QueryAsync<string>("""
|
||||
SELECT DISTINCT MA_USER_NAME
|
||||
FROM dbo.MA_DATEN
|
||||
WHERE MA_USER_NAME IS NOT NULL AND MA_USER_AKTIV = 1
|
||||
ORDER BY MA_USER_NAME
|
||||
""");
|
||||
}
|
||||
|
||||
[HttpGet, Route("{user}")]
|
||||
public async Task<object> GetAvailability(string user)
|
||||
{
|
||||
await using var con = new SqlConnection(_config["Db:ConnectionStringZc"]);
|
||||
await using var con = new SqlConnection(config["Db:ConnectionStringZc"]);
|
||||
await con.OpenAsync();
|
||||
var stampCount = (await con.QueryAsync(@"
|
||||
SELECT *
|
||||
FROM dbo.BU
|
||||
INNER JOIN dbo.MA_DATEN on MA_NR = BU_MA_NR
|
||||
WHERE
|
||||
MA_USER_NAME = @user AND
|
||||
BU_BU >= @date AND BU_BU < @tomorrow", new { user, date = DateTime.Now.Date, tomorrow = DateTime.Now.AddDays(1).Date })).Count();
|
||||
var stampCount = (await con.QueryAsync("""
|
||||
SELECT *
|
||||
FROM dbo.BU
|
||||
INNER JOIN dbo.MA_DATEN on MA_NR = BU_MA_NR
|
||||
WHERE
|
||||
MA_USER_NAME = @user AND
|
||||
BU_BU >= @date AND BU_BU < @tomorrow
|
||||
""", new { user, date = DateTime.Now.Date, tomorrow = DateTime.Now.AddDays(1).Date })).Count();
|
||||
return new { user, loggedIn = stampCount % 2 != 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
using System.Threading.Tasks;
|
||||
using CPATapi.Server.Models;
|
||||
using Dapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace CPATapi.Server.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
public class CallerIdController : ControllerBase
|
||||
public class CallerIdController(IConfiguration config) : ControllerBase
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
public CallerIdController(IConfiguration config) => _config = config;
|
||||
|
||||
|
||||
[HttpGet, Route("{number}")]
|
||||
public async Task<TapiContact> CallerIdAsync([FromRoute] string number)
|
||||
{
|
||||
@@ -24,18 +18,19 @@ namespace CPATapi.Server.Controllers
|
||||
number = "%" + minMatch;
|
||||
}
|
||||
|
||||
await using var con = new SqlConnection(_config["Db:ConnectionString"]);
|
||||
await using var con = new SqlConnection(config["Db:ConnectionString"]);
|
||||
await con.OpenAsync();
|
||||
|
||||
var result = await con.QueryFirstOrDefaultAsync<TapiContact>(@"
|
||||
SELECT
|
||||
TD_ID,
|
||||
TD_NAME,
|
||||
TD_NUMBER,
|
||||
TD_NUMBER_TAPI,
|
||||
TD_MEDIUM
|
||||
FROM dbo.CP_TAPI_DIRECTORY
|
||||
WHERE TD_NUMBER_TAPI LIKE @number", new {number});
|
||||
var result = await con.QueryFirstOrDefaultAsync<TapiContact>("""
|
||||
SELECT
|
||||
TD_ID,
|
||||
TD_NAME,
|
||||
TD_NUMBER,
|
||||
TD_NUMBER_TAPI,
|
||||
TD_MEDIUM
|
||||
FROM dbo.CP_TAPI_DIRECTORY
|
||||
WHERE TD_NUMBER_TAPI LIKE @number
|
||||
""", new {number});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CPATapi.Server.Models;
|
||||
using Dapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CPATapi.Server.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class ContactController : ControllerBase
|
||||
public class ContactController(ILogger<ContactController> logger, IConfiguration config) : ControllerBase
|
||||
{
|
||||
|
||||
private readonly ILogger<ContactController> _logger;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public ContactController(ILogger<ContactController> logger, IConfiguration config)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
}
|
||||
private readonly ILogger<ContactController> _logger = logger;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IEnumerable<TapiContact>> GetAsync()
|
||||
{
|
||||
await using var con = new SqlConnection(_config["Db:ConnectionString"]);
|
||||
await using var con = new SqlConnection(config["Db:ConnectionString"]);
|
||||
await con.OpenAsync();
|
||||
|
||||
var contacts = await con.QueryAsync<TapiContact>(@"
|
||||
SELECT
|
||||
TD_ID,
|
||||
TD_NAME,
|
||||
TD_NUMBER,
|
||||
TD_NUMBER_TAPI,
|
||||
TD_MEDIUM
|
||||
FROM dbo.CP_TAPI_DIRECTORY");
|
||||
var contacts = await con.QueryAsync<TapiContact>("""
|
||||
SELECT
|
||||
TD_ID,
|
||||
TD_NAME,
|
||||
TD_NUMBER,
|
||||
TD_NUMBER_TAPI,
|
||||
TD_MEDIUM
|
||||
FROM dbo.CP_TAPI_DIRECTORY
|
||||
""");
|
||||
return contacts;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using CPATapi.Server.Models;
|
||||
using Dapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace CPATapi.Server.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
public class SearchController : ControllerBase
|
||||
public class SearchController(IConfiguration config) : ControllerBase
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
public SearchController(IConfiguration config) => _config = config;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IEnumerable<TapiContact>> SearchAsync([FromQuery] string query)
|
||||
{
|
||||
@@ -33,17 +26,18 @@ namespace CPATapi.Server.Controllers
|
||||
return new List<TapiContact>();
|
||||
}
|
||||
|
||||
await using var con = new SqlConnection(_config["Db:ConnectionString"]);
|
||||
await using var con = new SqlConnection(config["Db:ConnectionString"]);
|
||||
await con.OpenAsync();
|
||||
var sql = new StringBuilder(@"
|
||||
SELECT TOP 10
|
||||
TD_ID,
|
||||
TD_NAME,
|
||||
TD_NUMBER,
|
||||
TD_NUMBER_TAPI,
|
||||
TD_MEDIUM
|
||||
FROM dbo.CP_TAPI_DIRECTORY
|
||||
WHERE ");
|
||||
var sql = new StringBuilder("""
|
||||
SELECT TOP 10
|
||||
TD_ID,
|
||||
TD_NAME,
|
||||
TD_NUMBER,
|
||||
TD_NUMBER_TAPI,
|
||||
TD_MEDIUM
|
||||
FROM dbo.CP_TAPI_DIRECTORY
|
||||
WHERE
|
||||
""");
|
||||
var first = true;
|
||||
var dp = new DynamicParameters();
|
||||
for (var i = 1; i <= args.Length; i++)
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
namespace CPATapi.Server
|
||||
builder.Services.AddControllers();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
}
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace CPATapi.Server
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services
|
||||
.AddControllers();
|
||||
//.AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
//app.UseHttpsRedirection();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user