first things
This commit is contained in:
74
Repositories/FwDbContext.cs
Normal file
74
Repositories/FwDbContext.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Datamodels.Lookups;
|
||||
using Datamodels.DatabaseModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Repositories
|
||||
{
|
||||
public class FwDbContext: DbContext
|
||||
{
|
||||
public string _connectionString { get; set; } = "SERVER=127.0.0.1;DATABASE=testdb;PORT=3306;USER=root;PASSWORD=example";
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
|
||||
optionsBuilder.UseMySql(_connectionString);
|
||||
}
|
||||
|
||||
public DbSet<LookupCategory> LookupCategories { get; set; }
|
||||
public DbSet<LookupValue> LookupValues { get; set; }
|
||||
public DbSet<Address> Address { get; set; }
|
||||
public DbSet<Person> Person { get; set; }
|
||||
public DbSet<Communication> Communication { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
modelBuilder.Entity<LookupValue>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<LookupValue>()
|
||||
.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
|
||||
modelBuilder.Entity<LookupCategory>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<LookupCategory>()
|
||||
.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
|
||||
modelBuilder.Entity<LookupCategory>()
|
||||
.HasMany(x => x.LookupValues)
|
||||
.WithOne(y => y.LookupCategory);
|
||||
|
||||
modelBuilder.Entity<Person>()
|
||||
.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
|
||||
modelBuilder.Entity<Person>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<Person>()
|
||||
.HasMany(x => x.Communications)
|
||||
.WithOne(y => y.Person);
|
||||
|
||||
modelBuilder.Entity<Person>()
|
||||
.HasMany(x => x.Addresses)
|
||||
.WithOne(y => y.Person);
|
||||
|
||||
modelBuilder.Entity<Address>()
|
||||
.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
|
||||
modelBuilder.Entity<Address>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<Communication>()
|
||||
.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
|
||||
modelBuilder.Entity<Communication>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
147
Repositories/FwMariaLookupRepo.cs
Normal file
147
Repositories/FwMariaLookupRepo.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using Datamodels.BusinessModels;
|
||||
using Datamodels.Lookups;
|
||||
using Repositories.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Repositories
|
||||
{
|
||||
public class FwMariaLookupRepo: IFwMariaLookupRepo
|
||||
{
|
||||
|
||||
private readonly FwDbContext _dbContext = new FwDbContext();
|
||||
private readonly ILogger<FwMariaLookupRepo> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public FwMariaLookupRepo(ILogger<FwMariaLookupRepo> logger, IConfiguration configuration)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
try
|
||||
{
|
||||
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
|
||||
{
|
||||
_dbContext._connectionString = "SERVER=127.0.0.1;DATABASE=testdb;PORT=3306;USER=root;PASSWORD=example";
|
||||
}
|
||||
else
|
||||
{
|
||||
string usedDb = configuration.GetSection("GeneralSettings").GetSection("DbToUse").Get<string>();
|
||||
string connectionString = configuration.GetConnectionString(usedDb);
|
||||
_dbContext._connectionString = connectionString;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Database Connection Configuration not valid");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<DataResult<List<LookupCategory>>> GetAllLookups()
|
||||
{
|
||||
var result = await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var newList = _dbContext.LookupCategories.Include(vals => vals.LookupValues).OrderBy(o => o.CategoryName).ToList();
|
||||
return new DataResult<List<LookupCategory>> { Data = newList };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error reading Lookup Data");
|
||||
return new DataResult<List<LookupCategory>>
|
||||
{
|
||||
UserMessage = "Daten f<>r Lookups konnten nicht gelesen werden.",
|
||||
ServerMessage = ex.Message,
|
||||
GeneralResult = GeneralResults.DatabaseError,
|
||||
StackTrace = ex.StackTrace
|
||||
};
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<DataResult<LookupCategory>> GetLookupCategoryById(long id)
|
||||
{
|
||||
var result = await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var cat = _dbContext.LookupCategories.Where(x => x.Id == id).Include(vals => vals.LookupValues).FirstOrDefault();
|
||||
return new DataResult<LookupCategory> { Data = cat };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error reading Lookup Category with Id: {id}");
|
||||
return new DataResult<LookupCategory>
|
||||
{
|
||||
UserMessage = $"Daten f<>r Lookup Kategorie mit Id {id} konnten nicht gelesen werden.",
|
||||
ServerMessage = ex.Message,
|
||||
GeneralResult = GeneralResults.DatabaseError,
|
||||
StackTrace = ex.StackTrace
|
||||
};
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<DataResult<List<LookupCategory>>> GetLookupCategoryByName(string categoryName)
|
||||
{
|
||||
var result = await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var cat = _dbContext.LookupCategories.Where(x => x.CategoryName.ToUpper().Contains(categoryName.ToUpper())).Include(vals => vals.LookupValues).ToList();
|
||||
return new DataResult<List<LookupCategory>> { Data = cat };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error reading Lookup Category with Name: {categoryName}");
|
||||
return new DataResult<List<LookupCategory>>
|
||||
{
|
||||
UserMessage = $"Daten f<>r Lookup Kategorie mit Namen {categoryName} konnten nicht gelesen werden.",
|
||||
ServerMessage = ex.Message,
|
||||
GeneralResult = GeneralResults.DatabaseError,
|
||||
StackTrace = ex.StackTrace
|
||||
};
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<DataResult<List<LookupCategory>>> GetActiveLookupCategories()
|
||||
{
|
||||
var result = await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var catList = _dbContext.LookupCategories.Where(x => x.IsActive).Include(vals => vals.LookupValues).OrderBy(o => o.CategoryName).ToList();
|
||||
return new DataResult<List<LookupCategory>> { Data = catList };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error reading active Lookup Data");
|
||||
return new DataResult<List<LookupCategory>>
|
||||
{
|
||||
UserMessage = "Daten f<>r aktive Lookups konnten nicht gelesen werden.",
|
||||
ServerMessage = ex.Message,
|
||||
GeneralResult = GeneralResults.DatabaseError,
|
||||
StackTrace = ex.StackTrace
|
||||
};
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public void DeleteAllCategories()
|
||||
{
|
||||
_dbContext.Database.ExecuteSqlRaw("delete from LookupValues");
|
||||
_dbContext.Database.ExecuteSqlRaw("delete from LookupCategories");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
94
Repositories/FwMariaSearchRepo.cs
Normal file
94
Repositories/FwMariaSearchRepo.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using Datamodels.BusinessModels;
|
||||
using Datamodels.DatabaseModels;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Repositories.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Datamodels.SearchModels;
|
||||
using System.Linq.Expressions;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Repositories
|
||||
{
|
||||
public class FwMariaSearchRepo : IFwMariaSearchRepo
|
||||
{
|
||||
private readonly FwDbContext _dbContext = new FwDbContext();
|
||||
private readonly ILogger<FwMariaSearchRepo> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public FwMariaSearchRepo(ILogger<FwMariaSearchRepo> logger, IConfiguration configuration)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
try
|
||||
{
|
||||
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
|
||||
{
|
||||
_dbContext._connectionString = "SERVER=127.0.0.1;DATABASE=testdb;PORT=3306;USER=root;PASSWORD=example";
|
||||
}
|
||||
else
|
||||
{
|
||||
string usedDb = configuration.GetSection("GeneralSettings").GetSection("DbToUse").Get<string>();
|
||||
string connectionString = configuration.GetConnectionString(usedDb);
|
||||
_dbContext._connectionString = connectionString;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Database Connection Configuration not valid");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<DataResult<List<Address>>> GetAllAddresses()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _dbContext.Address.Where(x => x.City == "Augsburg" || x.City == "München").Where(y => y.StreetName.Contains("bruck")).ToListAsync().ConfigureAwait(false);
|
||||
return new DataResult<List<Address>> { Data = result };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new DataResult<List<Address>>
|
||||
{
|
||||
GeneralResult = GeneralResults.DatabaseError,
|
||||
UserMessage = "Fehler beim Laden der Adressen",
|
||||
ServerMessage = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public Task<object> GetAllSortedData(TableModel queryFieldDef, List<SortModel> sortModel)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<string> GetBlobData(string tableName, string fieldName, long id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<object> GetDataFilteredAndSorted(List<FilterModel> filter, List<SortModel> sortModel, long skip = 0, long take = -1)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<DataResult<List<IEntityClass>>> GetFilteredData<T>(List<Expression> expressions, long skip = 0, long take = -1) where T : IEntityClass
|
||||
{
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class FilterLinq<T>
|
||||
{
|
||||
public static Expression<Func<T, Boolean>> GetWherePredicate(string whereFieldList, string whereFieldValues)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Repositories/Interfaces/IFwMariaLookupRepo.cs
Normal file
16
Repositories/Interfaces/IFwMariaLookupRepo.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Datamodels.BusinessModels;
|
||||
using Datamodels.Lookups;
|
||||
|
||||
namespace Repositories.Interfaces
|
||||
{
|
||||
public interface IFwMariaLookupRepo
|
||||
{
|
||||
Task<DataResult<List<LookupCategory>>> GetAllLookups();
|
||||
Task<DataResult<LookupCategory>> GetLookupCategoryById(long id);
|
||||
Task<DataResult<List<LookupCategory>>> GetLookupCategoryByName(string categoryName);
|
||||
Task<DataResult<List<LookupCategory>>> GetActiveLookupCategories();
|
||||
}
|
||||
}
|
||||
53
Repositories/Interfaces/IFwMariaSearchRepo.cs
Normal file
53
Repositories/Interfaces/IFwMariaSearchRepo.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Datamodels.BusinessModels;
|
||||
using Datamodels.DatabaseModels;
|
||||
using Datamodels.SearchModels;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Repositories.Interfaces
|
||||
{
|
||||
public interface IFwMariaSearchRepo
|
||||
{
|
||||
Task<DataResult<List<Address>>> GetAllAddresses();
|
||||
|
||||
/// <summary>
|
||||
/// Get Filtered Data from DB Provider without sorting
|
||||
/// </summary>
|
||||
/// <param name="filter">Object describing filters</param>
|
||||
/// <param name="skip">From row</param>
|
||||
/// <param name="take">To Row (-1 for all rows)</param>
|
||||
/// <param name="queryFieldDef">Table- and FieldDefinitions to load from</param>
|
||||
/// <returns>Result Object with Result information and list of DataObjects</returns>
|
||||
Task<DataResult<List<IEntityClass>>> GetFilteredData<T> (List<Expression> expressions, long skip = 0, long take = -1) where T: IEntityClass;
|
||||
|
||||
/// <summary>
|
||||
/// Get all Data from query field definition sorted by sortModel
|
||||
/// </summary>
|
||||
/// <param name="queryFieldDef">Table and Field Descriptions to Query from</param>
|
||||
/// <param name="sortModel">Sorting Definitions</param>
|
||||
/// <returns>Result Object with Result information and list of DataObjects</returns>
|
||||
Task<object> GetAllSortedData (TableModel queryFieldDef, List<SortModel> sortModel);
|
||||
|
||||
/// <summary>
|
||||
/// Get filtered and sorted DB Provider with given range of records
|
||||
/// </summary>
|
||||
/// <param name="queryFieldDef">Table- and Field Description to Query from</param>
|
||||
/// <param name="filter">Object describing filter</param>
|
||||
/// <param name="sortModel">Sorting Definitions</param>
|
||||
/// <param name="skip">From Row</param>
|
||||
/// <param name="take">To Row (-1) for all rows</param>
|
||||
/// <returns>Result Object with Result information and list of DataObjects</returns>
|
||||
Task<object> GetDataFilteredAndSorted(List<FilterModel> filter, List<SortModel> sortModel, long skip=0, long take=-1);
|
||||
|
||||
/// <summary>
|
||||
/// Get Blob String from specific Field in specific Table - works only with id long fields
|
||||
/// </summary>
|
||||
/// <param name="tableName">Name of Table</param>
|
||||
/// <param name="fieldName">Name of Field</param>
|
||||
/// <param name="id">id value of Record</param>
|
||||
/// <returns>String with Blob data</returns>
|
||||
Task<string> GetBlobData(string tableName, string fieldName, long id);
|
||||
}
|
||||
}
|
||||
202
Repositories/Migrations/20210706081036_v1.Designer.cs
generated
Normal file
202
Repositories/Migrations/20210706081036_v1.Designer.cs
generated
Normal file
@@ -0,0 +1,202 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Repositories;
|
||||
|
||||
namespace Repositories.Migrations
|
||||
{
|
||||
[DbContext(typeof(FwDbContext))]
|
||||
[Migration("20210706081036_v1")]
|
||||
partial class v1
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "3.1.16")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Address", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long?>("AddressTypeId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTime>("ChangedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("City")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("PersonId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("StreetName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<int>("StreetNumber")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Zip")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AddressTypeId");
|
||||
|
||||
b.HasIndex("PersonId");
|
||||
|
||||
b.ToTable("Address");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Communication", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTime>("ChangedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("CommunicationTypeId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("CommunicationValue")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("PersonId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CommunicationTypeId");
|
||||
|
||||
b.HasIndex("PersonId");
|
||||
|
||||
b.ToTable("Communication");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Person", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTime?>("Birthday")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTime>("ChangedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<long?>("GenderId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GenderId");
|
||||
|
||||
b.ToTable("Person");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.Lookups.LookupCategory", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("CategoryName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("LookupCategories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.Lookups.LookupValue", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<long?>("LookupCategoryId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LookupCategoryId");
|
||||
|
||||
b.ToTable("LookupValues");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Address", b =>
|
||||
{
|
||||
b.HasOne("Datamodels.Lookups.LookupValue", "AddressType")
|
||||
.WithMany()
|
||||
.HasForeignKey("AddressTypeId");
|
||||
|
||||
b.HasOne("Datamodels.DatabaseModels.Person", "Person")
|
||||
.WithMany("Addresses")
|
||||
.HasForeignKey("PersonId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Communication", b =>
|
||||
{
|
||||
b.HasOne("Datamodels.Lookups.LookupValue", "CommunicationType")
|
||||
.WithMany()
|
||||
.HasForeignKey("CommunicationTypeId");
|
||||
|
||||
b.HasOne("Datamodels.DatabaseModels.Person", "Person")
|
||||
.WithMany("Communications")
|
||||
.HasForeignKey("PersonId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Person", b =>
|
||||
{
|
||||
b.HasOne("Datamodels.Lookups.LookupValue", "Gender")
|
||||
.WithMany()
|
||||
.HasForeignKey("GenderId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.Lookups.LookupValue", b =>
|
||||
{
|
||||
b.HasOne("Datamodels.Lookups.LookupCategory", "LookupCategory")
|
||||
.WithMany("LookupValues")
|
||||
.HasForeignKey("LookupCategoryId");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
181
Repositories/Migrations/20210706081036_v1.cs
Normal file
181
Repositories/Migrations/20210706081036_v1.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace Repositories.Migrations
|
||||
{
|
||||
public partial class v1 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LookupCategories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
CategoryName = table.Column<string>(nullable: true),
|
||||
IsActive = table.Column<bool>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LookupCategories", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LookupValues",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Value = table.Column<string>(nullable: true),
|
||||
IsActive = table.Column<bool>(nullable: false),
|
||||
LookupCategoryId = table.Column<long>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LookupValues", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_LookupValues_LookupCategories_LookupCategoryId",
|
||||
column: x => x.LookupCategoryId,
|
||||
principalTable: "LookupCategories",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Person",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
LastName = table.Column<string>(nullable: true),
|
||||
FirstName = table.Column<string>(nullable: true),
|
||||
Birthday = table.Column<DateTime>(nullable: true),
|
||||
IsActive = table.Column<bool>(nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(nullable: false),
|
||||
ChangedAt = table.Column<DateTime>(nullable: false),
|
||||
GenderId = table.Column<long>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Person", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Person_LookupValues_GenderId",
|
||||
column: x => x.GenderId,
|
||||
principalTable: "LookupValues",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Address",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
StreetName = table.Column<string>(nullable: true),
|
||||
StreetNumber = table.Column<int>(nullable: false),
|
||||
Zip = table.Column<string>(nullable: true),
|
||||
City = table.Column<string>(nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(nullable: false),
|
||||
ChangedAt = table.Column<DateTime>(nullable: false),
|
||||
AddressTypeId = table.Column<long>(nullable: true),
|
||||
PersonId = table.Column<long>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Address", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Address_LookupValues_AddressTypeId",
|
||||
column: x => x.AddressTypeId,
|
||||
principalTable: "LookupValues",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_Address_Person_PersonId",
|
||||
column: x => x.PersonId,
|
||||
principalTable: "Person",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Communication",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
CommunicationValue = table.Column<string>(nullable: true),
|
||||
CommunicationTypeId = table.Column<long>(nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(nullable: false),
|
||||
ChangedAt = table.Column<DateTime>(nullable: false),
|
||||
PersonId = table.Column<long>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Communication", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Communication_LookupValues_CommunicationTypeId",
|
||||
column: x => x.CommunicationTypeId,
|
||||
principalTable: "LookupValues",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_Communication_Person_PersonId",
|
||||
column: x => x.PersonId,
|
||||
principalTable: "Person",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Address_AddressTypeId",
|
||||
table: "Address",
|
||||
column: "AddressTypeId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Address_PersonId",
|
||||
table: "Address",
|
||||
column: "PersonId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Communication_CommunicationTypeId",
|
||||
table: "Communication",
|
||||
column: "CommunicationTypeId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Communication_PersonId",
|
||||
table: "Communication",
|
||||
column: "PersonId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_LookupValues_LookupCategoryId",
|
||||
table: "LookupValues",
|
||||
column: "LookupCategoryId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Person_GenderId",
|
||||
table: "Person",
|
||||
column: "GenderId");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Address");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Communication");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Person");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "LookupValues");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "LookupCategories");
|
||||
}
|
||||
}
|
||||
}
|
||||
200
Repositories/Migrations/FwDbContextModelSnapshot.cs
Normal file
200
Repositories/Migrations/FwDbContextModelSnapshot.cs
Normal file
@@ -0,0 +1,200 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Repositories;
|
||||
|
||||
namespace Repositories.Migrations
|
||||
{
|
||||
[DbContext(typeof(FwDbContext))]
|
||||
partial class FwDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "3.1.16")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Address", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long?>("AddressTypeId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTime>("ChangedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("City")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("PersonId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("StreetName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<int>("StreetNumber")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Zip")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AddressTypeId");
|
||||
|
||||
b.HasIndex("PersonId");
|
||||
|
||||
b.ToTable("Address");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Communication", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTime>("ChangedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("CommunicationTypeId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("CommunicationValue")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("PersonId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CommunicationTypeId");
|
||||
|
||||
b.HasIndex("PersonId");
|
||||
|
||||
b.ToTable("Communication");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Person", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTime?>("Birthday")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTime>("ChangedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<long?>("GenderId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GenderId");
|
||||
|
||||
b.ToTable("Person");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.Lookups.LookupCategory", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("CategoryName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("LookupCategories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.Lookups.LookupValue", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<long?>("LookupCategoryId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LookupCategoryId");
|
||||
|
||||
b.ToTable("LookupValues");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Address", b =>
|
||||
{
|
||||
b.HasOne("Datamodels.Lookups.LookupValue", "AddressType")
|
||||
.WithMany()
|
||||
.HasForeignKey("AddressTypeId");
|
||||
|
||||
b.HasOne("Datamodels.DatabaseModels.Person", "Person")
|
||||
.WithMany("Addresses")
|
||||
.HasForeignKey("PersonId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Communication", b =>
|
||||
{
|
||||
b.HasOne("Datamodels.Lookups.LookupValue", "CommunicationType")
|
||||
.WithMany()
|
||||
.HasForeignKey("CommunicationTypeId");
|
||||
|
||||
b.HasOne("Datamodels.DatabaseModels.Person", "Person")
|
||||
.WithMany("Communications")
|
||||
.HasForeignKey("PersonId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.DatabaseModels.Person", b =>
|
||||
{
|
||||
b.HasOne("Datamodels.Lookups.LookupValue", "Gender")
|
||||
.WithMany()
|
||||
.HasForeignKey("GenderId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Datamodels.Lookups.LookupValue", b =>
|
||||
{
|
||||
b.HasOne("Datamodels.Lookups.LookupCategory", "LookupCategory")
|
||||
.WithMany("LookupValues")
|
||||
.HasForeignKey("LookupCategoryId");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Repositories/Repositories.csproj
Normal file
22
Repositories/Repositories.csproj
Normal file
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Datamodels\Datamodels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.16">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.16" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.16" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user