Use file-scoped namespaces

This commit is contained in:
Andriy
2023-07-29 15:14:52 +03:00
parent a24332370d
commit 8ab067a027
58 changed files with 2222 additions and 2280 deletions
+28 -29
View File
@@ -2,40 +2,39 @@
using BotFramework;
using Microsoft.EntityFrameworkCore;
namespace Kruzya.TelegramBot.Core
namespace Kruzya.TelegramBot.Core;
/// <summary>
/// Resolves the GUIDs from database to entities.
/// </summary>
/// <typeparam name="TResolvedEntity">Entity type</typeparam>
/// <typeparam name="TAppContext">Database context where entity should be finded</typeparam>
public class DbResolverParameter<TResolvedEntity, TAppContext> : IParameterParser<TResolvedEntity>
where TAppContext : DbContext
where TResolvedEntity : class
{
/// <summary>
/// Resolves the GUIDs from database to entities.
/// </summary>
/// <typeparam name="TResolvedEntity">Entity type</typeparam>
/// <typeparam name="TAppContext">Database context where entity should be finded</typeparam>
public class DbResolverParameter<TResolvedEntity, TAppContext> : IParameterParser<TResolvedEntity>
where TAppContext : DbContext
where TResolvedEntity : class
private TAppContext _dbContext;
public DbResolverParameter(TAppContext dbContext)
{
private TAppContext _dbContext;
public DbResolverParameter(TAppContext dbContext)
{
_dbContext = dbContext;
}
_dbContext = dbContext;
}
public TResolvedEntity DefaultInstance()
public TResolvedEntity DefaultInstance()
{
return default(TResolvedEntity);
}
public bool TryGetValue(string text, out TResolvedEntity result)
{
result = null;
Guid id;
if (Guid.TryParse(text, out id))
{
return default(TResolvedEntity);
result = _dbContext.Find<TResolvedEntity>(id);
return (result != null);
}
public bool TryGetValue(string text, out TResolvedEntity result)
{
result = null;
Guid id;
if (Guid.TryParse(text, out id))
{
result = _dbContext.Find<TResolvedEntity>(id);
return (result != null);
}
return false;
}
return false;
}
}