Upload project.

This commit is contained in:
StevenJW
2020-06-09 21:21:37 +01:00
parent 251cec2dac
commit 15556e92aa
196 changed files with 86759 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
// <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 ThAmCo.Stock.Data;
namespace ThAmCo.Stock.Data.Migrations
{
[DbContext(typeof(StockDbContext))]
[Migration("20191205144118_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("ThAmCo.Stock.Data.Price", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<DateTime>("Date");
b.Property<double>("ProductPrice");
b.Property<int>("ProductStockId");
b.HasKey("Id");
b.ToTable("Prices");
b.HasData(
new
{
Id = 1,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 9.9900000000000002,
ProductStockId = 1
},
new
{
Id = 2,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 8.9900000000000002,
ProductStockId = 1
},
new
{
Id = 3,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 17.989999999999998,
ProductStockId = 2
});
});
modelBuilder.Entity("ThAmCo.Stock.Data.ProductStock", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("PriceId");
b.Property<int>("ProductId");
b.Property<int>("Stock");
b.HasKey("Id");
b.ToTable("ProductStocks");
b.HasData(
new
{
Id = 1,
PriceId = 2,
ProductId = 1,
Stock = 4
},
new
{
Id = 2,
PriceId = 3,
ProductId = 2,
Stock = 42
});
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,70 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace ThAmCo.Stock.Data.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Prices",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
ProductStockId = table.Column<int>(nullable: false),
ProductPrice = table.Column<double>(nullable: false),
Date = table.Column<DateTime>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Prices", x => x.Id);
});
migrationBuilder.CreateTable(
name: "ProductStocks",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
ProductId = table.Column<int>(nullable: false),
Stock = table.Column<int>(nullable: false),
PriceId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ProductStocks", x => x.Id);
});
migrationBuilder.InsertData(
table: "Prices",
columns: new[] { "Id", "Date", "ProductPrice", "ProductStockId" },
values: new object[,]
{
{ 1, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 9.9900000000000002, 1 },
{ 2, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 8.9900000000000002, 1 },
{ 3, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 17.989999999999998, 2 }
});
migrationBuilder.InsertData(
table: "ProductStocks",
columns: new[] { "Id", "PriceId", "ProductId", "Stock" },
values: new object[,]
{
{ 1, 2, 1, 4 },
{ 2, 3, 2, 42 }
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Prices");
migrationBuilder.DropTable(
name: "ProductStocks");
}
}
}

View File

@@ -0,0 +1,169 @@
// <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 ThAmCo.Stock.Data;
namespace ThAmCo.Stock.Data.Migrations
{
[DbContext(typeof(StockDbContext))]
[Migration("20191218210759_TestDataProducts")]
partial class TestDataProducts
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("ThAmCo.Stock.Data.Price", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<DateTime>("Date");
b.Property<double>("ProductPrice");
b.Property<int>("ProductStockId");
b.HasKey("Id");
b.ToTable("Prices");
b.HasData(
new
{
Id = 1,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 9.9900000000000002,
ProductStockId = 1
},
new
{
Id = 2,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 8.9900000000000002,
ProductStockId = 1
},
new
{
Id = 3,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 17.989999999999998,
ProductStockId = 2
},
new
{
Id = 4,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 23.0,
ProductStockId = 3
},
new
{
Id = 5,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 2.9900000000000002,
ProductStockId = 4
},
new
{
Id = 6,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 49.630000000000003,
ProductStockId = 5
},
new
{
Id = 7,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 4.5599999999999996,
ProductStockId = 6
},
new
{
Id = 8,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 10.01,
ProductStockId = 7
});
});
modelBuilder.Entity("ThAmCo.Stock.Data.ProductStock", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("PriceId");
b.Property<int>("ProductId");
b.Property<int>("Stock");
b.HasKey("Id");
b.ToTable("ProductStocks");
b.HasData(
new
{
Id = 1,
PriceId = 2,
ProductId = 1,
Stock = 4
},
new
{
Id = 2,
PriceId = 3,
ProductId = 2,
Stock = 42
},
new
{
Id = 3,
PriceId = 4,
ProductId = 3,
Stock = 32
},
new
{
Id = 4,
PriceId = 5,
ProductId = 4,
Stock = 13
},
new
{
Id = 5,
PriceId = 6,
ProductId = 5,
Stock = 0
},
new
{
Id = 6,
PriceId = 7,
ProductId = 6,
Stock = 1
},
new
{
Id = 7,
PriceId = 8,
ProductId = 7,
Stock = 49
});
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,88 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace ThAmCo.Stock.Data.Migrations
{
public partial class TestDataProducts : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "Prices",
columns: new[] { "Id", "Date", "ProductPrice", "ProductStockId" },
values: new object[,]
{
{ 4, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 23.0, 3 },
{ 5, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 2.9900000000000002, 4 },
{ 6, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 49.630000000000003, 5 },
{ 7, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 4.5599999999999996, 6 },
{ 8, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 10.01, 7 }
});
migrationBuilder.InsertData(
table: "ProductStocks",
columns: new[] { "Id", "PriceId", "ProductId", "Stock" },
values: new object[,]
{
{ 3, 4, 3, 32 },
{ 4, 5, 4, 13 },
{ 5, 6, 5, 0 },
{ 6, 7, 6, 1 },
{ 7, 8, 7, 49 }
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Prices",
keyColumn: "Id",
keyValue: 4);
migrationBuilder.DeleteData(
table: "Prices",
keyColumn: "Id",
keyValue: 5);
migrationBuilder.DeleteData(
table: "Prices",
keyColumn: "Id",
keyValue: 6);
migrationBuilder.DeleteData(
table: "Prices",
keyColumn: "Id",
keyValue: 7);
migrationBuilder.DeleteData(
table: "Prices",
keyColumn: "Id",
keyValue: 8);
migrationBuilder.DeleteData(
table: "ProductStocks",
keyColumn: "Id",
keyValue: 3);
migrationBuilder.DeleteData(
table: "ProductStocks",
keyColumn: "Id",
keyValue: 4);
migrationBuilder.DeleteData(
table: "ProductStocks",
keyColumn: "Id",
keyValue: 5);
migrationBuilder.DeleteData(
table: "ProductStocks",
keyColumn: "Id",
keyValue: 6);
migrationBuilder.DeleteData(
table: "ProductStocks",
keyColumn: "Id",
keyValue: 7);
}
}
}

