added a notes file for important running stuff

Create working for tenant and added in efcore and data layer
This commit is contained in:
2026-04-02 09:05:53 +10:30
parent ad107753b5
commit 4ee8b9101d
22 changed files with 415 additions and 26 deletions
@@ -11,6 +11,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Emergence.data\Emergence.data.csproj" />
<ProjectReference Include="..\Emergence.models\Emergence.models.csproj" />
</ItemGroup>
@@ -1,19 +1,19 @@
using Emergence.services.Interface;
using Emergence.data.Extensions;
using Emergence.services.Interface;
using Emergence.services.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.IdentityModel.Protocols;
namespace Emergence.services.Extensions
namespace Emergence.services.Extensions;
public static class ServiceBuilderExtension
{
public static class ServiceBuilderExtension
public static IServiceCollection AddEmergenceServices(this IServiceCollection services, IConfigurationManager configuration)
{
public static IServiceCollection AddEmergenceServices(this IServiceCollection services)
{
services = services.AddTransient<ITenantService, TenantService>();
services.AddDataServices(configuration);
services = services.AddTransient<ITenantService, TenantService>();
return services;
}
return services;
}
}
@@ -8,5 +8,7 @@ namespace Emergence.services.Interface
{
public Task<IEnumerable<T>> GetAllAsync();
public Task<T> GetByIdAsync(I id);
public Task<T> CreateAsync(T tenant);
}
}
+55 -11
View File
@@ -1,29 +1,73 @@
using Emergence.models;
using Emergence.data.Contexts;
using Emergence.data.Models;
using Emergence.models;
using Emergence.services.Interface;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text;
namespace Emergence.services.Services;
public static class TenantExtension
{
public static TenantModel ConvertToTenantModel(this Tenant tenant)
{
TenantModel model = new TenantModel
{
Id = tenant.Id,
TenantCode = tenant.TenantCode,
CompanyName = tenant.CompanyName,
IsInactive = tenant.IsInactive,
};
return model;
}
public static Tenant ConvertToTenant(this TenantModel tenant)
{
Tenant model = new Tenant
{
Id = tenant.Id.HasValue ? tenant.Id.Value : Guid.NewGuid(),
TenantCode = tenant.TenantCode,
CompanyName = tenant.CompanyName,
IsInactive = tenant.IsInactive,
};
return model;
}
}
public class TenantService : ITenantService
{
private List<TenantModel> testList = [
new TenantModel {Id = Guid.NewGuid(), TenantCode = "FJP", CompanyName = "Fred J Potter", IsInactive = false },
new TenantModel {Id = Guid.NewGuid(), TenantCode = "JAZZ", CompanyName = "Jazzbond", IsInactive = false },
new TenantModel {Id = Guid.NewGuid(), TenantCode = "TDT", CompanyName = "The Digital Tailor", IsInactive = false },
new TenantModel {Id = Guid.NewGuid(), TenantCode = "HBAS", CompanyName = "Hicks Building and Asbestos Services", IsInactive = false },
];
private readonly AdminDbContext _dbContext;
public TenantService(AdminDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task<IEnumerable<TenantModel>> GetAllAsync()
{
return testList;
return _dbContext.Tenant.Select(s => s.ConvertToTenantModel());
}
public async Task<TenantModel> GetByIdAsync(Guid id)
{
#pragma warning disable CS8603 // Possible null reference return.
return testList.FirstOrDefault(f => f.Id == id);
#pragma warning restore CS8603 // Possible null reference return.
var entity = _dbContext.Tenant.Where(f => f.Id == id)?.Select(s => s.ConvertToTenantModel()).FirstOrDefault();
return entity;
}
public async Task<TenantModel> CreateAsync(TenantModel model)
{
if (model.Id == Guid.Empty || model.Id == null)
model.Id = Guid.NewGuid();
Tenant newTenant = model.ConvertToTenant();
try
{
_dbContext.Tenant.Add(newTenant);
await _dbContext.SaveChangesAsync();
return model;
}
catch (DbException ex)
{
return null;
}
}
}