Add project files.
This commit is contained in:
155
OemanTrader.EntityFramework/Migrations/20220508202548_initial.Designer.cs
generated
Normal file
155
OemanTrader.EntityFramework/Migrations/20220508202548_initial.Designer.cs
generated
Normal file
@ -0,0 +1,155 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using OemanTrader.EntityFramework;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace OemanTrader.EntityFramework.Migrations
|
||||
{
|
||||
[DbContext(typeof(OemanTraderDbContext))]
|
||||
[Migration("20220508202548_initial")]
|
||||
partial class initial
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.Account", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<int>("AccountHolderId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Balance")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AccountHolderId");
|
||||
|
||||
b.ToTable("Accounts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.AssetTransaction", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<int>("AccountId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateProcessed")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<bool>("IsPurchase")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("ShareAmount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AccountId");
|
||||
|
||||
b.ToTable("AssetTransactions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<DateTime>("DateJoined")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.Account", b =>
|
||||
{
|
||||
b.HasOne("OemanTrader.Domain.Models.User", "AccountHolder")
|
||||
.WithMany()
|
||||
.HasForeignKey("AccountHolderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AccountHolder");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.AssetTransaction", b =>
|
||||
{
|
||||
b.HasOne("OemanTrader.Domain.Models.Account", "Account")
|
||||
.WithMany("AssetTransactions")
|
||||
.HasForeignKey("AccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.OwnsOne("OemanTrader.Domain.Models.Stock", "Stock", b1 =>
|
||||
{
|
||||
b1.Property<int>("AssetTransactionId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b1.Property<double>("PricePerShare")
|
||||
.HasColumnType("float");
|
||||
|
||||
b1.Property<string>("Symbol")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b1.HasKey("AssetTransactionId");
|
||||
|
||||
b1.ToTable("AssetTransactions");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AssetTransactionId");
|
||||
});
|
||||
|
||||
b.Navigation("Account");
|
||||
|
||||
b.Navigation("Stock")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.Account", b =>
|
||||
{
|
||||
b.Navigation("AssetTransactions");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace OemanTrader.EntityFramework.Migrations
|
||||
{
|
||||
public partial class initial : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
UserName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateJoined = table.Column<DateTime>(type: "datetime2", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Accounts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
AccountHolderId = table.Column<int>(type: "int", nullable: false),
|
||||
Balance = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Accounts", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Accounts_Users_AccountHolderId",
|
||||
column: x => x.AccountHolderId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AssetTransactions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
AccountId = table.Column<int>(type: "int", nullable: false),
|
||||
IsPurchase = table.Column<bool>(type: "bit", nullable: false),
|
||||
Stock_Symbol = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Stock_PricePerShare = table.Column<double>(type: "float", nullable: false),
|
||||
ShareAmount = table.Column<int>(type: "int", nullable: false),
|
||||
DateProcessed = table.Column<DateTime>(type: "datetime2", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AssetTransactions", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AssetTransactions_Accounts_AccountId",
|
||||
column: x => x.AccountId,
|
||||
principalTable: "Accounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Accounts_AccountHolderId",
|
||||
table: "Accounts",
|
||||
column: "AccountHolderId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AssetTransactions_AccountId",
|
||||
table: "AssetTransactions",
|
||||
column: "AccountId");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AssetTransactions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Accounts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
}
|
||||
}
|
||||
}
|
||||
155
OemanTrader.EntityFramework/Migrations/20220519211347_stock-to-asset.Designer.cs
generated
Normal file
155
OemanTrader.EntityFramework/Migrations/20220519211347_stock-to-asset.Designer.cs
generated
Normal file
@ -0,0 +1,155 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using OemanTrader.EntityFramework;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace OemanTrader.EntityFramework.Migrations
|
||||
{
|
||||
[DbContext(typeof(OemanTraderDbContext))]
|
||||
[Migration("20220519211347_stock-to-asset")]
|
||||
partial class stocktoasset
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.Account", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<int>("AccountHolderId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Balance")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AccountHolderId");
|
||||
|
||||
b.ToTable("Accounts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.AssetTransaction", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<int>("AccountId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateProcessed")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<bool>("IsPurchase")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("ShareAmount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AccountId");
|
||||
|
||||
b.ToTable("AssetTransactions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<DateTime>("DateJoined")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.Account", b =>
|
||||
{
|
||||
b.HasOne("OemanTrader.Domain.Models.User", "AccountHolder")
|
||||
.WithMany()
|
||||
.HasForeignKey("AccountHolderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AccountHolder");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.AssetTransaction", b =>
|
||||
{
|
||||
b.HasOne("OemanTrader.Domain.Models.Account", "Account")
|
||||
.WithMany("AssetTransactions")
|
||||
.HasForeignKey("AccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.OwnsOne("OemanTrader.Domain.Models.Asset", "Asset", b1 =>
|
||||
{
|
||||
b1.Property<int>("AssetTransactionId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b1.Property<double>("PricePerShare")
|
||||
.HasColumnType("float");
|
||||
|
||||
b1.Property<string>("Symbol")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b1.HasKey("AssetTransactionId");
|
||||
|
||||
b1.ToTable("AssetTransactions");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AssetTransactionId");
|
||||
});
|
||||
|
||||
b.Navigation("Account");
|
||||
|
||||
b.Navigation("Asset")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.Account", b =>
|
||||
{
|
||||
b.Navigation("AssetTransactions");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace OemanTrader.EntityFramework.Migrations
|
||||
{
|
||||
public partial class stocktoasset : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "Stock_Symbol",
|
||||
table: "AssetTransactions",
|
||||
newName: "Asset_Symbol");
|
||||
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "Stock_PricePerShare",
|
||||
table: "AssetTransactions",
|
||||
newName: "Asset_PricePerShare");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "Asset_Symbol",
|
||||
table: "AssetTransactions",
|
||||
newName: "Stock_Symbol");
|
||||
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "Asset_PricePerShare",
|
||||
table: "AssetTransactions",
|
||||
newName: "Stock_PricePerShare");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,153 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using OemanTrader.EntityFramework;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace OemanTrader.EntityFramework.Migrations
|
||||
{
|
||||
[DbContext(typeof(OemanTraderDbContext))]
|
||||
partial class OemanTraderDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.Account", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<int>("AccountHolderId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Balance")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AccountHolderId");
|
||||
|
||||
b.ToTable("Accounts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.AssetTransaction", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<int>("AccountId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateProcessed")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<bool>("IsPurchase")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("ShareAmount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AccountId");
|
||||
|
||||
b.ToTable("AssetTransactions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<DateTime>("DateJoined")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.Account", b =>
|
||||
{
|
||||
b.HasOne("OemanTrader.Domain.Models.User", "AccountHolder")
|
||||
.WithMany()
|
||||
.HasForeignKey("AccountHolderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AccountHolder");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.AssetTransaction", b =>
|
||||
{
|
||||
b.HasOne("OemanTrader.Domain.Models.Account", "Account")
|
||||
.WithMany("AssetTransactions")
|
||||
.HasForeignKey("AccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.OwnsOne("OemanTrader.Domain.Models.Asset", "Asset", b1 =>
|
||||
{
|
||||
b1.Property<int>("AssetTransactionId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b1.Property<double>("PricePerShare")
|
||||
.HasColumnType("float");
|
||||
|
||||
b1.Property<string>("Symbol")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b1.HasKey("AssetTransactionId");
|
||||
|
||||
b1.ToTable("AssetTransactions");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AssetTransactionId");
|
||||
});
|
||||
|
||||
b.Navigation("Account");
|
||||
|
||||
b.Navigation("Asset")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OemanTrader.Domain.Models.Account", b =>
|
||||
{
|
||||
b.Navigation("AssetTransactions");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OemanTrader.Domain\OemanTrader.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
26
OemanTrader.EntityFramework/OemanTraderDbContext.cs
Normal file
26
OemanTrader.EntityFramework/OemanTraderDbContext.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OemanTrader.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OemanTrader.EntityFramework
|
||||
{
|
||||
public class OemanTraderDbContext : DbContext
|
||||
{
|
||||
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<Account> Accounts { get; set; }
|
||||
public DbSet<AssetTransaction> AssetTransactions { get; set; }
|
||||
public OemanTraderDbContext(DbContextOptions options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<AssetTransaction>().OwnsOne(x => x.Asset);
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
20
OemanTrader.EntityFramework/OemanTraderDbContextFactory.cs
Normal file
20
OemanTrader.EntityFramework/OemanTraderDbContextFactory.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
namespace OemanTrader.EntityFramework
|
||||
{
|
||||
public class OemanTraderDbContextFactory : IDesignTimeDbContextFactory<OemanTraderDbContext>
|
||||
{
|
||||
public OemanTraderDbContext CreateDbContext(string[] args = null)
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<OemanTraderDbContext>();
|
||||
options.UseSqlServer("Server=oemansv7win;Initial Catalog=OemanTraderDB;Persist Security Info=True;User ID=sa;Password=SAOemansv7SA;");
|
||||
return new OemanTraderDbContext(options.Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
73
OemanTrader.EntityFramework/Services/GenericDataService.cs
Normal file
73
OemanTrader.EntityFramework/Services/GenericDataService.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using OemanTrader.Domain.Models;
|
||||
using OemanTrader.Domain.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OemanTrader.EntityFramework.Services
|
||||
{
|
||||
public class GenericDataService<T> : IDataService<T> where T : DomainObject
|
||||
{
|
||||
private readonly OemanTraderDbContextFactory _contextFactory;
|
||||
|
||||
public GenericDataService(OemanTraderDbContextFactory contextFactory)
|
||||
{
|
||||
_contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
public async Task<T> Create(T entity)
|
||||
{
|
||||
using (var context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
EntityEntry<T> createdResult = await context.Set<T>().AddAsync(entity);
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
return createdResult.Entity;
|
||||
}
|
||||
}
|
||||
public async Task<bool> Delete(int id)
|
||||
{
|
||||
using (var context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
|
||||
T entity = await context.Set<T>().FirstOrDefaultAsync((e) => e.Id == id);
|
||||
context.Set<T>().Remove(entity);
|
||||
await context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<T> Get(int id)
|
||||
{
|
||||
using (var context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
T entity = await context.Set<T>().FirstOrDefaultAsync((e) => e.Id == id);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<T>> GetAll()
|
||||
{
|
||||
using (var context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
IEnumerable<T> entities = await context.Set<T>().ToListAsync();
|
||||
return entities;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<T> Update(int Id, T entity)
|
||||
{
|
||||
using (var context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
entity.Id = Id;
|
||||
context.Set<T>().Update(entity);
|
||||
await context.SaveChangesAsync();
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user