View File

@@ -0,0 +1,194 @@
// <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 ThAmCo.Stock.Data;
namespace ThAmCo.Stock.Data.Migrations
{
[DbContext(typeof(StockDbContext))]
[Migration("20200102001637_AddBaseOrderRequests")]
partial class AddBaseOrderRequests
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("ThAmCo.Stock.Data.OrderRequest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("Approved");
b.Property<DateTime>("ApprovedTime");
b.Property<bool>("Deleted");
b.Property<double>("Price");
b.Property<int>("ProductId");
b.Property<int>("Quantity");
b.Property<DateTime>("SubmittedTime");
b.HasKey("Id");
b.ToTable("OrderRequests");
});
modelBuilder.Entity("ThAmCo.Stock.Data.Price", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<DateTime>("Date");
b.Property<double>("ProductPrice");
b.Property<int>("ProductStockId");
b.HasKey("Id");
b.ToTable("Prices");
b.HasData(
new
{
Id = 1,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 9.9900000000000002,
ProductStockId = 1
},
new
{
Id = 2,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 8.9900000000000002,
ProductStockId = 1
},
new
{
Id = 3,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 17.989999999999998,
ProductStockId = 2
},
new
{
Id = 4,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 23.0,
ProductStockId = 3
},
new
{
Id = 5,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 2.9900000000000002,
ProductStockId = 4
},
new
{
Id = 6,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 49.630000000000003,
ProductStockId = 5
},
new
{
Id = 7,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 4.5599999999999996,
ProductStockId = 6
},
new
{
Id = 8,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 10.01,
ProductStockId = 7
});
});
modelBuilder.Entity("ThAmCo.Stock.Data.ProductStock", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("PriceId");
b.Property<int>("ProductId");
b.Property<int>("Stock");
b.HasKey("Id");
b.ToTable("ProductStocks");
b.HasData(
new
{
Id = 1,
PriceId = 2,
ProductId = 1,
Stock = 4
},
new
{
Id = 2,
PriceId = 3,
ProductId = 2,
Stock = 42
},
new
{
Id = 3,
PriceId = 4,
ProductId = 3,
Stock = 32
},
new
{
Id = 4,
PriceId = 5,
ProductId = 4,
Stock = 13
},
new
{
Id = 5,
PriceId = 6,
ProductId = 5,
Stock = 0
},
new
{
Id = 6,
PriceId = 7,
ProductId = 6,
Stock = 1
},
new
{
Id = 7,
PriceId = 8,
ProductId = 7,
Stock = 49
});
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace ThAmCo.Stock.Data.Migrations
{
public partial class AddBaseOrderRequests : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "OrderRequests",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
ProductId = table.Column<int>(nullable: false),
Quantity = table.Column<int>(nullable: false),
Price = table.Column<double>(nullable: false),
SubmittedTime = table.Column<DateTime>(nullable: false),
Approved = table.Column<bool>(nullable: false),
ApprovedTime = table.Column<DateTime>(nullable: false),
Deleted = table.Column<bool>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_OrderRequests", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "OrderRequests");
}
}
}

