More implementation of Ordering microservice with draft EF Core DbContext linked to a SQL LocalDB. Code in WebAPI related to the Context still to be refactored and moved to the Infrastructure.SqlData project.
This commit is contained in:
parent
9aed8221f2
commit
ec6256ef6e
@ -45,6 +45,12 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Catalog.SqlData", "src\Serv
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ordering.SqlData", "src\Services\Ordering\Ordering.SqlData\Ordering.SqlData.xproj", "{5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A857AD10-40FF-4303-BEC2-FF1C58D5735E}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{EF0337F2-ED00-4643-89FD-EE10863F1870}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ordering.Test", "test\Services\Ordering.Test\Ordering.Test.xproj", "{A0AFC432-3846-4B4E-BD8E-3C8C896F4967}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -91,6 +97,10 @@ Global
|
||||
{5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -112,5 +122,7 @@ Global
|
||||
{D78C4572-F8D8-4B49-ACD0-F0567CB15F0D} = {BF3EF4F3-E4F5-41DA-9D2D-57223687D1A8}
|
||||
{D9FDCDDA-7823-4043-8C40-634E5FD78046} = {326A7FB3-5295-468C-A4FE-67DCB823E1E5}
|
||||
{5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B}
|
||||
{EF0337F2-ED00-4643-89FD-EE10863F1870} = {A857AD10-40FF-4303-BEC2-FF1C58D5735E}
|
||||
{A0AFC432-3846-4B4E-BD8E-3C8C896F4967} = {EF0337F2-ED00-4643-89FD-EE10863F1870}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,5 +1,9 @@
|
||||
{
|
||||
"projects": [ "src", "test" ],
|
||||
{
|
||||
"projects": [
|
||||
"src",
|
||||
"test"
|
||||
],
|
||||
|
||||
"sdk": {
|
||||
"version": "1.0.0-preview2-003121"
|
||||
}
|
||||
|
@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.UnitOfWork;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel;
|
||||
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
public class OrdersController : Controller
|
||||
{
|
||||
private OrderingContext _context;
|
||||
|
||||
public OrdersController(OrderingContext context)
|
||||
{
|
||||
//Injected DbContext from the IoC container
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET api/orders
|
||||
[HttpGet]
|
||||
public IEnumerable<Order> Get()
|
||||
{
|
||||
//Create generic Address ValueObject
|
||||
Address sampleAddress = new Address("15703 NE 61st Ct.",
|
||||
"Redmond",
|
||||
"Washington",
|
||||
"WA",
|
||||
"United States",
|
||||
"US",
|
||||
"98052",
|
||||
47.661492,
|
||||
-122.131309
|
||||
);
|
||||
|
||||
//Create sample Orders
|
||||
Order order1 = new Order(Guid.NewGuid(), sampleAddress, sampleAddress);
|
||||
_context.Orders.Add(order1);
|
||||
_context.SaveChanges();
|
||||
|
||||
return _context.Orders.ToList();
|
||||
}
|
||||
|
||||
// GET api/orders/xxxGUIDxxxx
|
||||
[HttpGet("{id}")]
|
||||
public string Get(Guid id)
|
||||
{
|
||||
return "value TBD";
|
||||
}
|
||||
|
||||
// POST api/orders
|
||||
[HttpPost]
|
||||
public void Post([FromBody]Order order)
|
||||
{
|
||||
_context.Orders.Add(order);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
// PUT api/orders/xxxGUIDxxxx
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody]Order value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// DELETE api/orders/xxxGUIDxxxx
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(Guid id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.DTO
|
||||
{
|
||||
[DataContract]
|
||||
public sealed class OrderItemDTO
|
||||
@ -20,7 +20,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("ID: {0}, Quantity: {1}, Fulfillment Remaing: {2}", this.ItemId, this.Quantity, this.FulfillmentRemaining);
|
||||
return String.Format("ID: {0}, Quantity: {1}, Fulfillment Remaing: {2}", this.Id, this.Quantity, this.FulfillmentRemaining);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
src/Services/Ordering/Ordering.API/Migrations/20160909202620_MyFirstMigration.Designer.cs
generated
Normal file
37
src/Services/Ordering/Ordering.API/Migrations/20160909202620_MyFirstMigration.Designer.cs
generated
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.UnitOfWork;
|
||||
|
||||
namespace Ordering.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(OrderingContext))]
|
||||
[Migration("20160909202620_MyFirstMigration")]
|
||||
partial class MyFirstMigration
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<Guid>("BuyerId");
|
||||
|
||||
b.Property<DateTime>("OrderDate");
|
||||
|
||||
b.Property<int>("Status");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace Ordering.API.Migrations
|
||||
{
|
||||
public partial class MyFirstMigration : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(nullable: false),
|
||||
BuyerId = table.Column<Guid>(nullable: false),
|
||||
OrderDate = table.Column<DateTime>(nullable: false),
|
||||
Status = table.Column<int>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
}
|
||||
}
|
||||
}
|
84
src/Services/Ordering/Ordering.API/Migrations/20160909223213_Migration2.Designer.cs
generated
Normal file
84
src/Services/Ordering/Ordering.API/Migrations/20160909223213_Migration2.Designer.cs
generated
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.UnitOfWork;
|
||||
|
||||
namespace Ordering.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(OrderingContext))]
|
||||
[Migration("20160909223213_Migration2")]
|
||||
partial class Migration2
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("City");
|
||||
|
||||
b.Property<string>("Country");
|
||||
|
||||
b.Property<string>("CountryCode");
|
||||
|
||||
b.Property<double>("Latitude");
|
||||
|
||||
b.Property<double>("Longitude");
|
||||
|
||||
b.Property<string>("State");
|
||||
|
||||
b.Property<string>("StateCode");
|
||||
|
||||
b.Property<string>("Street");
|
||||
|
||||
b.Property<string>("ZipCode");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Address");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<Guid?>("BillingAddressId");
|
||||
|
||||
b.Property<Guid>("BuyerId");
|
||||
|
||||
b.Property<DateTime>("OrderDate");
|
||||
|
||||
b.Property<Guid?>("ShippingAddressId");
|
||||
|
||||
b.Property<int>("Status");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BillingAddressId");
|
||||
|
||||
b.HasIndex("ShippingAddressId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", "BillingAddress")
|
||||
.WithMany()
|
||||
.HasForeignKey("BillingAddressId");
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", "ShippingAddress")
|
||||
.WithMany()
|
||||
.HasForeignKey("ShippingAddressId");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace Ordering.API.Migrations
|
||||
{
|
||||
public partial class Migration2 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Address",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(nullable: false),
|
||||
City = table.Column<string>(nullable: true),
|
||||
Country = table.Column<string>(nullable: true),
|
||||
CountryCode = table.Column<string>(nullable: true),
|
||||
Latitude = table.Column<double>(nullable: false),
|
||||
Longitude = table.Column<double>(nullable: false),
|
||||
State = table.Column<string>(nullable: true),
|
||||
StateCode = table.Column<string>(nullable: true),
|
||||
Street = table.Column<string>(nullable: true),
|
||||
ZipCode = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Address", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "BillingAddressId",
|
||||
table: "Orders",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "ShippingAddressId",
|
||||
table: "Orders",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_BillingAddressId",
|
||||
table: "Orders",
|
||||
column: "BillingAddressId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ShippingAddressId",
|
||||
table: "Orders",
|
||||
column: "ShippingAddressId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Orders_Address_BillingAddressId",
|
||||
table: "Orders",
|
||||
column: "BillingAddressId",
|
||||
principalTable: "Address",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Orders_Address_ShippingAddressId",
|
||||
table: "Orders",
|
||||
column: "ShippingAddressId",
|
||||
principalTable: "Address",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Orders_Address_BillingAddressId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Orders_Address_ShippingAddressId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Orders_BillingAddressId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Orders_ShippingAddressId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "BillingAddressId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ShippingAddressId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Address");
|
||||
}
|
||||
}
|
||||
}
|
84
src/Services/Ordering/Ordering.API/Migrations/20160909233852_Migration3.Designer.cs
generated
Normal file
84
src/Services/Ordering/Ordering.API/Migrations/20160909233852_Migration3.Designer.cs
generated
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.UnitOfWork;
|
||||
|
||||
namespace Ordering.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(OrderingContext))]
|
||||
[Migration("20160909233852_Migration3")]
|
||||
partial class Migration3
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("City");
|
||||
|
||||
b.Property<string>("Country");
|
||||
|
||||
b.Property<string>("CountryCode");
|
||||
|
||||
b.Property<double>("Latitude");
|
||||
|
||||
b.Property<double>("Longitude");
|
||||
|
||||
b.Property<string>("State");
|
||||
|
||||
b.Property<string>("StateCode");
|
||||
|
||||
b.Property<string>("Street");
|
||||
|
||||
b.Property<string>("ZipCode");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Address");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<Guid?>("BillingAddressId");
|
||||
|
||||
b.Property<Guid>("BuyerId");
|
||||
|
||||
b.Property<DateTime>("OrderDate");
|
||||
|
||||
b.Property<Guid?>("ShippingAddressId");
|
||||
|
||||
b.Property<int>("Status");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BillingAddressId");
|
||||
|
||||
b.HasIndex("ShippingAddressId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", "BillingAddress")
|
||||
.WithMany()
|
||||
.HasForeignKey("BillingAddressId");
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", "ShippingAddress")
|
||||
.WithMany()
|
||||
.HasForeignKey("ShippingAddressId");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace Ordering.API.Migrations
|
||||
{
|
||||
public partial class Migration3 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.UnitOfWork;
|
||||
|
||||
namespace Ordering.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(OrderingContext))]
|
||||
partial class OrderingContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("City");
|
||||
|
||||
b.Property<string>("Country");
|
||||
|
||||
b.Property<string>("CountryCode");
|
||||
|
||||
b.Property<double>("Latitude");
|
||||
|
||||
b.Property<double>("Longitude");
|
||||
|
||||
b.Property<string>("State");
|
||||
|
||||
b.Property<string>("StateCode");
|
||||
|
||||
b.Property<string>("Street");
|
||||
|
||||
b.Property<string>("ZipCode");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Address");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<Guid?>("BillingAddressId");
|
||||
|
||||
b.Property<Guid>("BuyerId");
|
||||
|
||||
b.Property<DateTime>("OrderDate");
|
||||
|
||||
b.Property<Guid?>("ShippingAddressId");
|
||||
|
||||
b.Property<int>("Status");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BillingAddressId");
|
||||
|
||||
b.HasIndex("ShippingAddressId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", "BillingAddress")
|
||||
.WithMany()
|
||||
.HasForeignKey("BillingAddressId");
|
||||
|
||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", "ShippingAddress")
|
||||
.WithMany()
|
||||
.HasForeignKey("ShippingAddressId");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/values",
|
||||
"launchUrl": "api/orders",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.UnitOfWork;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
||||
{
|
||||
public class Startup
|
||||
@ -24,11 +27,16 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
||||
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
// This method gets called by the runtime.
|
||||
// Use this method to add services to the IoC container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Add framework services.
|
||||
services.AddMvc();
|
||||
|
||||
//Add EF Core Context (UnitOfWork)
|
||||
var connection = @"Server=(localdb)\mssqllocaldb;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;";
|
||||
services.AddDbContext<OrderingContext>(options => options.UseSqlServer(connection));
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.UnitOfWork
|
||||
{
|
||||
public class OrderingContext : DbContext
|
||||
{
|
||||
public OrderingContext(DbContextOptions<OrderingContext> options)
|
||||
: base(options)
|
||||
{ }
|
||||
|
||||
public DbSet<Order> Orders { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
{
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"version": "1.0.0",
|
||||
@ -13,10 +13,16 @@
|
||||
"Microsoft.Extensions.Logging": "1.0.0",
|
||||
"Microsoft.Extensions.Logging.Console": "1.0.0",
|
||||
"Microsoft.Extensions.Logging.Debug": "1.0.0",
|
||||
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
|
||||
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
|
||||
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
|
||||
"Microsoft.EntityFrameworkCore": "1.0.0",
|
||||
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0",
|
||||
"Ordering.Domain": "1.0.0-*",
|
||||
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
|
||||
},
|
||||
|
||||
"tools": {
|
||||
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
|
||||
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
|
||||
},
|
||||
|
||||
|
@ -7,7 +7,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel
|
||||
{
|
||||
public Buyer(Guid buyerId, string name, string lastName, string email, Address address, string phoneNumber)
|
||||
{
|
||||
this.BuyerId = buyerId;
|
||||
this.Id = buyerId;
|
||||
this.Name = name;
|
||||
this.LastName = lastName;
|
||||
this.Email = email;
|
||||
@ -15,13 +15,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel
|
||||
this.PhoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
protected Buyer() { } // infrastructure
|
||||
|
||||
public virtual Guid BuyerId
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public virtual string Name
|
||||
{
|
||||
|
@ -5,60 +5,66 @@ using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel
|
||||
{
|
||||
public class Address : ValueObject<Address> //A VO doesn't have IDENTITY, like in this case, the Address
|
||||
public class Address : ValueObject<Address>
|
||||
{
|
||||
public virtual String Street
|
||||
public Address(string street,
|
||||
string city,
|
||||
string state,
|
||||
string stateCode,
|
||||
string country,
|
||||
string countryCode,
|
||||
string zipCode,
|
||||
double latitude = 0,
|
||||
double longitude = 0
|
||||
)
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
if (street == null)
|
||||
throw new ArgumentNullException("street");
|
||||
|
||||
if (city == null)
|
||||
throw new ArgumentNullException("city");
|
||||
|
||||
if (state == null)
|
||||
throw new ArgumentNullException("state");
|
||||
|
||||
if (stateCode == null)
|
||||
throw new ArgumentNullException("stateCode");
|
||||
|
||||
if (country == null)
|
||||
throw new ArgumentNullException("country");
|
||||
|
||||
if (countryCode == null)
|
||||
throw new ArgumentNullException("countryCode");
|
||||
|
||||
if (zipCode == null)
|
||||
throw new ArgumentNullException("zipCode");
|
||||
|
||||
//Generate the ID guid - Remove this when EF Core supports ValueObjects
|
||||
// https://github.com/aspnet/EntityFramework/issues/246
|
||||
this.Id = Guid.NewGuid();
|
||||
|
||||
this.Street = street;
|
||||
this.City = city;
|
||||
this.State = state;
|
||||
this.StateCode = stateCode;
|
||||
this.Country = country;
|
||||
this.CountryCode = countryCode;
|
||||
this.ZipCode = zipCode;
|
||||
this.Latitude = latitude;
|
||||
this.Longitude = longitude;
|
||||
}
|
||||
|
||||
public virtual String City
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
//Infrastructure requisite - Parameterless constructor needed by EF
|
||||
Address() { }
|
||||
|
||||
public virtual String State
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public virtual String StateCode
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public virtual String Country
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public virtual String CountryCode
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public virtual String ZipCode
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public virtual double Latitude
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public virtual double Longitude
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public virtual String Street { get; private set; }
|
||||
public virtual String City { get; private set; }
|
||||
public virtual String State { get; private set; }
|
||||
public virtual String StateCode { get; private set; }
|
||||
public virtual String Country { get; private set; }
|
||||
public virtual String CountryCode { get; private set; }
|
||||
public virtual String ZipCode { get; private set; }
|
||||
public virtual double Latitude { get; private set; }
|
||||
public virtual double Longitude { get; private set; }
|
||||
}
|
||||
}
|
||||
|
@ -22,56 +22,37 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel
|
||||
this.OrderDate = orderDate;
|
||||
}
|
||||
|
||||
protected Order() { } // Infrastructure. EF might need a plain constructor. Do not use.
|
||||
//Infrastructure requisite - Parameterless constructor needed by EF
|
||||
Order() { }
|
||||
|
||||
//Order ID comes derived from the Entity base class
|
||||
|
||||
List<OrderItem> _orderItems;
|
||||
public virtual List<OrderItem> orderItems
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_orderItems == null)
|
||||
_orderItems = new List<OrderItem>();
|
||||
//List<OrderItem> _orderItems;
|
||||
//public virtual List<OrderItem> orderItems
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (_orderItems == null)
|
||||
// _orderItems = new List<OrderItem>();
|
||||
|
||||
return _orderItems;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
_orderItems = value;
|
||||
}
|
||||
}
|
||||
// return _orderItems;
|
||||
// }
|
||||
|
||||
public virtual Guid BuyerId
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
// private set
|
||||
// {
|
||||
// _orderItems = value;
|
||||
// }
|
||||
//}
|
||||
|
||||
public virtual Address ShippingAddress
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public virtual Guid BuyerId { get; private set; }
|
||||
|
||||
public virtual Address BillingAddress
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public virtual Address ShippingAddress { get; private set; }
|
||||
|
||||
public virtual Address BillingAddress { get; private set; }
|
||||
|
||||
public virtual DateTime OrderDate
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public virtual DateTime OrderDate { get; private set; }
|
||||
|
||||
public virtual OrderStatus Status
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public virtual OrderStatus Status { get; private set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
||||
public class ValueObject<TValueObject> : IEquatable<TValueObject>
|
||||
where TValueObject : ValueObject<TValueObject>
|
||||
{
|
||||
//A ValueObject doesn't have Identity, but we just need an Id/key so EF knows how to persist
|
||||
//becuase in EF Core it still doesn't support ValueObjects or ComplexTypes
|
||||
//This should be changed when EF Core supports any of those.
|
||||
// https://github.com/aspnet/EntityFramework/issues/246
|
||||
public virtual Guid Id { get; protected set; }
|
||||
|
||||
//IEquatable and Override Equals operators
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
{
|
||||
"userSecretsId": "aspnet-Microsoft.eShopOnContainers.WebMVC-946ae052-8305-4a99-965b-ec8636ddbae3",
|
||||
|
||||
"dependencies": {
|
||||
@ -23,10 +23,6 @@
|
||||
"version": "1.0.0",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.EntityFrameworkCore.Tools": {
|
||||
"version": "1.0.0-preview2-final",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
|
||||
"Microsoft.Extensions.Configuration.Json": "1.0.0",
|
||||
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
|
||||
|
19
test/Services/Ordering.Test/Ordering.Test.xproj
Normal file
19
test/Services/Ordering.Test/Ordering.Test.xproj
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>a0afc432-3846-4b4e-bd8e-3c8c896f4967</ProjectGuid>
|
||||
<RootNamespace>Ordering.Test</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
14
test/Services/Ordering.Test/Tests.cs
Normal file
14
test/Services/Ordering.Test/Tests.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
public class Tests
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
Assert.True(true);
|
||||
}
|
||||
}
|
||||
}
|
26
test/Services/Ordering.Test/project.json
Normal file
26
test/Services/Ordering.Test/project.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable"
|
||||
},
|
||||
"dependencies": {
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "2.2.0-preview2-build1029"
|
||||
},
|
||||
"testRunner": "xunit",
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"dotnet5.4",
|
||||
"portable-net451+win8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
21
test/Services/Ordering.TestsOLD/Ordering.Tests.xproj
Normal file
21
test/Services/Ordering.TestsOLD/Ordering.Tests.xproj
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>9b26282e-d550-4289-9a18-3334023c4f69</ProjectGuid>
|
||||
<RootNamespace>Ordering.Tests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
19
test/Services/Ordering.TestsOLD/Properties/AssemblyInfo.cs
Normal file
19
test/Services/Ordering.TestsOLD/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Ordering.Tests")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("9b26282e-d550-4289-9a18-3334023c4f69")]
|
13
test/Services/Ordering.TestsOLD/project.json
Normal file
13
test/Services/Ordering.TestsOLD/project.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.6.0"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netstandard1.6": {
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user