Skip to content

Commit

Permalink
feat: Install the library of 'Pomelo.EntityFrameworkCore.MySql' in re…
Browse files Browse the repository at this point in the history
…placement of the MySQL and restart migrations
  • Loading branch information
CarlosPavajeau committed Aug 6, 2021
1 parent cc2aba7 commit 6669333
Show file tree
Hide file tree
Showing 39 changed files with 1,538 additions and 7,842 deletions.
2 changes: 1 addition & 1 deletion src/Armory.Api/Armory.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MySql.EntityFrameworkCore" Version="5.0.3.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
</ItemGroup>

Expand Down
20 changes: 14 additions & 6 deletions src/Armory.Api/Extensions/Infrastructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Armory.Armament.Weapons.Infrastructure.Persistence;
using Armory.Degrees.Domain;
using Armory.Degrees.Infrastructure.Persistence;
using Armory.Formats.WarMaterialAndSpecialEquipmentAssignmentFormats.Domain;
using Armory.Formats.WarMaterialAndSpecialEquipmentAssignmentFormats.Infrastructure.Persistence;
using Armory.People.Domain;
using Armory.People.Infrastructure.Persistence;
using Armory.Ranks.Domain;
Expand Down Expand Up @@ -58,7 +60,10 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi

services.AddScoped<ArmoryDbContext, ArmoryDbContext>();
services.AddDbContext<ArmoryDbContext>(
options => options.UseMySQL(configuration.GetConnectionString("DefaultConnection")),
options => options.UseMySql(
configuration.GetConnectionString("DefaultConnection"),
new MySqlServerVersion(new Version(8, 0, 26)))
.EnableDetailedErrors(),
ServiceLifetime.Transient);

services.AddMediatR(AssemblyHelper.GetInstance(Assemblies.Armory));
Expand All @@ -76,6 +81,9 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi
services.AddScoped<IRanksRepository, MySqlRanksRepository>();
services.AddScoped<IDegreesRepository, MySqlDegreesRepository>();
services.AddScoped<ITroopersRepository, MySqlTroopersRepository>();
services
.AddScoped<IWarMaterialAndSpecialEquipmentAssignmentFormatsRepository,
MySqlWarMaterialAndSpecialEquipmentAssignmentFormatsRepository>();

services.AddScoped<ITransactionInitializer, TransactionInitializer>();