View File

@@ -0,0 +1,194 @@
// <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 ThAmCo.Stock.Data;
namespace ThAmCo.Stock.Data.Migrations
{
[DbContext(typeof(StockDbContext))]
[Migration("20200102011301_MakeApprovedDateNullable")]
partial class MakeApprovedDateNullable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("ThAmCo.Stock.Data.OrderRequest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("Approved");
b.Property<DateTime?>("ApprovedTime");
b.Property<bool>("Deleted");
b.Property<double>("Price");
b.Property<int>("ProductId");
b.Property<int>("Quantity");
b.Property<DateTime>("SubmittedTime");
b.HasKey("Id");
b.ToTable("OrderRequests");
});
modelBuilder.Entity("ThAmCo.Stock.Data.Price", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<DateTime>("Date");
b.Property<double>("ProductPrice");
b.Property<int>("ProductStockId");
b.HasKey("Id");
b.ToTable("Prices");
b.HasData(
new
{
Id = 1,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 9.9900000000000002,
ProductStockId = 1
},
new
{
Id = 2,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 8.9900000000000002,
ProductStockId = 1
},
new
{
Id = 3,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 17.989999999999998,
ProductStockId = 2
},
new
{
Id = 4,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 23.0,
ProductStockId = 3
},
new
{
Id = 5,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 2.9900000000000002,
ProductStockId = 4
},
new
{
Id = 6,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 49.630000000000003,
ProductStockId = 5
},
new
{
Id = 7,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 4.5599999999999996,
ProductStockId = 6
},
new
{
Id = 8,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 10.01,
ProductStockId = 7
});
});
modelBuilder.Entity("ThAmCo.Stock.Data.ProductStock", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("PriceId");
b.Property<int>("ProductId");
b.Property<int>("Stock");
b.HasKey("Id");
b.ToTable("ProductStocks");
b.HasData(
new
{
Id = 1,
PriceId = 2,
ProductId = 1,
Stock = 4
},
new
{
Id = 2,
PriceId = 3,
ProductId = 2,
Stock = 42
},
new
{
Id = 3,
PriceId = 4,
ProductId = 3,
Stock = 32
},
new
{
Id = 4,
PriceId = 5,
ProductId = 4,
Stock = 13
},
new
{
Id = 5,
PriceId = 6,
ProductId = 5,
Stock = 0
},
new
{
Id = 6,
PriceId = 7,
ProductId = 6,
Stock = 1
},
new
{
Id = 7,
PriceId = 8,
ProductId = 7,
Stock = 49
});
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,27 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace ThAmCo.Stock.Data.Migrations
{
public partial class MakeApprovedDateNullable : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "ApprovedTime",
table: "OrderRequests",
nullable: true,
oldClrType: typeof(DateTime));
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "ApprovedTime",
table: "OrderRequests",
nullable: false,
oldClrType: typeof(DateTime),
oldNullable: true);
}
}
}

View File

