Supporting 'friendly constructors'
This commit is contained in:
parent
b13a5ac392
commit
0d410211c8
|
@ -20,9 +20,13 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BlueWest.Data\BlueWest.Data.csproj" />
|
||||
<ProjectReference Include="..\BlueWest.Data.Capital\BlueWest.Data.Capital.csproj" />
|
||||
<ProjectReference Include="..\BlueWest\BlueWest.csproj" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Repositories" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
using BlueWest.Data;
|
||||
using BlueWest.WebApi.EF.Model;
|
||||
using MapTo;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BlueWest.WebApi.EF
|
||||
{
|
||||
internal sealed class CompanyDbContext : DbContext
|
||||
{
|
||||
public DbSet<Company> Companies { get; set; }
|
||||
|
||||
public DbSet<Industry> Industries { get; set; }
|
||||
|
||||
public DbSet<Product> Products { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Options to be injected in the app
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public CompanyDbContext(DbContextOptions<CompanyDbContext> options) : base(options)
|
||||
{
|
||||
Database.EnsureCreated();
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
modelBuilder.ConfigureCurrentDbModel();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
using BlueWest.Data;
|
||||
using BlueWest.WebApi.MySQL.Model;
|
||||
using BlueWest.WebApi.EF.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace BlueWest.WebApi.MySQL
|
||||
namespace BlueWest.WebApi.EF
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Countries and Currencies
|
||||
/// </summary>
|
||||
public sealed class CountryDbContext : DbContext
|
||||
internal sealed class CountryDbContext : DbContext
|
||||
{
|
||||
|
||||
public DbSet<Country> Countries { get; set; }
|
||||
|
@ -26,7 +26,6 @@ namespace BlueWest.WebApi.MySQL
|
|||
public CountryDbContext(DbContextOptions<CountryDbContext> options) : base(options)
|
||||
{
|
||||
Database.EnsureCreated();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -39,5 +38,6 @@ namespace BlueWest.WebApi.MySQL
|
|||
base.OnModelCreating(modelBuilder);
|
||||
modelBuilder.ConfigureCurrentDbModel();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using BlueWest.Tools;
|
||||
using BlueWest.WebApi.MySQL;
|
||||
using BlueWest.WebApi.EF;
|
||||
|
||||
namespace BlueWest.WebApi.Interfaces
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ namespace BlueWest.WebApi.Interfaces
|
|||
/// Interface for getting and storing exchange rates data
|
||||
/// </summary>
|
||||
///
|
||||
public sealed class ExchangeInterface : EventListener<ExchangeEvent>, IDisposable, IAsyncDisposable
|
||||
internal sealed class ExchangeInterface : EventListener<ExchangeEvent>, IDisposable, IAsyncDisposable
|
||||
{
|
||||
private readonly EventManager _eventManager;
|
||||
private readonly CountryDbContext _countryDbContext;
|
|
@ -0,0 +1,61 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BlueWest.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BlueWest.WebApi.EF
|
||||
{
|
||||
internal static class CountryDbExtensions
|
||||
{
|
||||
|
||||
internal static Country GetCountryById(this DbSet<Country> countries, int countryId) => countries.GetOne(x => x.Id == countryId);
|
||||
internal static (bool, T) NotFound<T>() where T : class => (false, null);
|
||||
|
||||
internal static (bool, Country) AddCountry (this CountryDbContext dbContext, CountryCreate countryCreate)
|
||||
{
|
||||
Country newCountry = new Country(countryCreate);
|
||||
return dbContext.Countries.Add(dbContext, newCountry);
|
||||
}
|
||||
|
||||
internal static async Task<(bool, Country)> AddCountryAsync (this CountryDbContext dbContext, CountryCreate countryCreate)
|
||||
{
|
||||
var newCountry = new Country(countryCreate);
|
||||
return await dbContext.Countries.AddAsync(dbContext, newCountry);
|
||||
}
|
||||
|
||||
internal static (bool, Country) UpdateCountry(this CountryDbContext dbContext, CountryUpdate countryUpdate,
|
||||
int countryId)
|
||||
{
|
||||
var country = dbContext.Countries.FirstOrDefault(x => x.Id == countryId);
|
||||
|
||||
if (country != null)
|
||||
{
|
||||
var updatedCountry = new Country(countryUpdate);
|
||||
return dbContext.Countries.Update(dbContext, updatedCountry);
|
||||
}
|
||||
|
||||
return NotFound<Country>();
|
||||
}
|
||||
|
||||
internal static async Task<Country> GetCountryByIdAsync(this DbSet<Country> countries, int countryId) =>
|
||||
await countries.FirstOrDefaultAsync(x => x.Id == countryId);
|
||||
|
||||
|
||||
internal static async Task<(bool, Country)> UpdateCountryAsync(this CountryDbContext dbContext, CountryUpdate countryUpdate,
|
||||
int countryCode)
|
||||
{
|
||||
var country = await dbContext.Countries.FirstOrDefaultAsync(x => x.Code == countryCode);
|
||||
|
||||
if (country != null)
|
||||
{
|
||||
var updatedCountry = new Country(countryUpdate);
|
||||
return await dbContext.Countries.UpdateAsync(dbContext, updatedCountry);
|
||||
}
|
||||
|
||||
return NotFound<Country>();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BlueWest.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BlueWest.WebApi.EF
|
||||
{
|
||||
internal static class CurrencyExtensions
|
||||
{
|
||||
|
||||
internal static Currency GetCurrencyById(this DbSet<Currency> currencies, int currencyId) => currencies.GetOne(x => x.Id == currencyId);
|
||||
internal static (bool, T) NotFound<T>() where T : class => (false, null);
|
||||
|
||||
|
||||
internal static (bool, Currency) AddCurrency(this CountryDbContext dbContext, CurrencyCreate currencyToCreate)
|
||||
{
|
||||
|
||||
var newCurrency = new Currency(currencyToCreate);
|
||||
return dbContext.Currencies.Add(dbContext, newCurrency);
|
||||
}
|
||||
|
||||
|
||||
internal static (bool, Currency) UpdateCurrency(this CountryDbContext dbContext, int currencyId, CurrencyUpdate currencyToUpdate)
|
||||
{
|
||||
var currency = dbContext.Currencies.FirstOrDefault(x => x.Id == currencyId);
|
||||
|
||||
if (currency == null) return NotFound<Currency>();
|
||||
|
||||
var newCurrency = new Currency(currencyToUpdate);
|
||||
var operationResult = dbContext.Currencies.Update(dbContext, newCurrency);
|
||||
return operationResult;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
|
||||
namespace BlueWest.WebApi.EF
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
|
||||
public class DatabaseFundamentalsAttribute : Attribute
|
||||
{
|
||||
public Type DatabaseContextType;
|
||||
public Type EntityType;
|
||||
|
||||
public DatabaseFundamentalsAttribute(Type databaseContextType, Type entityType) { }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using BlueWest.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BlueWest.WebApi.EF;
|
||||
|
||||
public static class GenericExtensions
|
||||
{
|
||||
|
||||
|
||||
internal static T GetOne<T>(this DbSet<T> dbSet, Expression<Func<T,bool>> predicate) where T: class => dbSet.FirstOrDefault(predicate);
|
||||
|
||||
internal static async Task<T> GetOneAsync<T>(this DbSet<T> dbSet, Expression<Func<T,bool>> predicate) where T: class => await dbSet.FirstOrDefaultAsync(predicate);
|
||||
|
||||
|
||||
internal static (bool, T) NotFound<T>() where T : class => (false, null);
|
||||
|
||||
internal static (bool, T) Add<T>(this DbSet<T> dbSet, DbContext dbContext, T objectToAdd) where T: class
|
||||
{
|
||||
var newEntity = dbSet.Add(objectToAdd).Entity;
|
||||
return (dbContext.SaveChanges() >= 0, newEntity);
|
||||
}
|
||||
|
||||
internal static async Task<(bool, T)> AddAsync<T>(this DbSet<T> dbSet, DbContext dbContext, T objectToAdd) where T: class
|
||||
{
|
||||
var newEntity = dbSet.Add(objectToAdd);
|
||||
bool resultOperation = await dbContext.SaveChangesAsync() >= 0;
|
||||
return (resultOperation, objectToAdd);
|
||||
}
|
||||
|
||||
|
||||
internal static (bool, T) Update<T>(this DbSet<T> dbSet, DbContext dbContext, T objectToUpdate) where T: class
|
||||
{
|
||||
|
||||
dbContext.Update(objectToUpdate);
|
||||
var resultOperation = dbContext.SaveChanges() >= 0;
|
||||
return resultOperation ? (true, objectToUpdate) : (false, null);
|
||||
}
|
||||
|
||||
internal static async Task<(bool, T)> UpdateAsync<T>(this DbSet<T> dbSet, DbContext dbContext, T objectToUpdate) where T: class
|
||||
{
|
||||
dbSet.Update(objectToUpdate);
|
||||
var result = await dbContext.SaveChangesAsync() >= 0;
|
||||
return (result, objectToUpdate);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +1,25 @@
|
|||
using BlueWest.Data;
|
||||
using BlueWest.WebApi.MySQL.Model;
|
||||
using BlueWest.WebApi.EF.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BlueWest.WebApi.MySQL
|
||||
namespace BlueWest.WebApi.EF
|
||||
{
|
||||
/// <summary>
|
||||
/// Finance operations table
|
||||
/// </summary>
|
||||
public sealed class FinanceDbContext : DbContext
|
||||
internal sealed class FinanceDbContext : DbContext
|
||||
{
|
||||
public DbSet<FinanceOp> Transactions { get; set; }
|
||||
[DatabaseFundamentals(typeof(FinanceDbContext), typeof(FinanceOp))]
|
||||
internal DbSet<FinanceOp> Transactions { get; set; }
|
||||
|
||||
public DbSet<FinanceOpType> TransactionTypes { get; set; }
|
||||
[DatabaseFundamentals(typeof(FinanceDbContext), typeof(FinanceOpType))]
|
||||
internal DbSet<FinanceOpType> TransactionTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Finance transactions context
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public FinanceDbContext(DbContextOptions<FinanceDbContext> options) : base(options)
|
||||
internal FinanceDbContext(DbContextOptions<FinanceDbContext> options) : base(options)
|
||||
{
|
||||
Database.EnsureCreated();
|
||||
}
|
||||
|
|
|
@ -1,24 +1,21 @@
|
|||
using BlueWest.Data;
|
||||
using BlueWest.WebApi.MySQL.Model;
|
||||
using BlueWest.WebApi.EF.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace BlueWest.WebApi.MySQL
|
||||
namespace BlueWest.WebApi.EF
|
||||
{
|
||||
|
||||
public sealed class UserDbContext : DbContext
|
||||
internal sealed class UserDbContext : DbContext
|
||||
{
|
||||
public DbSet<User> Users { get; set; }
|
||||
internal DbSet<User> Users { get; set; }
|
||||
internal IConfiguration Configuration;
|
||||
|
||||
|
||||
public IConfiguration Configuration;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Database for the context of database users
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public UserDbContext(DbContextOptions<UserDbContext> options) : base(options)
|
||||
internal UserDbContext(DbContextOptions<UserDbContext> options) : base(options)
|
||||
{
|
||||
Database.EnsureCreated();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BlueWest.Data;
|
||||
using BlueWest.WebApi.MySQL;
|
||||
using BlueWest.WebApi.EF;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace BlueWest.WebApi.Controllers
|
|||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class CountryController : ControllerBase
|
||||
internal class CountryController : ControllerBase
|
||||
{
|
||||
private readonly CountryDbContext _dbContext;
|
||||
|
||||
|
@ -50,10 +50,8 @@ namespace BlueWest.WebApi.Controllers
|
|||
[HttpPost]
|
||||
public ActionResult AddCountry(CountryCreate countryToCreate)
|
||||
{
|
||||
var newCountry = countryToCreate.ToCountry();
|
||||
_dbContext.Countries.Add(newCountry);
|
||||
_dbContext.SaveChanges();
|
||||
return CreatedAtRoute(nameof(GetCountryById), new {countryId = newCountry.Code}, newCountry);
|
||||
_dbContext.AddCountry(countryToCreate);
|
||||
return CreatedAtRoute(nameof(GetCountryById), new {countryId = countryToCreate.Code});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -67,13 +65,11 @@ namespace BlueWest.WebApi.Controllers
|
|||
[HttpPut("{countryCode}")]
|
||||
public ActionResult UpdateCountry(int countryCode, CountryUpdate countryToUpdate)
|
||||
{
|
||||
var country = _dbContext.Countries.FirstOrDefault(x => x.Code == countryCode);
|
||||
var (success, country) = _dbContext.UpdateCountry(countryToUpdate, countryCode);
|
||||
|
||||
if (country != null)
|
||||
if (success)
|
||||
{
|
||||
var updatedCountry = new Country(countryToUpdate, countryCode, country.Currencies, country.Users);
|
||||
_dbContext.Countries.Update(updatedCountry);
|
||||
return Ok(updatedCountry);
|
||||
return Ok(country);
|
||||
}
|
||||
|
||||
return new NotFoundResult();
|
||||
|
|
|
@ -2,7 +2,7 @@ using System.Collections.Generic;
|
|||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using BlueWest.Data;
|
||||
using BlueWest.WebApi.MySQL;
|
||||
using BlueWest.WebApi.EF;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
@ -13,11 +13,10 @@ namespace BlueWest.WebApi.Controllers
|
|||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class CurrencyController : ControllerBase
|
||||
internal class CurrencyController : ControllerBase
|
||||
{
|
||||
private readonly CountryDbContext _dbContext;
|
||||
|
||||
|
||||
public CurrencyController(CountryDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
|
@ -32,14 +31,8 @@ namespace BlueWest.WebApi.Controllers
|
|||
[HttpGet]
|
||||
public ActionResult GetCurrencies()
|
||||
{
|
||||
var dbContext = _dbContext.Currencies;
|
||||
|
||||
if (dbContext != null)
|
||||
{
|
||||
return Ok(dbContext.ToArray());
|
||||
}
|
||||
|
||||
return new NotFoundResult();
|
||||
var currencies = _dbContext.Currencies.ToArray();
|
||||
return Ok(currencies);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -53,9 +46,13 @@ namespace BlueWest.WebApi.Controllers
|
|||
public ActionResult AddCurrency(CurrencyCreate currencyToCreate)
|
||||
{
|
||||
|
||||
var newCurrency = currencyToCreate.ToCurrency();
|
||||
_dbContext.Currencies.Add(newCurrency);
|
||||
_dbContext.SaveChanges();
|
||||
var (success, newCurrency) = _dbContext.AddCurrency(currencyToCreate);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
|
||||
return CreatedAtRoute(nameof(GetCurrencyById), new {CurrencyId = newCurrency.Code}, newCurrency);
|
||||
}
|
||||
|
||||
|
@ -70,14 +67,11 @@ namespace BlueWest.WebApi.Controllers
|
|||
[HttpPut("{currencyNumber}")]
|
||||
public ActionResult UpdateCurrency(int currencyNumber, CurrencyUpdate currencyToUpdate)
|
||||
{
|
||||
var currency = _dbContext.Currencies.FirstOrDefault(x => x.Num == currencyNumber);
|
||||
var (success, currency) = _dbContext.UpdateCurrency(currencyNumber, currencyToUpdate);
|
||||
|
||||
if (currency != null)
|
||||
if (success)
|
||||
{
|
||||
var updatedCurrency = new Currency(currencyToUpdate, currencyNumber, new List<Country>());
|
||||
_dbContext.Update(updatedCurrency);
|
||||
_dbContext.SaveChanges();
|
||||
return Ok(updatedCurrency);
|
||||
return Ok(currency);
|
||||
}
|
||||
|
||||
return new NotFoundResult();
|
||||
|
@ -94,11 +88,11 @@ namespace BlueWest.WebApi.Controllers
|
|||
[HttpGet("{currencyId}", Name = nameof(GetCurrencyById))]
|
||||
public ActionResult GetCurrencyById(int currencyId)
|
||||
{
|
||||
var array = _dbContext.Countries.FirstOrDefault(x => x.Code == currencyId);
|
||||
var currency = _dbContext.Currencies.GetCurrencyById(currencyId);
|
||||
|
||||
if (array != null)
|
||||
if (currency != null)
|
||||
{
|
||||
return Ok(array);
|
||||
return Ok(currency);
|
||||
}
|
||||
|
||||
return new NotFoundResult();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using BlueWest.Data;
|
||||
using BlueWest.WebApi.MySQL;
|
||||
using BlueWest.WebApi.EF;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
@ -11,7 +11,7 @@ namespace BlueWest.WebApi.Controllers;
|
|||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class FinanceController : ControllerBase
|
||||
internal class FinanceController : ControllerBase
|
||||
{
|
||||
private readonly FinanceDbContext _dbContext;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ using Swashbuckle.AspNetCore.SwaggerGen;
|
|||
|
||||
namespace BlueWest.WebApi.Tools
|
||||
{
|
||||
public class SwaggerEnumSchemaFilter : ISchemaFilter
|
||||
internal class SwaggerEnumSchemaFilter : ISchemaFilter
|
||||
{
|
||||
public void Apply(OpenApiSchema model, SchemaFilterContext context)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using BlueWest.Data;
|
||||
using BlueWest.WebApi.MySQL;
|
||||
using BlueWest.WebApi.EF;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
@ -11,7 +11,7 @@ namespace BlueWest.WebApi.Controllers
|
|||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class UserController : ControllerBase
|
||||
internal class UserController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly UserDbContext _dbContext;
|
||||
|
@ -70,7 +70,7 @@ namespace BlueWest.WebApi.Controllers
|
|||
[HttpPost]
|
||||
public ActionResult AddUser(UserCreate userCreate)
|
||||
{
|
||||
var user = new User(userCreate, 0, new List<FinanceOp>(), null, -1);
|
||||
var user = new User(userCreate);
|
||||
_dbContext.Users.Add(user);
|
||||
_dbContext.SaveChanges();
|
||||
return CreatedAtRoute(nameof(GetUserById), new {userId = user.Id}, user);
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
using BlueWest.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BlueWest.WebApi.MySQL.Model
|
||||
namespace BlueWest.WebApi.EF.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// Database model configuration extensions
|
||||
/// </summary>
|
||||
public static class ModelBuilderExtensions
|
||||
{
|
||||
#region Initialization
|
||||
|
||||
/// <summary>
|
||||
/// Setup the database model
|
||||
/// </summary>
|
||||
|
@ -16,36 +18,77 @@ namespace BlueWest.WebApi.MySQL.Model
|
|||
{
|
||||
modelBuilder
|
||||
.ConfigureDatabaseKeys()
|
||||
.CountryCurrencyModel()
|
||||
.CurrencyModel()
|
||||
.ConfigureUserModel();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DatabasePK
|
||||
|
||||
private static ModelBuilder ConfigureDatabaseKeys(this ModelBuilder modelBuilder)
|
||||
{
|
||||
// User PK
|
||||
modelBuilder.Entity<User>(builder => builder
|
||||
.HasKey(user => user.Id));
|
||||
// User
|
||||
modelBuilder
|
||||
.Entity<User>(builder => builder
|
||||
.HasKey(user => user.Id))
|
||||
.Entity<User>().Property(user => user.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
// Country PK
|
||||
modelBuilder.Entity<Country>(builder => builder
|
||||
.HasKey(country => country.Code));
|
||||
// Country
|
||||
modelBuilder
|
||||
.Entity<Country>(builder => builder
|
||||
.HasKey(country => country.Id))
|
||||
.Entity<Country>().Property(country => country.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
// Currency PK
|
||||
modelBuilder.Entity<Currency>(builder => builder
|
||||
.HasKey(currency => currency.Num));
|
||||
// Currency
|
||||
modelBuilder
|
||||
.Entity<Currency>(builder => builder
|
||||
.HasKey(currency => currency.Id))
|
||||
.Entity<Currency>()
|
||||
.Property(currency => currency.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
// FinanceOp PK
|
||||
// Company PK
|
||||
modelBuilder
|
||||
.Entity<Company>(builder => builder
|
||||
.HasKey(company => company.Id))
|
||||
.Entity<Company>().Property(company => company.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
// Industry PK
|
||||
modelBuilder
|
||||
.Entity<Industry>(builder => builder
|
||||
.HasKey(industry => industry.Id))
|
||||
.Entity<Industry>().Property(industry => industry.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
|
||||
// Product
|
||||
modelBuilder
|
||||
.Entity<Industry>(builder => builder
|
||||
.HasKey(industry => industry.Id));
|
||||
|
||||
modelBuilder
|
||||
.Entity<Industry>()
|
||||
.Property(industry => industry.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
// FinanceOp
|
||||
return
|
||||
modelBuilder.Entity<FinanceOp>(builder => builder
|
||||
.HasKey(financeOp => financeOp.Id));
|
||||
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
private static ModelBuilder CountryCurrencyModel(this ModelBuilder modelBuilder)
|
||||
#region Database Models
|
||||
|
||||
private static ModelBuilder CurrencyModel(this ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
// Relationships
|
||||
modelBuilder
|
||||
.Entity<Currency>()
|
||||
.HasMany(ub => ub.Countries)
|
||||
|
@ -87,6 +130,8 @@ namespace BlueWest.WebApi.MySQL.Model
|
|||
|
||||
return modelBuilder;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using BlueWest.WebApi.MySQL;
|
||||
using BlueWest.WebApi.EF;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
@ -51,11 +51,14 @@ namespace BlueWest.WebApi
|
|||
public static IServiceCollection PrepareDatabasePool(this IServiceCollection serviceCollection,
|
||||
IConfiguration configuration, IWebHostEnvironment environment)
|
||||
{
|
||||
|
||||
|
||||
return serviceCollection
|
||||
.AddDbContextPool<UserDbContext>(options => options.GetMySqlSettings(configuration, environment))
|
||||
.AddDbContextPool<CountryDbContext>(options => options.GetMySqlSettings(configuration, environment))
|
||||
.AddDbContextPool<FinanceDbContext>(options => options.GetMySqlSettings(configuration, environment));
|
||||
.AddDbContextPool<FinanceDbContext>(options => options.GetMySqlSettings(configuration, environment))
|
||||
.AddDbContextPool<CompanyDbContext>(options => options.GetMySqlSettings(configuration, environment));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
using BlueWest.WebApi.MySQL;
|
||||
using BlueWest.WebApi.EF;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace BlueWest.WebApi;
|
||||
|
|
|
@ -13,6 +13,9 @@ using BlueWest.WebApi.Interfaces;
|
|||
|
||||
namespace BlueWest.WebApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Entry point of the application.
|
||||
/// </summary>
|
||||
public class Program
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -35,18 +38,21 @@ namespace BlueWest.WebApi
|
|||
optimizationLevel: OptimizationLevel.Release));
|
||||
}*/
|
||||
|
||||
public static IHost Host1 { get; private set; }
|
||||
/// <summary>
|
||||
/// Host Interface of the application.
|
||||
/// </summary>
|
||||
public static IHost MainHost { get; private set; }
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Host1 = CreateHostBuilder(args)
|
||||
MainHost = CreateHostBuilder(args)
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.Build();
|
||||
Host1.RunAsync();
|
||||
|
||||
|
||||
var tryGetEventManager = Host1.Services.GetService(typeof(EventManager));
|
||||
_ = Host1.Services.GetService(typeof(ExchangeInterface));
|
||||
MainHost.RunAsync();
|
||||
|
||||
var tryGetEventManager = MainHost.Services.GetService(typeof(EventManager));
|
||||
_ = MainHost.Services.GetService(typeof(ExchangeInterface));
|
||||
|
||||
|
||||
if(tryGetEventManager == null) Console.WriteLine($"Failed to get {nameof(EventManager)} Service.");
|
||||
|
@ -62,7 +68,7 @@ namespace BlueWest.WebApi
|
|||
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
private static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MapTo;
|
||||
|
||||
namespace BlueWest.Data
|
||||
{
|
||||
[MapFrom(typeof(CompanyCreate))]
|
||||
public partial class Company
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Address { get; set; }
|
||||
|
||||
public CompanyType CompanyType { get; set; }
|
||||
|
||||
public Country CurrentCountry { get; set; }
|
||||
|
||||
public Country OriginCountry { get; set; }
|
||||
|
||||
public DateTime FoundingDate { get; set; }
|
||||
|
||||
public List<Industry> Industry { get; set; }
|
||||
|
||||
public Company()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using MapTo;
|
||||
|
||||
namespace BlueWest.Data
|
||||
{
|
||||
[MapFrom(typeof(Company))]
|
||||
public partial class CompanyCreate
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Address { get; set; }
|
||||
|
||||
public Country CurrentCountry { get; set; }
|
||||
|
||||
public Country OriginCountry { get; set; }
|
||||
|
||||
public DateTime FoundingDate { get; set; }
|
||||
|
||||
public CompanyCreate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
namespace BlueWest.Data
|
||||
{
|
||||
public partial class CompanySeller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using MapTo;
|
||||
|
||||
namespace BlueWest.Data
|
||||
{
|
||||
[MapFrom(typeof(Company))]
|
||||
public partial class CompanyType
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public CompanyType()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using MapTo;
|
||||
|
||||
namespace BlueWest.Data
|
||||
{
|
||||
[MapFrom(typeof(Company))]
|
||||
public partial class CompanyTypeCreate
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public CompanyTypeCreate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace BlueWest.Data
|
||||
{
|
||||
public partial class Product
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Industry Industry { get; set; }
|
||||
public List<Company> Seller { get; set; }
|
||||
|
||||
public Product()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,12 +14,14 @@ namespace BlueWest.Data
|
|||
|
||||
public partial class Country
|
||||
{
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// ISO 3166-1 numeric code
|
||||
/// Primary key.
|
||||
/// </summary>
|
||||
public int Code { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ISO 3166-1 State Name
|
||||
/// </summary>
|
||||
|
@ -33,15 +35,15 @@ namespace BlueWest.Data
|
|||
|
||||
|
||||
[JsonConstructor]
|
||||
public Country(int code, string stateName, string tld, List<Currency> currencies)
|
||||
public Country(string stateName, string tld, List<Currency> currencies)
|
||||
{
|
||||
Code = code;
|
||||
StateName = stateName;
|
||||
TLD = tld;
|
||||
Currencies = currencies;
|
||||
}
|
||||
|
||||
public Country() { }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,9 @@ namespace BlueWest.Data
|
|||
public partial class CountryCreate
|
||||
{
|
||||
// ISO 3166-1 numeric code
|
||||
public int Code { get; set; } // Primary key
|
||||
public int Code { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public string StateName { get; set; }
|
||||
|
||||
public List<CurrencyUnique> CurrenciesToCreate { get; set; }
|
||||
|
@ -18,19 +20,8 @@ namespace BlueWest.Data
|
|||
public string TLD { get; set; }
|
||||
|
||||
public CountryCreate() { }
|
||||
|
||||
public Country ToCountry()
|
||||
{
|
||||
var currencies = new List<Currency>();
|
||||
|
||||
foreach (var currencyCreate in CurrenciesToCreate)
|
||||
{
|
||||
currencies.Add(new Currency(currencyCreate, null));
|
||||
}
|
||||
|
||||
return new Country(this, currencies, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,12 @@ namespace BlueWest.Data
|
|||
public partial class CountryUnique
|
||||
{
|
||||
// ISO 3166-1 numeric code
|
||||
public int Code { get; set; } // Primary key
|
||||
public int Id { get; set; }
|
||||
|
||||
public int Code { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string StateName { get; set; }
|
||||
|
||||
[MaxLength(2)] public string Alpha2Code { get; set; }
|
|
@ -8,10 +8,14 @@ namespace BlueWest.Data
|
|||
|
||||
public partial class CountryUpdate
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string StateName { get; set; }
|
||||
public string Alpha2Code { get; set; }
|
||||
public string TLD { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ISO 3166-1 numeric code
|
||||
/// </summary>
|
||||
public int Code { get; set; }
|
||||
public CountryUpdate() { }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
namespace BlueWest.Data.generated
|
||||
{
|
||||
public class GeneratedCountries
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -12,14 +12,12 @@ namespace BlueWest.Data
|
|||
|
||||
public partial class Currency
|
||||
{
|
||||
public int Num { get; set; } // Primary key
|
||||
public int Id { get; set; }
|
||||
public int Num { get; set; }
|
||||
[MaxLength(3)] public string Code { get; set; }
|
||||
public List<Country> Countries { get; set; }
|
||||
|
||||
public Currency()
|
||||
{
|
||||
|
||||
}
|
||||
public Currency() { }
|
||||
}
|
||||
}
|
||||
|
|
@ -11,20 +11,7 @@ namespace BlueWest.Data
|
|||
[MaxLength(3)] public string Code { get; set; }
|
||||
public List<CountryUnique> CountriesToCreate { get; set; }
|
||||
public CurrencyCreate() { }
|
||||
|
||||
public Currency ToCurrency()
|
||||
{
|
||||
List<Country> countries = new List<Country>();
|
||||
|
||||
foreach (var countryCreate in CountriesToCreate)
|
||||
{
|
||||
var newCountry = new Country(countryCreate, null, null);
|
||||
countries.Add(newCountry);
|
||||
}
|
||||
|
||||
return new Currency(this, countries);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ namespace BlueWest.Data
|
|||
|
||||
public partial class CurrencyUpdate
|
||||
{
|
||||
public int Num { get; set; }
|
||||
|
||||
// ISO 4217 Code
|
||||
[MaxLength(3)] public string Code { get; set; }
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
namespace BlueWest.Data
|
||||
{
|
||||
public partial class Industry
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string IndustryType { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
namespace BlueWest.Data.Media
|
||||
{
|
||||
public class MediaSource
|
||||
{
|
||||
public MediaSourceType SourceType { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
namespace BlueWest.Data.Media
|
||||
{
|
||||
public class MediaSourceType
|
||||
{
|
||||
public string SourceTypeName { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
namespace BlueWest.Data.Media
|
||||
{
|
||||
public class Website
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string WebsiteDomain { get; set; }
|
||||
public string IsHttps { get; set; }
|
||||
public bool HasCloudflareLikeService { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BlueWest.Data.Capital\BlueWest.Data.Capital.csproj" />
|
||||
<ProjectReference Include="..\include\BlueWest.MapTo\src\BlueWest.MapTo\BlueWest.MapTo.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,12 @@
|
|||
namespace BlueWest.Data.Geography
|
||||
{
|
||||
public partial class Coordinate
|
||||
{
|
||||
public Guid Key { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public Country Country { get; set; }
|
||||
public TimeSpan CreatedTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 8f656cbcc1c5782b1c5983600568704b6244b1ef
|
||||
Subproject commit 75205acb359d624f2bdd9cb32474aca993fb77f1
|
|
@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.31911.196
|
|||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest", "BlueWest\BlueWest.csproj", "{293E7852-8AFD-4EFB-8C2D-F1BBE68AEE78}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Data", "BlueWest.Data\BlueWest.Data.csproj", "{E518C62D-768C-4885-9C9D-FD5761605B54}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Data.Capital", "BlueWest.Data.Capital\BlueWest.Data.Capital.csproj", "{E518C62D-768C-4885-9C9D-FD5761605B54}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Api", "BlueWest.Api\BlueWest.Api.csproj", "{6D3321B5-CF1A-4251-B28D-329EDA6DC278}"
|
||||
EndProject
|
||||
|
@ -34,6 +34,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{552B9217-4
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueWest.Api.Gateway", "BlueWest.Api.Gateway\BlueWest.Api.Gateway.csproj", "{A78343AF-77C6-48FD-A9C4-F8B7CBA56212}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueWest.Data.Geography", "BlueWest.Data.Geography\BlueWest.Data.Geography.csproj", "{D5924A3F-0AA1-4AF4-AEDB-3B9F91E6531E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -72,6 +74,10 @@ Global
|
|||
{A78343AF-77C6-48FD-A9C4-F8B7CBA56212}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A78343AF-77C6-48FD-A9C4-F8B7CBA56212}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A78343AF-77C6-48FD-A9C4-F8B7CBA56212}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D5924A3F-0AA1-4AF4-AEDB-3B9F91E6531E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D5924A3F-0AA1-4AF4-AEDB-3B9F91E6531E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D5924A3F-0AA1-4AF4-AEDB-3B9F91E6531E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D5924A3F-0AA1-4AF4-AEDB-3B9F91E6531E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlueWest.Tools;
|
||||
using BlueWest.Core.Threading;
|
||||
|
||||
|
||||
namespace BlueWest.Core
|
||||
|
@ -18,7 +17,7 @@ namespace BlueWest.Core
|
|||
public void Run()
|
||||
{
|
||||
|
||||
new ThreadServer(EventManager);
|
||||
_ = new ThreadServer(EventManager);
|
||||
BlueWestConsoleBanner();
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using BlueWest.Core.ComponentSystem;
|
||||
using BlueWest.Core.Threading;
|
||||
using BlueWest.Tools;
|
||||
|
||||
namespace BlueWest.Core
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace BlueWest.Core.Threading
|
||||
{
|
||||
public static class Threads
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
Subproject commit f7963d2d7e32a45bc7da61e31b07c55ca4829fb4
|
||||
Subproject commit aa5b01cdc42a00e873f126049a9c111b1d5220fa
|
Loading…
Reference in New Issue