Expand All @@ -86,7 +94,7 @@ public static IServiceCollection AddSwagger(this IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo {Title = "Armory.Api", Version = "v1"});
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Armory.Api", Version = "v1" });
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Expand Down Expand Up @@ -165,25 +173,25 @@ public static IApplicationBuilder SeedRoles(this IApplicationBuilder app, RoleMa
{
if (!roleManager.RoleExistsAsync("Developer").Result)
{
var developerRole = new ArmoryRole {Name = "Developer"};
var developerRole = new ArmoryRole { Name = "Developer" };
_ = roleManager.CreateAsync(developerRole).Result;
}

if (!roleManager.RoleExistsAsync("SquadronLeader").Result)
{
var squadronLeader = new ArmoryRole {Name = "SquadronLeader"};
var squadronLeader = new ArmoryRole { Name = "SquadronLeader" };
_ = roleManager.CreateAsync(squadronLeader).Result;
}

if (!roleManager.RoleExistsAsync("SquadLeader").Result)
{
var squadLeader = new ArmoryRole {Name = "SquadLeader"};
var squadLeader = new ArmoryRole { Name = "SquadLeader" };
_ = roleManager.CreateAsync(squadLeader).Result;
}

if (!roleManager.RoleExistsAsync("StoreLeader").Result)
{
var inventoryLeader = new ArmoryRole {Name = "StoreLeader"};
var inventoryLeader = new ArmoryRole { Name = "StoreLeader" };
_ = roleManager.CreateAsync(inventoryLeader).Result;
}

Expand Down
16 changes: 10 additions & 6 deletions src/Armory/Armament/Weapons/Domain/Weapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ public class Weapon
[Required] public int ProviderCapacity { get; set; }
[Required] public int QuantityAvailable { get; set; }

public ICollection<WarMaterialAndSpecialEquipmentAssignmentFormat>
WarMaterialAndSpecialEquipmentAssignmentFormats { get; set; } =
new HashSet<WarMaterialAndSpecialEquipmentAssignmentFormat>();
public ICollection<WarMaterialAndSpecialEquipmentAssignmentFormatWeapon>
WarMaterialAndSpecialEquipmentAssignmentFormatWeapons { get; set; } =
new HashSet<WarMaterialAndSpecialEquipmentAssignmentFormatWeapon>();

public ICollection<WarMaterialDeliveryCertificateFormat> WarMaterialDeliveryCertificateFormats { get; set; } =
new HashSet<WarMaterialDeliveryCertificateFormat>();
public ICollection<WarMaterialDeliveryCertificateFormatWeapon> WarMaterialDeliveryCertificateFormatWeapons
{
get;
set;
} =
new HashSet<WarMaterialDeliveryCertificateFormatWeapon>();

public Weapon(string code, string type, string mark, string model, string caliber, string series, string lot,
int numberOfProviders, int providerCapacity, int quantityAvailable)
Expand All @@ -40,7 +44,7 @@ public Weapon(string code, string type, string mark, string model, string calibe
QuantityAvailable = quantityAvailable;
}

private Weapon()
internal Weapon()
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Armory/Armory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="ClosedXML" Version="0.95.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.8" />
<PackageReference Include="MySql.EntityFrameworkCore" Version="5.0.3.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.1" />
<PackageReference Include="QRCoder" Version="1.4.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public class WarMaterialAndSpecialEquipmentAssignmentFormat : AggregateRoot
[Required, MaxLength(256)] public string PhysicalLocation { get; set; }
[MaxLength(256)] public string Others { get; set; }

public ICollection<Weapon> Weapons { get; set; } = new HashSet<Weapon>();
public ICollection<WarMaterialAndSpecialEquipmentAssignmentFormatWeapon>
WarMaterialAndSpecialEquipmentAssignmentFormatWeapons { get; set; } =
new HashSet<WarMaterialAndSpecialEquipmentAssignmentFormatWeapon>();

public ICollection<WarMaterialAndSpecialEquipmentAssignmentFormatAmmunition>
WarMaterialAndSpecialEquipmentAssignmentFormatAmmunition { get; set; } =
Expand All @@ -52,14 +54,14 @@ public ICollection<WarMaterialAndSpecialEquipmentAssignmentFormatExplosive>
WarMaterialAndSpecialEquipmentAssignmentFormatExplosives { get; set; } =
new HashSet<WarMaterialAndSpecialEquipmentAssignmentFormatExplosive>();

[NotMapped] public ICollection<Weapon> Weapons { get; set; } = new HashSet<Weapon>();
[NotMapped] public ICollection<Ammunition> Ammunition { get; set; } = new HashSet<Ammunition>();
[NotMapped] public ICollection<Equipment> Equipments { get; set; } = new HashSet<Equipment>();
[NotMapped] public ICollection<Explosive> Explosives { get; set; } = new HashSet<Explosive>();

public WarMaterialAndSpecialEquipmentAssignmentFormat(string code, DateTime validity, string place,
DateTime date, string squadronCode, string squadCode, string troopId, Warehouse warehouse,
Purpose purpose,
DocMovement docMovement, string physicalLocation, string others)
Purpose purpose, DocMovement docMovement, string physicalLocation, string others)
{
Code = code;
Validity = validity;
Expand All @@ -77,10 +79,40 @@ public WarMaterialAndSpecialEquipmentAssignmentFormat(string code, DateTime vali

public static WarMaterialAndSpecialEquipmentAssignmentFormat Create(string code, DateTime validity,
string place, DateTime date, string squadronCode, string squadCode, string troopId, Warehouse warehouse,
Purpose purpose, DocMovement docMovement, string physicalLocation, string others)
Purpose purpose, DocMovement docMovement, string physicalLocation, string others,
IEnumerable<string> weaponCodes, IDictionary<string, int> ammunition,
IDictionary<string, int> equipments,
IDictionary<string, int> explosives)
{
return new(code, validity, place, date, squadronCode, squadCode, troopId, warehouse, purpose, docMovement,
physicalLocation, others);
var format = new WarMaterialAndSpecialEquipmentAssignmentFormat(code, validity, place, date, squadronCode,
squadCode, troopId, warehouse, purpose, docMovement, physicalLocation, others);

foreach (var weaponCode in weaponCodes)
{
format.WarMaterialAndSpecialEquipmentAssignmentFormatWeapons.Add(
WarMaterialAndSpecialEquipmentAssignmentFormatWeapon.Create(format, weaponCode));
}

foreach (var (ammunitionCode, quantity) in ammunition)
{
format.WarMaterialAndSpecialEquipmentAssignmentFormatAmmunition.Add(
Domain.WarMaterialAndSpecialEquipmentAssignmentFormatAmmunition.Create(format, ammunitionCode,
quantity));
}

foreach (var (equipmentCode, quantity) in equipments)
{
format.WarMaterialAndSpecialEquipmentAssignmentFormatEquipments.Add(
WarMaterialAndSpecialEquipmentAssignmentFormatEquipment.Create(format, equipmentCode, quantity));
}

foreach (var (explosiveCode, quantity) in explosives)
{
format.WarMaterialAndSpecialEquipmentAssignmentFormatExplosives.Add(
WarMaterialAndSpecialEquipmentAssignmentFormatExplosive.Create(format, explosiveCode, quantity));
}

return format;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ public class WarMaterialAndSpecialEquipmentAssignmentFormatAmmunition
public int Quantity { get; set; }

public WarMaterialAndSpecialEquipmentAssignmentFormatAmmunition(
int warMaterialAndSpecialEquipmentAssignmentFormatId, string ammunitionCode, int quantity)
WarMaterialAndSpecialEquipmentAssignmentFormat format, string ammunitionCode, int quantity)
{
WarMaterialAndSpecialEquipmentAssignmentFormatId = warMaterialAndSpecialEquipmentAssignmentFormatId;
Format = format;
AmmunitionCode = ammunitionCode;
Quantity = quantity;
}

private WarMaterialAndSpecialEquipmentAssignmentFormatAmmunition()
{
}

public static WarMaterialAndSpecialEquipmentAssignmentFormatAmmunition Create(
int warMaterialAndSpecialEquipmentAssignmentFormatId, string ammunitionCode, int quantity)
WarMaterialAndSpecialEquipmentAssignmentFormat format, string ammunitionCode, int quantity)
{
return new(warMaterialAndSpecialEquipmentAssignmentFormatId, ammunitionCode, quantity);
return new WarMaterialAndSpecialEquipmentAssignmentFormatAmmunition(format, ammunitionCode, quantity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ public class WarMaterialAndSpecialEquipmentAssignmentFormatEquipment
public int Quantity { get; set; }

public WarMaterialAndSpecialEquipmentAssignmentFormatEquipment(
int warMaterialAndSpecialEquipmentAssignmentFormatId, string equipmentCode, int quantity)
WarMaterialAndSpecialEquipmentAssignmentFormat format, string equipmentCode, int quantity)
{
WarMaterialAndSpecialEquipmentAssignmentFormatId = warMaterialAndSpecialEquipmentAssignmentFormatId;
Format = format;
EquipmentCode = equipmentCode;
Quantity = quantity;
}

private WarMaterialAndSpecialEquipmentAssignmentFormatEquipment()
{
}

public static WarMaterialAndSpecialEquipmentAssignmentFormatEquipment Create(
int warMaterialAndSpecialEquipmentAssignmentFormatId, string equipmentCode, int quantity)
WarMaterialAndSpecialEquipmentAssignmentFormat format, string equipmentCode, int quantity)
{
return new(warMaterialAndSpecialEquipmentAssignmentFormatId, equipmentCode, quantity);
return new WarMaterialAndSpecialEquipmentAssignmentFormatEquipment(format, equipmentCode, quantity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ public class WarMaterialAndSpecialEquipmentAssignmentFormatExplosive
public int Quantity { get; set; }

public WarMaterialAndSpecialEquipmentAssignmentFormatExplosive(
int warMaterialAndSpecialEquipmentAssignmentFormatId, string explosiveCode, int quantity)
WarMaterialAndSpecialEquipmentAssignmentFormat format, string explosiveCode, int quantity)
{
WarMaterialAndSpecialEquipmentAssignmentFormatId = warMaterialAndSpecialEquipmentAssignmentFormatId;
Format = format;
ExplosiveCode = explosiveCode;
Quantity = quantity;
}

private WarMaterialAndSpecialEquipmentAssignmentFormatExplosive()
{
}

public static WarMaterialAndSpecialEquipmentAssignmentFormatExplosive Create(
int warMaterialAndSpecialEquipmentAssignmentFormatId, string explosiveCode, int quantity)
WarMaterialAndSpecialEquipmentAssignmentFormat format, string explosiveCode, int quantity)
{
return new(warMaterialAndSpecialEquipmentAssignmentFormatId, explosiveCode, quantity);
return new WarMaterialAndSpecialEquipmentAssignmentFormatExplosive(format, explosiveCode, quantity);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.ComponentModel.DataAnnotations.Schema;
using Armory.Armament.Weapons.Domain;

namespace Armory.Formats.WarMaterialAndSpecialEquipmentAssignmentFormats.Domain
{
public class WarMaterialAndSpecialEquipmentAssignmentFormatWeapon
{
public int WarMaterialAndSpecialEquipmentAssignmentFormatId { get; set; }

[ForeignKey("WarMaterialAndSpecialEquipmentAssignmentFormatId")]
public WarMaterialAndSpecialEquipmentAssignmentFormat Format { get; set; }

public string WeaponCode { get; set; }
[ForeignKey("WeaponCode")] public Weapon Weapon { get; set; }

public WarMaterialAndSpecialEquipmentAssignmentFormatWeapon(
WarMaterialAndSpecialEquipmentAssignmentFormat format, string weaponCode)
{
Format = format;
WeaponCode = weaponCode;
}

private WarMaterialAndSpecialEquipmentAssignmentFormatWeapon()
{
}

public static WarMaterialAndSpecialEquipmentAssignmentFormatWeapon Create(
WarMaterialAndSpecialEquipmentAssignmentFormat format, string weaponCode)
{
return new WarMaterialAndSpecialEquipmentAssignmentFormatWeapon(format, weaponCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public class WarMaterialDeliveryCertificateFormat : AggregateRoot
[Required] public string TroopId { get; set; }
[ForeignKey("TroopId")] public Troop Applicant { get; set; }

public ICollection<Weapon> Weapons { get; set; } = new HashSet<Weapon>();
public ICollection<WarMaterialDeliveryCertificateFormatWeapon> WarMaterialDeliveryCertificateFormatWeapons
{
get;
set;
} = new HashSet<WarMaterialDeliveryCertificateFormatWeapon>();

public ICollection<WarMaterialDeliveryCertificateFormatAmmunition>
WarMaterialDeliveryCertificateFormatAmmunition { get; set; } =
Expand All @@ -45,6 +49,7 @@ public ICollection<WarMaterialDeliveryCertificateFormatExplosive>
WarMaterialDeliveryCertificateFormatExplosives { get; set; } =
new HashSet<WarMaterialDeliveryCertificateFormatExplosive>();

[NotMapped] public ICollection<Weapon> Weapons { get; set; } = new HashSet<Weapon>();
[NotMapped] public ICollection<Ammunition> Ammunition { get; set; } = new HashSet<Ammunition>();
[NotMapped] public ICollection<Equipment> Equipments { get; set; } = new HashSet<Equipment>();
[NotMapped] public ICollection<Explosive> Explosives { get; set; } = new HashSet<Explosive>();
Expand All @@ -64,7 +69,7 @@ public WarMaterialDeliveryCertificateFormat(string code, DateTime validity, stri
public static WarMaterialDeliveryCertificateFormat Create(string code, DateTime validity, string place,
DateTime date, string squadronCode, string squadCode, string troopId)
{
return new(code, validity, place, date, squadCode, squadCode, troopId);
return new WarMaterialDeliveryCertificateFormat(code, validity, place, date, squadCode, squadCode, troopId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.ComponentModel.DataAnnotations.Schema;
using Armory.Armament.Weapons.Domain;

namespace Armory.Formats.WarMaterialDeliveryCertificateFormats.Domain
{
public class WarMaterialDeliveryCertificateFormatWeapon
{
public int WarMaterialDeliveryCertificateFormatId { get; set; }

[ForeignKey("WarMaterialDeliveryCertificateFormatId")]
public WarMaterialDeliveryCertificateFormat Format { get; set; }

public string WeaponCode { get; set; }
[ForeignKey("ExplosiveCode")] public Weapon Weapon { get; set; }

public WarMaterialDeliveryCertificateFormatWeapon(WarMaterialDeliveryCertificateFormat format,
string weaponCode)
{
Format = format;
WeaponCode = weaponCode;
}

private WarMaterialDeliveryCertificateFormatWeapon()
{
}

public static WarMaterialDeliveryCertificateFormatWeapon Create(WarMaterialDeliveryCertificateFormat format,
string weaponCode)
{
return new WarMaterialDeliveryCertificateFormatWeapon(format, weaponCode);
}
}
}
Loading

0 comments on commit 6669333

Please sign in to comment.