@@ -0,0 +1,196 @@
// <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 ThAmCo.Stock.Data;
namespace ThAmCo.Stock.Data.Migrations
{
[DbContext(typeof(StockDbContext))]
[Migration("20200102172432_AddSupplierToOrderRequest")]
partial class AddSupplierToOrderRequest
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("ThAmCo.Stock.Data.OrderRequest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("Approved");
b.Property<DateTime?>("ApprovedTime");
b.Property<bool>("Deleted");
b.Property<double>("Price");
b.Property<int>("ProductId");
b.Property<int>("Quantity");
b.Property<DateTime>("SubmittedTime");
b.Property<string>("Supplier");
b.HasKey("Id");
b.ToTable("OrderRequests");
});
modelBuilder.Entity("ThAmCo.Stock.Data.Price", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<DateTime>("Date");
b.Property<double>("ProductPrice");
b.Property<int>("ProductStockId");
b.HasKey("Id");
b.ToTable("Prices");
b.HasData(
new
{
Id = 1,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 9.9900000000000002,
ProductStockId = 1
},
new
{
Id = 2,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 8.9900000000000002,
ProductStockId = 1
},
new
{
Id = 3,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 17.989999999999998,
ProductStockId = 2
},
new
{
Id = 4,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 23.0,
ProductStockId = 3
},
new
{
Id = 5,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 2.9900000000000002,
ProductStockId = 4
},
new
{
Id = 6,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 49.630000000000003,
ProductStockId = 5
},
new
{
Id = 7,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 4.5599999999999996,
ProductStockId = 6
},
new
{
Id = 8,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 10.01,
ProductStockId = 7
});
});
modelBuilder.Entity("ThAmCo.Stock.Data.ProductStock", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("PriceId");
b.Property<int>("ProductId");
b.Property<int>("Stock");
b.HasKey("Id");
b.ToTable("ProductStocks");
b.HasData(
new
{
Id = 1,
PriceId = 2,
ProductId = 1,
Stock = 4
},
new
{
Id = 2,
PriceId = 3,
ProductId = 2,
Stock = 42
},
new
{
Id = 3,
PriceId = 4,
ProductId = 3,
Stock = 32
},
new
{
Id = 4,
PriceId = 5,
ProductId = 4,
Stock = 13
},
new
{
Id = 5,
PriceId = 6,
ProductId = 5,
Stock = 0
},
new
{
Id = 6,
PriceId = 7,
ProductId = 6,
Stock = 1
},
new
{
Id = 7,
PriceId = 8,
ProductId = 7,
Stock = 49
});
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace ThAmCo.Stock.Data.Migrations
{
public partial class AddSupplierToOrderRequest : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Supplier",
table: "OrderRequests",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Supplier",
table: "OrderRequests");
}
}
}

View File

@@ -0,0 +1,194 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ThAmCo.Stock.Data;
namespace ThAmCo.Stock.Data.Migrations
{
[DbContext(typeof(StockDbContext))]
partial class StockDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("ThAmCo.Stock.Data.OrderRequest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("Approved");
b.Property<DateTime?>("ApprovedTime");
b.Property<bool>("Deleted");
b.Property<double>("Price");
b.Property<int>("ProductId");
b.Property<int>("Quantity");
b.Property<DateTime>("SubmittedTime");
b.Property<string>("Supplier");
b.HasKey("Id");
b.ToTable("OrderRequests");
});
modelBuilder.Entity("ThAmCo.Stock.Data.Price", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<DateTime>("Date");
b.Property<double>("ProductPrice");
b.Property<int>("ProductStockId");
b.HasKey("Id");
b.ToTable("Prices");
b.HasData(
new
{
Id = 1,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 9.9900000000000002,
ProductStockId = 1
},
new
{
Id = 2,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 8.9900000000000002,
ProductStockId = 1
},
new
{
Id = 3,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 17.989999999999998,
ProductStockId = 2
},
new
{
Id = 4,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 23.0,
ProductStockId = 3
},
new
{
Id = 5,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 2.9900000000000002,
ProductStockId = 4
},
new
{
Id = 6,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 49.630000000000003,
ProductStockId = 5
},
new
{
Id = 7,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 4.5599999999999996,
ProductStockId = 6
},
new
{
Id = 8,
Date = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
ProductPrice = 10.01,
ProductStockId = 7
});
});
modelBuilder.Entity("ThAmCo.Stock.Data.ProductStock", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("PriceId");
b.Property<int>("ProductId");
b.Property<int>("Stock");
b.HasKey("Id");
b.ToTable("ProductStocks");
b.HasData(
new
{
Id = 1,
PriceId = 2,
ProductId = 1,
Stock = 4
},
new
{
Id = 2,
PriceId = 3,
ProductId = 2,
Stock = 42
},
new
{
Id = 3,
PriceId = 4,
ProductId = 3,
Stock = 32
},
new
{
Id = 4,
PriceId = 5,
ProductId = 4,
Stock = 13
},
new
{
Id = 5,
PriceId = 6,
ProductId = 5,
Stock = 0
},
new
{
Id = 6,
PriceId = 7,
ProductId = 6,
Stock = 1
},
new
{
Id = 7,
PriceId = 8,
ProductId = 7,
Stock = 49
});
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
namespace ThAmCo.Stock.Data
{
public class OrderRequest
{
public int Id { get; set; }
public int ProductId { get; set; }
public string Supplier { get; set; }
public int Quantity { get; set; }
public double Price { get; set; }
public DateTime SubmittedTime { get; set; }
public bool Approved { get; set; }
public DateTime? ApprovedTime { get; set; }
public bool Deleted { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ThAmCo.Stock.Data
{
public class Price
{
public int Id { get; set; }
public int ProductStockId { get; set; }
public double ProductPrice { get; set; }
public DateTime Date { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ThAmCo.Stock.Data
{
public class ProductStock
{
public int Id { get; set; }
public int ProductId { get; set; }
public int Stock { get; set; }
public int PriceId { get; set; }
}
}

View File

@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using ThAmCo.Stock.Models.Dto;
namespace ThAmCo.Stock.Data.StockContext
{
public interface IStockContext
{
Task<IEnumerable<ProductStockDto>> GetAll();
Task<IEnumerable<Price>> GetAllPrices();
Task<ProductStockDto> GetProductStockAsync(int id);
Task<IEnumerable<OrderRequest>> GetAllOrderRequests();
Task<OrderRequest> GetOrderRequest(int id);
void AddProductStockAsync();
Price AddPriceAsync(Price price);
void AddOrderRequest(OrderRequest order);
void UpdateProductStockAsync(ProductStock productStock);
void UpdateOrderRequest(OrderRequest orderRequest);
void ApproveOrderRequest(int id);
void SaveAndUpdateContext();
}
}

View File

@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ThAmCo.Stock.Models.Dto;
namespace ThAmCo.Stock.Data.StockContext
{
public class MockStockContext : IStockContext
{
private readonly List<ProductStock> _productStocks;
private readonly List<Price> _prices;
private readonly List<OrderRequest> _orderRequests;
public MockStockContext(List<ProductStock> productStocks, List<Price> prices, List<OrderRequest> orderRequests)
{
_productStocks = productStocks;
_prices = prices;
_orderRequests = orderRequests;
}
public Task<IEnumerable<ProductStockDto>> GetAll()
{
var productStocks = new List<ProductStockDto>();
//Janky List handling; Not linked so have to do this...
foreach (var p in _productStocks)
{
productStocks.Add(new ProductStockDto
{
ProductStock = p,
Price = _prices.FirstOrDefault(price => price.Id == p.PriceId)
});
}
return Task.FromResult(productStocks.AsEnumerable());
}
public Task<IEnumerable<Price>> GetAllPrices()
{
return Task.FromResult(_prices.AsEnumerable());
}
public Task<ProductStockDto> GetProductStockAsync(int id)
{
var prod = _productStocks.FirstOrDefault(p => p.Id == id);
if (prod == null)
return Task.FromResult<ProductStockDto>(null);
return Task.FromResult(new ProductStockDto
{
ProductStock = prod,
Price = _prices.FirstOrDefault(p => p.Id == prod.PriceId)
});
}
public Task<IEnumerable<OrderRequest>> GetAllOrderRequests()
{
return Task.FromResult(_orderRequests.AsEnumerable());
}
public Task<OrderRequest> GetOrderRequest(int id)
{
return Task.FromResult(_orderRequests.FirstOrDefault(or => or.Id == id));
}
public void AddProductStockAsync()
{
throw new System.NotImplementedException();
}
public Price AddPriceAsync(Price price)
{
price.Id = _prices.OrderByDescending(p => p.Id).First().Id + 1;
_prices.Add(price);
return price;
}
public void AddOrderRequest(OrderRequest order)
{
_orderRequests.Add(order);
}
public void UpdateProductStockAsync(ProductStock productStock)
{
var update = _productStocks.FirstOrDefault(p => p.Id == productStock.Id);
if (update != null && productStock != null)
update.Id = productStock.Id;
}
public void UpdateOrderRequest(OrderRequest orderRequest)
{
var update = _orderRequests.FirstOrDefault(or => or.Id == orderRequest.Id);
if (update != null)
update = orderRequest;
}
public void ApproveOrderRequest(int id)
{
var approve = _orderRequests.FirstOrDefault(or => or.Id == id);
if (approve != null)
{
approve.Approved = true;
approve.ApprovedTime = DateTime.Now;
}
}
public void SaveAndUpdateContext()
{
throw new System.NotImplementedException();
}
}
}

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using ThAmCo.Stock.Models.Dto;
namespace ThAmCo.Stock.Data.StockContext
{
public class StockContext : IStockContext
{
private readonly StockDbContext _context;
public StockContext(StockDbContext context)
{
_context = context;
}
public async Task<IEnumerable<ProductStockDto>> GetAll()
{
var productStocks = new List<ProductStockDto>();
//Janky Database handling; Not linked so have to do this...
foreach (var p in _context.ProductStocks)
{
productStocks.Add(new ProductStockDto
{
ProductStock = p,
Price = await _context.Prices.FirstOrDefaultAsync(price => price.Id == p.PriceId)
});
}
return productStocks;
}
public async Task<IEnumerable<Price>> GetAllPrices()
{
return await _context.Prices.ToListAsync();
}
public async Task<ProductStockDto> GetProductStockAsync(int id)
{
var prod = await _context.ProductStocks.FirstOrDefaultAsync(p => p.Id == id);
return new ProductStockDto
{
ProductStock = prod,
Price = await _context.Prices.FirstOrDefaultAsync(p => p.Id == prod.PriceId)
};
}
public async Task<IEnumerable<OrderRequest>> GetAllOrderRequests()
{
return await _context.OrderRequests.ToListAsync();
}
public async Task<OrderRequest> GetOrderRequest(int id)
{
return await _context.OrderRequests.FirstOrDefaultAsync(or => or.Id == id);
}
public void AddProductStockAsync()
{
throw new System.NotImplementedException();
}
public Price AddPriceAsync(Price price)
{
_context.Add(price);
_context.SaveChanges();
return price;
}
public void AddOrderRequest(OrderRequest order)
{
_context.Add(order);
_context.SaveChanges();
}
public void UpdateProductStockAsync(ProductStock productStock)
{
_context.Update(productStock);
SaveAndUpdateContext();
}
public void UpdateOrderRequest(OrderRequest orderRequest)
{
_context.Update(orderRequest);
_context.SaveChanges();
}
public void ApproveOrderRequest(int id)
{
var productStock = GetOrderRequest(id).Result;
if (productStock == null) return;
productStock.Approved = true;
productStock.ApprovedTime = DateTime.Now;
_context.Update(productStock);
}
public void SaveAndUpdateContext()
{
_context.SaveChangesAsync();
}
}
}

View File

@@ -0,0 +1,69 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ThAmCo.Stock.Data
{
public class StockDbContext : DbContext
{
public DbSet<Price> Prices { get; set; }
public DbSet<ProductStock> ProductStocks { get; set; }
public DbSet<OrderRequest> OrderRequests { get; set; }
private IHostingEnvironment HostEnv { get; }
public StockDbContext(DbContextOptions<StockDbContext> options, IHostingEnvironment env) : base(options)
{
HostEnv = env;
}
protected override void OnConfiguring(DbContextOptionsBuilder builder)
{
base.OnConfiguring(builder);
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<Price>()
.HasKey(p => p.Id);
builder.Entity<ProductStock>()
.HasKey(ps => ps.Id);
builder.Entity<OrderRequest>()
.HasKey(or => or.Id);
if (HostEnv != null && HostEnv.IsDevelopment())
{
builder.Entity<ProductStock>()
.HasData(
new ProductStock { Id = 1, ProductId = 1, PriceId = 2, Stock = 4 },
new ProductStock { Id = 2, ProductId = 2, PriceId = 3, Stock = 42 },
new ProductStock { Id = 3, ProductId = 3, PriceId = 4, Stock = 32 },
new ProductStock { Id = 4, ProductId = 4, PriceId = 5, Stock = 13},
new ProductStock { Id = 5, ProductId = 5, PriceId = 6, Stock = 0},
new ProductStock { Id = 6, ProductId = 6, PriceId = 7, Stock = 1},
new ProductStock { Id = 7, ProductId = 7, PriceId = 8, Stock = 49}
);
builder.Entity<Price>()
.HasData(
new Price { Id = 1, ProductStockId = 1, ProductPrice = 9.99 },
new Price { Id = 2, ProductStockId = 1, ProductPrice = 8.99 },
new Price { Id = 3, ProductStockId = 2, ProductPrice = 17.99 },
new Price { Id = 4, ProductStockId = 3, ProductPrice = 23.00},
new Price { Id = 5, ProductStockId = 4, ProductPrice = 2.99},
new Price { Id = 6, ProductStockId = 5, ProductPrice = 49.63},
new Price { Id = 7, ProductStockId = 6, ProductPrice = 4.56},
new Price { Id = 8, ProductStockId = 7, ProductPrice = 10.01}
);
}
}
}
}