From 95af33640495aaf2bee80c69902079d78c1b4c33 Mon Sep 17 00:00:00 2001 From: Unai Date: Mon, 21 Nov 2016 12:41:36 +0100 Subject: [PATCH] Remove old code and projects. Add MediatR. Added first commands. Review Entities and domain. Create queries --- eShopOnContainers.sln | 80 +++++++---- src/Services/Catalog/Catalog.API/Startup.cs | 10 +- src/Services/Catalog/Catalog.API/project.json | 1 + .../Ordering/Ordering.API/.vscode/launch.json | 41 ------ .../Ordering/Ordering.API/.vscode/tasks.json | 16 --- .../Controllers/EnvironmentInfoController.cs | 23 ---- .../Controllers/OrderingController.cs | 129 ------------------ .../Controllers/OrdersController.cs | 97 +++++++++++++ .../20160913204939_Migration1.Designer.cs | 121 ---------------- .../Migrations/20160913204939_Migration1.cs | 123 ----------------- ...61005002014_Migration_Baseline.Designer.cs | 121 ---------------- .../20161005002014_Migration_Baseline.cs | 19 --- .../20161005003321_Migration_Cero.Designer.cs | 121 ---------------- .../20161005003321_Migration_Cero.cs | 19 --- .../20161011040943_Migration2.Designer.cs | 123 ----------------- .../Migrations/20161011040943_Migration2.cs | 24 ---- .../20161011041130_Migration3.Designer.cs | 123 ----------------- .../Migrations/20161011041130_Migration3.cs | 19 --- .../OrderingDbContextModelSnapshot.cs | 122 ----------------- src/Services/Ordering/Ordering.API/Startup.cs | 56 ++++---- .../Ordering/Ordering.API/project.json | 7 +- .../Commands/CancelOrderRequest.cs | 15 ++ .../Commands/CancelOrderRequestHandler.cs | 15 ++ .../Commands/NewOrderREquestHandler.cs | 15 ++ .../Commands/NewOrderRequest.cs | 12 ++ .../Ordering.Application.xproj | 19 +++ .../Properties/AssemblyInfo.cs | 19 +++ .../Queries/IOrderQueries.cs | 11 ++ .../Queries/OrderQueries.cs | 13 ++ .../Ordering.Application/project.json | 16 +++ .../Ordering/Ordering.Domain/Address.cs | 29 ++++ .../AggregatesModel/Buyer/Buyer.cs | 49 ------- .../AggregatesModel/Order/Address.cs | 70 ---------- .../AggregatesModel/Order/Order.cs | 112 --------------- .../AggregatesModel/Order/OrderItem.cs | 33 ----- .../AggregatesModel/Order/OrderStatus.cs | 18 --- .../Ordering/Ordering.Domain/Buyer.cs | 12 ++ .../Contracts/IBuyerRepository.cs | 15 -- .../Contracts/IOrderRepository.cs | 20 --- .../Ordering/Ordering.Domain/Order.cs | 30 ++++ .../Ordering/Ordering.Domain/OrderItem.cs | 25 ++++ .../Ordering/Ordering.Domain/OrderStatus.cs | 59 ++++++++ .../Ordering.Domain/SeedWork/Entity.cs | 74 ++-------- .../SeedWork/IdentityGenerator.cs | 47 ------- .../Ordering.Domain/SeedWork/ValueObject.cs | 50 ++----- .../Queries/IOrderdingQueries.cs | 24 ---- .../Queries/OrderingQueries.cs | 98 ------------- .../Repositories/OrderRepository.cs | 51 ------- 48 files changed, 503 insertions(+), 1843 deletions(-) delete mode 100644 src/Services/Ordering/Ordering.API/.vscode/launch.json delete mode 100644 src/Services/Ordering/Ordering.API/.vscode/tasks.json delete mode 100644 src/Services/Ordering/Ordering.API/Controllers/EnvironmentInfoController.cs delete mode 100644 src/Services/Ordering/Ordering.API/Controllers/OrderingController.cs create mode 100644 src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/20160913204939_Migration1.Designer.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/20160913204939_Migration1.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/20161005002014_Migration_Baseline.Designer.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/20161005002014_Migration_Baseline.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/20161005003321_Migration_Cero.Designer.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/20161005003321_Migration_Cero.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/20161011040943_Migration2.Designer.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/20161011040943_Migration2.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/20161011041130_Migration3.Designer.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/20161011041130_Migration3.cs delete mode 100644 src/Services/Ordering/Ordering.API/Migrations/OrderingDbContextModelSnapshot.cs create mode 100644 src/Services/Ordering/Ordering.Application/Commands/CancelOrderRequest.cs create mode 100644 src/Services/Ordering/Ordering.Application/Commands/CancelOrderRequestHandler.cs create mode 100644 src/Services/Ordering/Ordering.Application/Commands/NewOrderREquestHandler.cs create mode 100644 src/Services/Ordering/Ordering.Application/Commands/NewOrderRequest.cs create mode 100644 src/Services/Ordering/Ordering.Application/Ordering.Application.xproj create mode 100644 src/Services/Ordering/Ordering.Application/Properties/AssemblyInfo.cs create mode 100644 src/Services/Ordering/Ordering.Application/Queries/IOrderQueries.cs create mode 100644 src/Services/Ordering/Ordering.Application/Queries/OrderQueries.cs create mode 100644 src/Services/Ordering/Ordering.Application/project.json create mode 100644 src/Services/Ordering/Ordering.Domain/Address.cs delete mode 100644 src/Services/Ordering/Ordering.Domain/AggregatesModel/Buyer/Buyer.cs delete mode 100644 src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/Address.cs delete mode 100644 src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/Order.cs delete mode 100644 src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/OrderItem.cs delete mode 100644 src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/OrderStatus.cs create mode 100644 src/Services/Ordering/Ordering.Domain/Buyer.cs delete mode 100644 src/Services/Ordering/Ordering.Domain/Contracts/IBuyerRepository.cs delete mode 100644 src/Services/Ordering/Ordering.Domain/Contracts/IOrderRepository.cs create mode 100644 src/Services/Ordering/Ordering.Domain/Order.cs create mode 100644 src/Services/Ordering/Ordering.Domain/OrderItem.cs create mode 100644 src/Services/Ordering/Ordering.Domain/OrderStatus.cs delete mode 100644 src/Services/Ordering/Ordering.Domain/SeedWork/IdentityGenerator.cs delete mode 100644 src/Services/Ordering/Ordering.SqlData/Queries/IOrderdingQueries.cs delete mode 100644 src/Services/Ordering/Ordering.SqlData/Queries/OrderingQueries.cs delete mode 100644 src/Services/Ordering/Ordering.SqlData/Repositories/OrderRepository.cs diff --git a/eShopOnContainers.sln b/eShopOnContainers.sln index 5fe74cfe3..f21b21491 100644 --- a/eShopOnContainers.sln +++ b/eShopOnContainers.sln @@ -32,8 +32,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ordering.API", "src\Service EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ordering.Domain", "src\Services\Ordering\Ordering.Domain\Ordering.Domain.xproj", "{F5598DCB-6DDE-4661-AD9D-A55612DA7E76}" 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}" @@ -60,6 +58,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Targets", "Targets", "{9CC7 EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "eShopOnContainers.WebSPA", "src\Web\WebSPA\eShopOnContainers.WebSPA\eShopOnContainers.WebSPA.xproj", "{9842DB3A-1391-48C7-A49C-2FABD0A18AC2}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ordering.Application", "src\Services\Ordering\Ordering.Application\Ordering.Application.xproj", "{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Ad-Hoc|Any CPU = Ad-Hoc|Any CPU @@ -192,32 +192,6 @@ Global {F5598DCB-6DDE-4661-AD9D-A55612DA7E76}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {F5598DCB-6DDE-4661-AD9D-A55612DA7E76}.Release|x64.ActiveCfg = Release|Any CPU {F5598DCB-6DDE-4661-AD9D-A55612DA7E76}.Release|x86.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Ad-Hoc|x64.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.AppStore|Any CPU.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.AppStore|ARM.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.AppStore|iPhone.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.AppStore|x64.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.AppStore|x86.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Debug|ARM.ActiveCfg = Debug|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Debug|x64.ActiveCfg = Debug|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Debug|x86.ActiveCfg = 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 - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Release|ARM.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Release|iPhone.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Release|x64.ActiveCfg = Release|Any CPU - {5DA6EF13-C7E0-4EC4-8599-A61C6AC2628D}.Release|x86.ActiveCfg = Release|Any CPU {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU @@ -556,6 +530,54 @@ Global {9842DB3A-1391-48C7-A49C-2FABD0A18AC2}.Release|x64.Build.0 = Release|Any CPU {9842DB3A-1391-48C7-A49C-2FABD0A18AC2}.Release|x86.ActiveCfg = Release|Any CPU {9842DB3A-1391-48C7-A49C-2FABD0A18AC2}.Release|x86.Build.0 = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|x64.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|x86.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|ARM.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|ARM.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|iPhone.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|x64.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|x64.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|x86.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|x86.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|ARM.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|ARM.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|iPhone.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|x64.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|x64.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|x86.ActiveCfg = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|x86.Build.0 = Debug|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|Any CPU.Build.0 = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|ARM.ActiveCfg = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|ARM.Build.0 = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|iPhone.ActiveCfg = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|iPhone.Build.0 = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x64.ActiveCfg = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x64.Build.0 = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x86.ActiveCfg = Release|Any CPU + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -571,7 +593,6 @@ Global {42681D9D-750A-4DF7-BD9F-9292CFD5C253} = {326A7FB3-5295-468C-A4FE-67DCB823E1E5} {231226CE-690B-4979-8870-9A79D80928E2} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} {F5598DCB-6DDE-4661-AD9D-A55612DA7E76} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} - {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} {48FC45C5-223F-4B59-AC77-6CBB1C561E85} = {932D8224-11F6-4D07-B109-DA28AD288A63} @@ -584,5 +605,6 @@ Global {778289CA-31F7-4464-8C2A-612EE846F8A7} = {F61357CE-1CC2-410E-8776-B16EEBC98EB8} {9CC7814B-72A6-465B-A61C-57B512DEE303} = {F61357CE-1CC2-410E-8776-B16EEBC98EB8} {9842DB3A-1391-48C7-A49C-2FABD0A18AC2} = {E279BF0F-7F66-4F3A-A3AB-2CDA66C1CD04} + {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} EndGlobalSection EndGlobal diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index 58b5ac7df..53cf8bbc2 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -18,8 +18,14 @@ var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile($"settings.json", optional: false, reloadOnChange: true) - .AddJsonFile($"settings.{env.EnvironmentName}.json", optional: true) - .AddEnvironmentVariables(); + .AddJsonFile($"settings.{env.EnvironmentName}.json", optional: true); + + if (env.IsDevelopment()) + { + builder.AddUserSecrets(); + } + + builder.AddEnvironmentVariables(); Configuration = builder.Build(); } diff --git a/src/Services/Catalog/Catalog.API/project.json b/src/Services/Catalog/Catalog.API/project.json index 813301bd7..d7e16be9e 100644 --- a/src/Services/Catalog/Catalog.API/project.json +++ b/src/Services/Catalog/Catalog.API/project.json @@ -10,6 +10,7 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", + "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", diff --git a/src/Services/Ordering/Ordering.API/.vscode/launch.json b/src/Services/Ordering/Ordering.API/.vscode/launch.json deleted file mode 100644 index b311e1323..000000000 --- a/src/Services/Ordering/Ordering.API/.vscode/launch.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (web)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - "program": "${workspaceRoot}\\bin\\Debug\\netcoreapp1.0\\Ordering.API.dll", - "args": [], - "cwd": "${workspaceRoot}", - "stopAtEntry": false, - "launchBrowser": { - "enabled": true, - "args": "${auto-detect-url}", - "windows": { - "command": "cmd.exe", - "args": "/C start ${auto-detect-url}" - }, - "osx": { - "command": "open" - }, - "linux": { - "command": "xdg-open" - } - }, - "env": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "sourceFileMap": { - "/Views": "${workspaceRoot}/Views" - } - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command.pickProcess}" - } - ] -} \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/.vscode/tasks.json b/src/Services/Ordering/Ordering.API/.vscode/tasks.json deleted file mode 100644 index 9cd37c150..000000000 --- a/src/Services/Ordering/Ordering.API/.vscode/tasks.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "version": "0.1.0", - "command": "dotnet", - "isShellCommand": true, - "args": [], - "tasks": [ - { - "taskName": "build", - "args": [ - "${workspaceRoot}\\project.json" - ], - "isBuildCommand": true, - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Controllers/EnvironmentInfoController.cs b/src/Services/Ordering/Ordering.API/Controllers/EnvironmentInfoController.cs deleted file mode 100644 index ba4d56509..000000000 --- a/src/Services/Ordering/Ordering.API/Controllers/EnvironmentInfoController.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; - -namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers -{ - [Route("api/[controller]")] - public class EnvironmentInfoController : Controller - { - // GET api/environmentInfo/machinename - [HttpGet("machinename")] - public dynamic GetMachineName() - { - return new - { - InstanceName = Environment.MachineName - }; - } - - } -} \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Controllers/OrderingController.cs b/src/Services/Ordering/Ordering.API/Controllers/OrderingController.cs deleted file mode 100644 index 6b9c4b2f2..000000000 --- a/src/Services/Ordering/Ordering.API/Controllers/OrderingController.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; - -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel; -using Microsoft.EntityFrameworkCore; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.Contracts; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.Queries; - -namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers -{ - [Route("api/[controller]")] - public class OrderingController : Controller - { - private IOrderRepository _orderRepository; - private IOrderdingQueries _queries; - - //private OrderingDbContext _context; - - public OrderingController(IOrderRepository orderRepository, - IOrderdingQueries orderingQueries //, - //OrderingDbContext context - ) - { - //Injected objects from the IoC container - _orderRepository = orderRepository; - _queries = orderingQueries; - //_context = context; - } - - - // GET api/ordering/orders - [HttpGet("orders")] - public async Task GetAllOrders() - { - dynamic response = await _queries.GetAllOrdersIncludingValueObjectsAndChildEntities(); - return Ok(response); - } - - - // GET api/ordering/orders/xxxGUIDxxxx - [HttpGet("orders/{orderId:Guid}")] - public async Task GetOrderById(Guid orderId) - { - dynamic response = await _queries.GetOrderById(orderId); - return Ok(response); - } - - //(CDLTLL) - Using parameters - //Alternate method if using several parameters instead of part of the URL - // GET api/ordering/orders/?orderId=xxxGUIDxxx&otherParam=value - //[HttpGet("orders")] - //public Order GetOrderByGuid([FromUri] Guid orderId, [FromUri] string otherParam) - - - // POST api/ordering/orders/create - [HttpPut("orders/create")] - public async Task Post([FromBody]Order order) - { - _orderRepository.Add(order); - int numChanges = await _orderRepository.UnitOfWork.CommitAsync(); - return Ok(numChanges); - } - - // PUT api/ordering/orders/xxxOrderGUIDxxxx/update - [HttpPut("orders/{orderId:Guid}/update")] - public async Task UpdateOrder(Guid orderID, [FromBody] Order orderToUpdate) - { - _orderRepository.Update(orderToUpdate); - int numChanges = await _orderRepository.UnitOfWork.CommitAsync(); - return Ok(numChanges); - } - - // DELETE api/ordering/orders/xxxOrderGUIDxxxx - [HttpDelete("orders/{orderId:Guid}/remove")] - public async Task Remove(Guid id) - { - await _orderRepository.Remove(id); - int numChanges = await _orderRepository.UnitOfWork.CommitAsync(); - return Ok(numChanges); - } - - - // GET api/ordering/orders/add_test_data_and_get_all - [HttpGet("orders/add_test_data_and_get_all")] - public async Task AddTestDataAndGetAllOrders() - { - //TEST ADDING ORDERS ********************************* - //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); - - //Add a few OrderItems - order1.AddNewOrderItem(Guid.NewGuid(), 2, 25, 30); - order1.AddNewOrderItem(Guid.NewGuid(), 1, 58, 0); - order1.AddNewOrderItem(Guid.NewGuid(), 1, 60, 0); - order1.AddNewOrderItem(Guid.NewGuid(), 3, 12, 0); - order1.AddNewOrderItem(Guid.NewGuid(), 5, 3, 0); - - _orderRepository.Add(order1); - int numRecs = await _orderRepository.UnitOfWork.CommitAsync(); - - //_context.Orders.Add(order1); - //_context.SaveChanges(); - - //***************************************************** - - dynamic response = await _queries.GetAllOrdersIncludingValueObjectsAndChildEntities(); - return Ok(response); - } - - } - -} - - diff --git a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs new file mode 100644 index 000000000..b0806f71c --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs @@ -0,0 +1,97 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers +{ + using Application.Commands; + using Application.Queries; + using MediatR; + using Microsoft.AspNetCore.Mvc; + using System; + using System.Threading.Tasks; + + [Route("api/v1/[controller]")] + public class OrdersController : Controller + { + private readonly IMediator _mediator; + private readonly IOrderQueries _orderQueries; + + public OrdersController(IMediator mediator,IOrderQueries orderQueries) + { + if (mediator == null) + { + throw new ArgumentNullException(nameof(mediator)); + } + + if (orderQueries == null) + { + throw new ArgumentNullException(nameof(orderQueries)); + } + + _mediator = mediator; + _orderQueries = orderQueries; + } + + [Route("new")] + [HttpPost] + public async Task AddOrder() + { + var newOrderRequest = new NewOrderRequest(); + + var added = await _mediator.SendAsync(newOrderRequest); + + if (added) + { + return Ok(); + } + + return BadRequest(); + } + + + [Route("cancel/{orderId:int}")] + [HttpPost] + public async Task CancelOrder(int orderId) + { + var cancelOrderRequest = new CancelOrderRequest(orderId); + + var cancelled = await _mediator.SendAsync(cancelOrderRequest); + + if (cancelled) + { + return Ok(); + } + + return BadRequest(); + } + + + [Route("{orderId:int}")] + [HttpGet] + public async Task GetOrder(int orderId) + { + var order = await _orderQueries.GetOrder(orderId); + + if ( order != null) + { + Ok(order); + } + + return NotFound(); + } + + [Route("pending")] + [HttpGet] + public async Task GetPendingOrders(int orderId) + { + var orders = await _orderQueries.GetPendingOrders(); + + if (orders.Any()) + { + Ok(orders); + } + + return NoContent(); + } + } + +} + + diff --git a/src/Services/Ordering/Ordering.API/Migrations/20160913204939_Migration1.Designer.cs b/src/Services/Ordering/Ordering.API/Migrations/20160913204939_Migration1.Designer.cs deleted file mode 100644 index 68d9f6d9e..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/20160913204939_Migration1.Designer.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; - -namespace Ordering.API.Migrations -{ - [DbContext(typeof(OrderingDbContext))] - [Migration("20160913204939_Migration1")] - partial class Migration1 - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.0.0-rtm-21431") - .HasAnnotation("Relational:Sequence:shared.OrderSequences", "'OrderSequences', 'shared', '1001', '1', '', '', 'Int32', 'False'") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("City"); - - b.Property("Country"); - - b.Property("CountryCode"); - - b.Property("Latitude"); - - b.Property("Longitude"); - - b.Property("State"); - - b.Property("StateCode"); - - b.Property("Street"); - - b.Property("ZipCode"); - - b.HasKey("Id"); - - b.ToTable("Address"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("BillingAddressId"); - - b.Property("BuyerId"); - - b.Property("OrderDate"); - - b.Property("SequenceNumber") - .ValueGeneratedOnAdd() - .HasDefaultValueSql("NEXT VALUE FOR shared.OrderSequences"); - - b.Property("ShippingAddressId"); - - b.Property("Status"); - - b.HasKey("Id"); - - b.HasIndex("BillingAddressId"); - - b.HasIndex("ShippingAddressId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Discount"); - - b.Property("FulfillmentRemaining"); - - b.Property("OrderId"); - - b.Property("ProductId"); - - b.Property("Quantity"); - - b.Property("UnitPrice"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.ToTable("OrderItem"); - }); - - 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"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order") - .WithMany("OrderItems") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade); - }); - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Migrations/20160913204939_Migration1.cs b/src/Services/Ordering/Ordering.API/Migrations/20160913204939_Migration1.cs deleted file mode 100644 index 1d9dcc444..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/20160913204939_Migration1.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Ordering.API.Migrations -{ - public partial class Migration1 : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.EnsureSchema( - name: "shared"); - - migrationBuilder.CreateSequence( - name: "OrderSequences", - schema: "shared", - startValue: 1001L); - - migrationBuilder.CreateTable( - name: "Address", - columns: table => new - { - Id = table.Column(nullable: false), - City = table.Column(nullable: true), - Country = table.Column(nullable: true), - CountryCode = table.Column(nullable: true), - Latitude = table.Column(nullable: false), - Longitude = table.Column(nullable: false), - State = table.Column(nullable: true), - StateCode = table.Column(nullable: true), - Street = table.Column(nullable: true), - ZipCode = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Address", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(nullable: false), - BillingAddressId = table.Column(nullable: true), - BuyerId = table.Column(nullable: false), - OrderDate = table.Column(nullable: false), - SequenceNumber = table.Column(nullable: false, defaultValueSql: "NEXT VALUE FOR shared.OrderSequences"), - ShippingAddressId = table.Column(nullable: true), - Status = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Address_BillingAddressId", - column: x => x.BillingAddressId, - principalTable: "Address", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Orders_Address_ShippingAddressId", - column: x => x.ShippingAddressId, - principalTable: "Address", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "OrderItem", - columns: table => new - { - Id = table.Column(nullable: false), - Discount = table.Column(nullable: false), - FulfillmentRemaining = table.Column(nullable: false), - OrderId = table.Column(nullable: false), - ProductId = table.Column(nullable: false), - Quantity = table.Column(nullable: false), - UnitPrice = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OrderItem", x => x.Id); - table.ForeignKey( - name: "FK_OrderItem_Orders_OrderId", - column: x => x.OrderId, - principalTable: "Orders", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_BillingAddressId", - table: "Orders", - column: "BillingAddressId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ShippingAddressId", - table: "Orders", - column: "ShippingAddressId"); - - migrationBuilder.CreateIndex( - name: "IX_OrderItem_OrderId", - table: "OrderItem", - column: "OrderId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropSequence( - name: "OrderSequences", - schema: "shared"); - - migrationBuilder.DropTable( - name: "OrderItem"); - - migrationBuilder.DropTable( - name: "Orders"); - - migrationBuilder.DropTable( - name: "Address"); - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Migrations/20161005002014_Migration_Baseline.Designer.cs b/src/Services/Ordering/Ordering.API/Migrations/20161005002014_Migration_Baseline.Designer.cs deleted file mode 100644 index c1408c1a3..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/20161005002014_Migration_Baseline.Designer.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; - -namespace Ordering.API.Migrations -{ - [DbContext(typeof(OrderingDbContext))] - [Migration("20161005002014_Migration_Baseline")] - partial class Migration_Baseline - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.0.0-rtm-21431") - .HasAnnotation("Relational:Sequence:shared.OrderSequences", "'OrderSequences', 'shared', '1001', '1', '', '', 'Int32', 'False'") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("City"); - - b.Property("Country"); - - b.Property("CountryCode"); - - b.Property("Latitude"); - - b.Property("Longitude"); - - b.Property("State"); - - b.Property("StateCode"); - - b.Property("Street"); - - b.Property("ZipCode"); - - b.HasKey("Id"); - - b.ToTable("Address"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("BillingAddressId"); - - b.Property("BuyerId"); - - b.Property("OrderDate"); - - b.Property("SequenceNumber") - .ValueGeneratedOnAdd() - .HasDefaultValueSql("NEXT VALUE FOR shared.OrderSequences"); - - b.Property("ShippingAddressId"); - - b.Property("Status"); - - b.HasKey("Id"); - - b.HasIndex("BillingAddressId"); - - b.HasIndex("ShippingAddressId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Discount"); - - b.Property("FulfillmentRemaining"); - - b.Property("OrderId"); - - b.Property("ProductId"); - - b.Property("Quantity"); - - b.Property("UnitPrice"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.ToTable("OrderItem"); - }); - - 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"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order") - .WithMany("OrderItems") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade); - }); - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Migrations/20161005002014_Migration_Baseline.cs b/src/Services/Ordering/Ordering.API/Migrations/20161005002014_Migration_Baseline.cs deleted file mode 100644 index ab54ddc1c..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/20161005002014_Migration_Baseline.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Ordering.API.Migrations -{ - public partial class Migration_Baseline : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Migrations/20161005003321_Migration_Cero.Designer.cs b/src/Services/Ordering/Ordering.API/Migrations/20161005003321_Migration_Cero.Designer.cs deleted file mode 100644 index 23b3007c4..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/20161005003321_Migration_Cero.Designer.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; - -namespace Ordering.API.Migrations -{ - [DbContext(typeof(OrderingDbContext))] - [Migration("20161005003321_Migration_Cero")] - partial class Migration_Cero - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.0.0-rtm-21431") - .HasAnnotation("Relational:Sequence:shared.OrderSequences", "'OrderSequences', 'shared', '1001', '1', '', '', 'Int32', 'False'") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("City"); - - b.Property("Country"); - - b.Property("CountryCode"); - - b.Property("Latitude"); - - b.Property("Longitude"); - - b.Property("State"); - - b.Property("StateCode"); - - b.Property("Street"); - - b.Property("ZipCode"); - - b.HasKey("Id"); - - b.ToTable("Address"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("BillingAddressId"); - - b.Property("BuyerId"); - - b.Property("OrderDate"); - - b.Property("SequenceNumber") - .ValueGeneratedOnAdd() - .HasDefaultValueSql("NEXT VALUE FOR shared.OrderSequences"); - - b.Property("ShippingAddressId"); - - b.Property("Status"); - - b.HasKey("Id"); - - b.HasIndex("BillingAddressId"); - - b.HasIndex("ShippingAddressId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Discount"); - - b.Property("FulfillmentRemaining"); - - b.Property("OrderId"); - - b.Property("ProductId"); - - b.Property("Quantity"); - - b.Property("UnitPrice"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.ToTable("OrderItem"); - }); - - 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"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order") - .WithMany("OrderItems") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade); - }); - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Migrations/20161005003321_Migration_Cero.cs b/src/Services/Ordering/Ordering.API/Migrations/20161005003321_Migration_Cero.cs deleted file mode 100644 index aec42924e..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/20161005003321_Migration_Cero.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Ordering.API.Migrations -{ - public partial class Migration_Cero : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Migrations/20161011040943_Migration2.Designer.cs b/src/Services/Ordering/Ordering.API/Migrations/20161011040943_Migration2.Designer.cs deleted file mode 100644 index 9728a1902..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/20161011040943_Migration2.Designer.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; - -namespace Ordering.API.Migrations -{ - [DbContext(typeof(OrderingDbContext))] - [Migration("20161011040943_Migration2")] - partial class Migration2 - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.0.0-rtm-21431") - .HasAnnotation("Relational:Sequence:shared.OrderSequences", "'OrderSequences', 'shared', '1001', '1', '', '', 'Int32', 'False'") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("City"); - - b.Property("Country"); - - b.Property("CountryCode"); - - b.Property("Latitude"); - - b.Property("Longitude"); - - b.Property("State"); - - b.Property("StateCode"); - - b.Property("Street"); - - b.Property("ZipCode"); - - b.HasKey("Id"); - - b.ToTable("Address"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("BillingAddressId"); - - b.Property("BuyerId"); - - b.Property("OrderDate"); - - b.Property("SequenceNumber") - .ValueGeneratedOnAdd() - .HasDefaultValueSql("NEXT VALUE FOR shared.OrderSequences"); - - b.Property("ShippingAddressId"); - - b.Property("Status"); - - b.HasKey("Id"); - - b.HasIndex("BillingAddressId"); - - b.HasIndex("ShippingAddressId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Discount"); - - b.Property("FulfillmentRemaining"); - - b.Property("OrderId"); - - b.Property("ProductId"); - - b.Property("ProductName"); - - b.Property("Quantity"); - - b.Property("UnitPrice"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.ToTable("OrderItem"); - }); - - 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"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order") - .WithMany("OrderItems") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade); - }); - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Migrations/20161011040943_Migration2.cs b/src/Services/Ordering/Ordering.API/Migrations/20161011040943_Migration2.cs deleted file mode 100644 index caf45e9c0..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/20161011040943_Migration2.cs +++ /dev/null @@ -1,24 +0,0 @@ -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.AddColumn( - name: "ProductName", - table: "OrderItem", - nullable: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "ProductName", - table: "OrderItem"); - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Migrations/20161011041130_Migration3.Designer.cs b/src/Services/Ordering/Ordering.API/Migrations/20161011041130_Migration3.Designer.cs deleted file mode 100644 index f0d76e51f..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/20161011041130_Migration3.Designer.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; - -namespace Ordering.API.Migrations -{ - [DbContext(typeof(OrderingDbContext))] - [Migration("20161011041130_Migration3")] - partial class Migration3 - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.0.0-rtm-21431") - .HasAnnotation("Relational:Sequence:shared.OrderSequences", "'OrderSequences', 'shared', '1001', '1', '', '', 'Int32', 'False'") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("City"); - - b.Property("Country"); - - b.Property("CountryCode"); - - b.Property("Latitude"); - - b.Property("Longitude"); - - b.Property("State"); - - b.Property("StateCode"); - - b.Property("Street"); - - b.Property("ZipCode"); - - b.HasKey("Id"); - - b.ToTable("Address"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("BillingAddressId"); - - b.Property("BuyerId"); - - b.Property("OrderDate"); - - b.Property("SequenceNumber") - .ValueGeneratedOnAdd() - .HasDefaultValueSql("NEXT VALUE FOR shared.OrderSequences"); - - b.Property("ShippingAddressId"); - - b.Property("Status"); - - b.HasKey("Id"); - - b.HasIndex("BillingAddressId"); - - b.HasIndex("ShippingAddressId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Discount"); - - b.Property("FulfillmentRemaining"); - - b.Property("OrderId"); - - b.Property("ProductId"); - - b.Property("ProductName"); - - b.Property("Quantity"); - - b.Property("UnitPrice"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.ToTable("OrderItem"); - }); - - 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"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order") - .WithMany("OrderItems") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade); - }); - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Migrations/20161011041130_Migration3.cs b/src/Services/Ordering/Ordering.API/Migrations/20161011041130_Migration3.cs deleted file mode 100644 index 3b3ae2b73..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/20161011041130_Migration3.cs +++ /dev/null @@ -1,19 +0,0 @@ -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) - { - - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Migrations/OrderingDbContextModelSnapshot.cs b/src/Services/Ordering/Ordering.API/Migrations/OrderingDbContextModelSnapshot.cs deleted file mode 100644 index e7b7b4aaf..000000000 --- a/src/Services/Ordering/Ordering.API/Migrations/OrderingDbContextModelSnapshot.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; - -namespace Ordering.API.Migrations -{ - [DbContext(typeof(OrderingDbContext))] - partial class OrderingDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.0.0-rtm-21431") - .HasAnnotation("Relational:Sequence:shared.OrderSequences", "'OrderSequences', 'shared', '1001', '1', '', '', 'Int32', 'False'") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("City"); - - b.Property("Country"); - - b.Property("CountryCode"); - - b.Property("Latitude"); - - b.Property("Longitude"); - - b.Property("State"); - - b.Property("StateCode"); - - b.Property("Street"); - - b.Property("ZipCode"); - - b.HasKey("Id"); - - b.ToTable("Address"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("BillingAddressId"); - - b.Property("BuyerId"); - - b.Property("OrderDate"); - - b.Property("SequenceNumber") - .ValueGeneratedOnAdd() - .HasDefaultValueSql("NEXT VALUE FOR shared.OrderSequences"); - - b.Property("ShippingAddressId"); - - b.Property("Status"); - - b.HasKey("Id"); - - b.HasIndex("BillingAddressId"); - - b.HasIndex("ShippingAddressId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Discount"); - - b.Property("FulfillmentRemaining"); - - b.Property("OrderId"); - - b.Property("ProductId"); - - b.Property("ProductName"); - - b.Property("Quantity"); - - b.Property("UnitPrice"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.ToTable("OrderItem"); - }); - - 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"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => - { - b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order") - .WithMany("OrderItems") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade); - }); - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 8e003d8e5..4b5009663 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -1,21 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; -using Microsoft.EntityFrameworkCore; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.Contracts; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.Repositories; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.Queries; - -namespace Microsoft.eShopOnContainers.Services.Ordering.API +namespace Microsoft.eShopOnContainers.Services.Ordering.API { + using MediatR; + using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Hosting; + using Microsoft.EntityFrameworkCore; + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Logging; + public class Startup { public Startup(IHostingEnvironment env) @@ -37,27 +29,34 @@ 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 IoC container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); + //services.AddEntityFrameworkSqlServer() + // .AddDbContext(options => + // { + // options.UseSqlServer(Configuration["ConnectionString"]); + // }); - var connString = Configuration["ConnectionString"]; - - services.AddDbContext(options => + services.AddSwaggerGen(); + services.ConfigureSwaggerGen(options => { - options.UseSqlServer(connString) - .UseSqlServer(connString, b => b.MigrationsAssembly("Ordering.API")); + options.DescribeAllEnumsAsStrings(); + options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info() + { + Title = "Ordering HTTP API", + Version = "v1", + Description = "The Ordering Service HTTP API", + TermsOfService = "Terms Of Service" + }); }); - services.AddTransient(); - services.AddTransient(); + services.AddMediatR(typeof(Startup)); //TODO:pending + } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); @@ -69,6 +68,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API } app.UseMvc(); + + app.UseSwagger() + .UseSwaggerUi(); } } } diff --git a/src/Services/Ordering/Ordering.API/project.json b/src/Services/Ordering/Ordering.API/project.json index d5b415b26..31217732b 100644 --- a/src/Services/Ordering/Ordering.API/project.json +++ b/src/Services/Ordering/Ordering.API/project.json @@ -4,6 +4,8 @@ "version": "1.0.0", "type": "platform" }, + "MediatR.Extensions.Microsoft.DependencyInjection": "1.0.1", + "Microsoft.Extensions.DependencyInjection": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", @@ -20,8 +22,11 @@ "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0", "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", "Microsoft.AspNetCore.Diagnostics": "1.0.0", + "Ordering.Application": "1.0.0-*", "Ordering.Domain": "1.0.0-*", - "Ordering.SqlData": "1.0.0-*" + "Ordering.SqlData": "1.0.0-*", + "Swashbuckle": "6.0.0-beta902", + "MediatR": "2.1.0" }, "tools": { "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", diff --git a/src/Services/Ordering/Ordering.Application/Commands/CancelOrderRequest.cs b/src/Services/Ordering/Ordering.Application/Commands/CancelOrderRequest.cs new file mode 100644 index 000000000..b68dbd375 --- /dev/null +++ b/src/Services/Ordering/Ordering.Application/Commands/CancelOrderRequest.cs @@ -0,0 +1,15 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Application.Commands +{ + using MediatR; + + public class CancelOrderRequest + : IAsyncRequest + { + public int OrderId { get; private set; } + + public CancelOrderRequest(int orderId) + { + OrderId = orderId; + } + } +} diff --git a/src/Services/Ordering/Ordering.Application/Commands/CancelOrderRequestHandler.cs b/src/Services/Ordering/Ordering.Application/Commands/CancelOrderRequestHandler.cs new file mode 100644 index 000000000..4874c178f --- /dev/null +++ b/src/Services/Ordering/Ordering.Application/Commands/CancelOrderRequestHandler.cs @@ -0,0 +1,15 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Application.Commands +{ + using MediatR; + using System; + using System.Threading.Tasks; + + public class CancelOrderRequestHandler + : IAsyncRequestHandler + { + public Task Handle(CancelOrderRequest message) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Services/Ordering/Ordering.Application/Commands/NewOrderREquestHandler.cs b/src/Services/Ordering/Ordering.Application/Commands/NewOrderREquestHandler.cs new file mode 100644 index 000000000..fceb7ef41 --- /dev/null +++ b/src/Services/Ordering/Ordering.Application/Commands/NewOrderREquestHandler.cs @@ -0,0 +1,15 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Application.Commands +{ + using MediatR; + using System; + using System.Threading.Tasks; + + public class NewOrderREquestHandler + : IAsyncRequestHandler + { + public Task Handle(NewOrderRequest message) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Services/Ordering/Ordering.Application/Commands/NewOrderRequest.cs b/src/Services/Ordering/Ordering.Application/Commands/NewOrderRequest.cs new file mode 100644 index 000000000..4dd5ac5bc --- /dev/null +++ b/src/Services/Ordering/Ordering.Application/Commands/NewOrderRequest.cs @@ -0,0 +1,12 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Application.Commands +{ + using MediatR; + + public class NewOrderRequest + :IAsyncRequest + { + public NewOrderRequest() + { + } + } +} diff --git a/src/Services/Ordering/Ordering.Application/Ordering.Application.xproj b/src/Services/Ordering/Ordering.Application/Ordering.Application.xproj new file mode 100644 index 000000000..2c6ff9897 --- /dev/null +++ b/src/Services/Ordering/Ordering.Application/Ordering.Application.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 4193caa3-a1c3-4818-a06f-a2d85fde77e7 + Microsoft.eShopOnContainers.Services.Ordering.Application + .\obj + .\bin\ + v4.5.1 + + + 2.0 + + + \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.Application/Properties/AssemblyInfo.cs b/src/Services/Ordering/Ordering.Application/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..a38e1f35b --- /dev/null +++ b/src/Services/Ordering/Ordering.Application/Properties/AssemblyInfo.cs @@ -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.Application")] +[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("4193caa3-a1c3-4818-a06f-a2d85fde77e7")] diff --git a/src/Services/Ordering/Ordering.Application/Queries/IOrderQueries.cs b/src/Services/Ordering/Ordering.Application/Queries/IOrderQueries.cs new file mode 100644 index 000000000..6b364a569 --- /dev/null +++ b/src/Services/Ordering/Ordering.Application/Queries/IOrderQueries.cs @@ -0,0 +1,11 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Application.Queries +{ + using System.Threading.Tasks; + + public interface IOrderQueries + { + Task GetOrder(int id); + + Task GetPendingOrders(); + } +} diff --git a/src/Services/Ordering/Ordering.Application/Queries/OrderQueries.cs b/src/Services/Ordering/Ordering.Application/Queries/OrderQueries.cs new file mode 100644 index 000000000..3c2412ebc --- /dev/null +++ b/src/Services/Ordering/Ordering.Application/Queries/OrderQueries.cs @@ -0,0 +1,13 @@ + + +namespace Microsoft.eShopOnContainers.Services.Ordering.Application.Queries +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + + public class OrderQueries + { + } +} diff --git a/src/Services/Ordering/Ordering.Application/project.json b/src/Services/Ordering/Ordering.Application/project.json new file mode 100644 index 000000000..814573611 --- /dev/null +++ b/src/Services/Ordering/Ordering.Application/project.json @@ -0,0 +1,16 @@ +{ + "version": "1.0.0-*", + + "dependencies": { + "NETStandard.Library": "1.6.0", + "MediatR": "2.1.0", + "System.Dynamic.Runtime": "4.0.11", + "Microsoft.CSharp": "4.0.1" + }, + + "frameworks": { + "netstandard1.6": { + "imports": "dnxcore50" + } + } +} diff --git a/src/Services/Ordering/Ordering.Domain/Address.cs b/src/Services/Ordering/Ordering.Domain/Address.cs new file mode 100644 index 000000000..19e62d9ca --- /dev/null +++ b/src/Services/Ordering/Ordering.Domain/Address.cs @@ -0,0 +1,29 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Domain +{ + using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; + using System; + + public class Address + : Entity + { + public String Street { get; private set; } + + public String City { get; private set; } + + public String State { get; private set; } + + public String StateCode { get; private set; } + + public String Country { get; private set; } + + public String CountryCode { get; private set; } + + public String ZipCode { get; private set; } + + public double Latitude { get; private set; } + + public double Longitude { get; private set; } + + protected Address() { } + } +} diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/Buyer/Buyer.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/Buyer/Buyer.cs deleted file mode 100644 index b10b087c4..000000000 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/Buyer/Buyer.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; - -namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel -{ - public class Buyer : Entity, IAggregateRoot - { - public Buyer(Guid buyerId, string name, string lastName, string email, Address address, string phoneNumber) - { - this.Id = buyerId; - this.Name = name; - this.LastName = lastName; - this.Email = email; - this.Address = address; - this.PhoneNumber = phoneNumber; - } - - - public virtual string Name - { - get; - private set; - } - - public virtual string LastName - { - get; - private set; - } - - public virtual string Email - { - get; - private set; - } - - public virtual Address Address - { - get; - private set; - } - - public virtual string PhoneNumber - { - get; - private set; - } - } -} diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/Address.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/Address.cs deleted file mode 100644 index 9114b2f93..000000000 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/Address.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; - -using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; - -namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel -{ - public class Address : ValueObject
- { - public Address(string street, - string city, - string state, - string stateCode, - string country, - string countryCode, - string zipCode, - double latitude = 0, - double longitude = 0 - ) - { - 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; - } - - //Infrastructure requisite - Parameterless constructor needed by EF - Address() { } - - 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; } - } -} diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/Order.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/Order.cs deleted file mode 100644 index 069afa981..000000000 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/Order.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; - -namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel -{ - public class Order : Entity, IAggregateRoot - { - public Order(Guid buyerId, Address shippingAddress, Address billingAddress) - : this(buyerId, shippingAddress, billingAddress, DateTime.UtcNow) - { - } - - public Order(Guid buyerId, Address shippingAddress, Address billingAddress, DateTime orderDate) - { - this.BuyerId = buyerId; - this.ShippingAddress = shippingAddress; - this.BillingAddress = billingAddress; - this.OrderDate = orderDate; - - this.Status = OrderStatus.New; - } - - //Infrastructure requisite - Parameterless constructor needed by EF - Order() { } - - //Order ID comes derived from the Entity base class - - List _orderItems; - public virtual List OrderItems - { - get - { - if (_orderItems == null) - _orderItems = new List(); - - return _orderItems; - } - - private set - { - _orderItems = value; - } - } - - public string OrderNumber - { - get - { - return string.Format("{0}/{1}-{2}", OrderDate.Year, OrderDate.Month, SequenceNumber); - } - } - - public int SequenceNumber { get; set; } - - public virtual Guid BuyerId { 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 OrderStatus Status { get; private set; } - - //////////////////////////////////////////////////////////////////////////////////////// - //Domain Rules and Logic in Order Aggregate-Root (Sample of a "NO ANEMIC DOMAIN MODEL" ) - //////////////////////////////////////////////////////////////////////////////////////// - - public OrderItem AddNewOrderItem(Guid productId, int quantity, decimal unitPrice, decimal discount) - { - //check preconditions - if (productId == Guid.Empty) - throw new ArgumentNullException("productId"); - - if (quantity <= 0) - { - throw new ArgumentException("The quantity of Product in an Order cannot be equal or less than cero"); - } - - //check discount values - if (discount < 0) - discount = 0; - - if (discount > 100) - discount = 100; - - //create new order line - var newOrderItem = new OrderItem() - { - OrderId = this.Id, - ProductId = productId, - Quantity = quantity, - FulfillmentRemaining = quantity, - Discount = discount, - UnitPrice = unitPrice - }; - - //set identity - newOrderItem.GenerateNewIdentity(); - - //add order item - this.OrderItems.Add(newOrderItem); - - //return added orderline - return newOrderItem; - } - } -} diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/OrderItem.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/OrderItem.cs deleted file mode 100644 index e993f7117..000000000 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/OrderItem.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Runtime.Serialization; - -using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; - -namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel -{ - public class OrderItem : Entity - { - public OrderItem() { } // Infrastructure. EF might need a plain constructor. Do not use. - - //NOTE: The OrderItem Id (Id) comes from the Entity base class - - public Guid ProductId { get; set; } - - public Guid OrderId { get; set; } - - public decimal UnitPrice { get; set; } - - public string ProductName { get; set; } - - public int Quantity { get; set; } - - public decimal Discount { get; set; } - - public int FulfillmentRemaining { get; set; } - - public override string ToString() - { - return String.Format("Product Id: {0}, Quantity: {1}, Fulfillment Remaing: {2}", this.Id, this.Quantity, this.FulfillmentRemaining); - } - } -} diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/OrderStatus.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/OrderStatus.cs deleted file mode 100644 index e48aaaaf1..000000000 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/Order/OrderStatus.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel -{ - public enum OrderStatus - { - Unknown, - New, - Submitted, - InProcess, - Backordered, - Shipped, - Canceled, - } -} diff --git a/src/Services/Ordering/Ordering.Domain/Buyer.cs b/src/Services/Ordering/Ordering.Domain/Buyer.cs new file mode 100644 index 000000000..40bb11499 --- /dev/null +++ b/src/Services/Ordering/Ordering.Domain/Buyer.cs @@ -0,0 +1,12 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Domain +{ + using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; + + public class Buyer + :Entity,IAggregateRoot + { + public string FullName { get; private set; } + + protected Buyer() { } + } +} diff --git a/src/Services/Ordering/Ordering.Domain/Contracts/IBuyerRepository.cs b/src/Services/Ordering/Ordering.Domain/Contracts/IBuyerRepository.cs deleted file mode 100644 index fb5848ea8..000000000 --- a/src/Services/Ordering/Ordering.Domain/Contracts/IBuyerRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; - -namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Contracts -{ - public interface IBuyerRepository : IRepository - { - //TBD - To define Specific Actions Not In Base Repo - } -} diff --git a/src/Services/Ordering/Ordering.Domain/Contracts/IOrderRepository.cs b/src/Services/Ordering/Ordering.Domain/Contracts/IOrderRepository.cs deleted file mode 100644 index 7e30b3dc7..000000000 --- a/src/Services/Ordering/Ordering.Domain/Contracts/IOrderRepository.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; - - -namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Contracts -{ - public interface IOrderRepository : IRepository - { - void Add(Order order); - void Update(Order order); - Task Remove(Guid id); - Task FindAsync(Guid id); - } -} - diff --git a/src/Services/Ordering/Ordering.Domain/Order.cs b/src/Services/Ordering/Ordering.Domain/Order.cs new file mode 100644 index 000000000..547d44148 --- /dev/null +++ b/src/Services/Ordering/Ordering.Domain/Order.cs @@ -0,0 +1,30 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Domain +{ + using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; + using System; + using System.Collections.Generic; + + public class Order + :Entity, IAggregateRoot + { + public int BuyerId { get; private set; } + + public Buyer Buyer { get; private set; } + + public DateTime OrderDate { get; private set; } + + public OrderStatus Status { get; private set; } + + public ICollection OrderItems { get; set; } + + public int ShippingAddressId { get; private set; } + + public Address ShippingAddress { get; private set; } + + public int BillingAddressId { get; private set; } + + public Address BillingAddress { get; private set; } + + protected Order() { } + } +} diff --git a/src/Services/Ordering/Ordering.Domain/OrderItem.cs b/src/Services/Ordering/Ordering.Domain/OrderItem.cs new file mode 100644 index 000000000..2701ad9af --- /dev/null +++ b/src/Services/Ordering/Ordering.Domain/OrderItem.cs @@ -0,0 +1,25 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Domain +{ + using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; + + + public class OrderItem + :Entity + { + public int ProductId { get; private set; } + + public string ProductName { get; private set; } + + public int OrderId { get; private set; } + + public decimal UnitPrice { get; private set; } + + public decimal Discount { get; private set; } + + public int Units { get; private set; } + + protected OrderItem() + { + } + } +} diff --git a/src/Services/Ordering/Ordering.Domain/OrderStatus.cs b/src/Services/Ordering/Ordering.Domain/OrderStatus.cs new file mode 100644 index 000000000..8a9faa511 --- /dev/null +++ b/src/Services/Ordering/Ordering.Domain/OrderStatus.cs @@ -0,0 +1,59 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Domain +{ + using SeedWork; + using System; + using System.Collections.Generic; + using System.Linq; + + public class OrderStatus + :Entity + { + public string Name { get; private set; } + + public static OrderStatus New = new OrderStatus(1, nameof(New).ToLowerInvariant()); + public static OrderStatus Submitted = new OrderStatus(1, nameof(Submitted).ToLowerInvariant()); + public static OrderStatus InProcess = new OrderStatus(1, nameof(InProcess).ToLowerInvariant()); + public static OrderStatus Shipped = new OrderStatus(1, nameof(Shipped).ToLowerInvariant()); + public static OrderStatus Canceled = new OrderStatus(1, nameof(Canceled).ToLowerInvariant()); + + protected OrderStatus() + { + } + + public OrderStatus(int id, string name) + { + Id = id; + Name = name; + } + + public static IEnumerable List() + { + return new[] { New, Submitted, InProcess, Shipped, Canceled }; + } + + public static OrderStatus FromName(string name) + { + var state = List() + .SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); + + if (state == null) + { + throw new ArgumentException($"Possible values for OrderStatus: {String.Join(",", List().Select(s => s.Name))}"); + } + + return state; + } + + public static OrderStatus From(int id) + { + var state = List().SingleOrDefault(s => s.Id == id); + + if (state == null) + { + throw new ArgumentException($"Possible values for OrderStatus: {String.Join(",", List().Select(s => s.Name))}"); + } + + return state; + } + } +} diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs index 258b364e5..e5653ad28 100644 --- a/src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs +++ b/src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs @@ -1,24 +1,15 @@ -using System; - -namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork +namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork { - /// - /// Base class for entities - /// + using System; + + public abstract class Entity { - //Members int? _requestedHashCode; - Guid _Id; - + int _Id; - //Properties - - /// - /// Get the persisten object identifier - /// - public virtual Guid Id + public virtual int Id { get { @@ -30,44 +21,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork } } - //Public Methods - - /// - /// Check if this entity is transient, ie, without identity at this moment - /// - /// True if entity is transient, else false public bool IsTransient() { - return this.Id == Guid.Empty; - } - - /// - /// Generate identity for this entity - /// - public void GenerateNewIdentity() - { - if ( IsTransient()) - this.Id = IdentityGenerator.NewSequentialGuid(); - } - - /// - /// Change current identity for a new non transient identity - /// - /// the new identity - public void ChangeCurrentIdentity(Guid identity) - { - if ( identity != Guid.Empty) - this.Id = identity; + return this.Id == default(Int32); } - - //Overrides Methods - - /// - /// - /// - /// - /// public override bool Equals(object obj) { if (obj == null || !(obj is Entity)) @@ -84,10 +42,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork return item.Id == this.Id; } - /// - /// - /// - /// public override int GetHashCode() { if (!IsTransient()) @@ -101,12 +55,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork return base.GetHashCode(); } - /// - /// equals operator - /// - /// left parameter - /// right parameter - /// true if equals + public static bool operator ==(Entity left, Entity right) { if (Object.Equals(left, null)) @@ -115,16 +64,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork return left.Equals(right); } - /// - /// Distinct operator - /// - /// left parameter - /// right parameter - /// True if different public static bool operator !=(Entity left, Entity right) { return !(left == right); } - } } diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/IdentityGenerator.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/IdentityGenerator.cs deleted file mode 100644 index bc880ed78..000000000 --- a/src/Services/Ordering/Ordering.Domain/SeedWork/IdentityGenerator.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; - -namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork -{ - internal static class IdentityGenerator - { - /// - /// This algorithm generates secuential GUIDs across system boundaries, ideal for databases - /// - /// - public static Guid NewSequentialGuid() - { - byte[] uid = Guid.NewGuid().ToByteArray(); - byte[] binDate = BitConverter.GetBytes(DateTime.UtcNow.Ticks); - - byte[] secuentialGuid = new byte[uid.Length]; - - secuentialGuid[0] = uid[0]; - secuentialGuid[1] = uid[1]; - secuentialGuid[2] = uid[2]; - secuentialGuid[3] = uid[3]; - secuentialGuid[4] = uid[4]; - secuentialGuid[5] = uid[5]; - secuentialGuid[6] = uid[6]; - // set the first part of the 8th byte to '1100' so - // later we'll be able to validate it was generated by us - - secuentialGuid[7] = (byte)(0xc0 | (0xf & uid[7])); - - // the last 8 bytes are sequential, - // it minimizes index fragmentation - // to a degree as long as there are not a large - // number of Secuential-Guids generated per millisecond - - secuentialGuid[9] = binDate[0]; - secuentialGuid[8] = binDate[1]; - secuentialGuid[15] = binDate[2]; - secuentialGuid[14] = binDate[3]; - secuentialGuid[13] = binDate[4]; - secuentialGuid[12] = binDate[5]; - secuentialGuid[11] = binDate[6]; - secuentialGuid[10] = binDate[7]; - - return new Guid(secuentialGuid); - } - } -} diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs index 43b377183..3dc5fc4cd 100644 --- a/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs +++ b/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs @@ -1,16 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Reflection; - + namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork { - /// - /// Base class for value objects in domain. - /// Value - /// - /// The type of this value object + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using System.Reflection; + + public class ValueObject : IEquatable where TValueObject : ValueObject { @@ -22,11 +19,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork //IEquatable and Override Equals operators - /// - /// - /// - /// - /// + public bool Equals(TValueObject other) { if ((object)other == null) @@ -62,11 +55,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork else return true; } - /// - /// - /// - /// - /// + public override bool Equals(object obj) { if ((object)obj == null) @@ -83,10 +72,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork return false; } - /// - /// - /// - /// + public override int GetHashCode() { int hashCode = 31; @@ -119,12 +105,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork return hashCode; } - /// - /// - /// - /// - /// - /// + public static bool operator ==(ValueObject left, ValueObject right) { if (Object.Equals(left, null)) @@ -133,12 +114,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork return left.Equals(right); } - /// - /// - /// - /// - /// - /// + public static bool operator !=(ValueObject left, ValueObject right) { return !(left == right); diff --git a/src/Services/Ordering/Ordering.SqlData/Queries/IOrderdingQueries.cs b/src/Services/Ordering/Ordering.SqlData/Queries/IOrderdingQueries.cs deleted file mode 100644 index 783cf7a47..000000000 --- a/src/Services/Ordering/Ordering.SqlData/Queries/IOrderdingQueries.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Microsoft.eShopOnContainers.Services.Ordering.SqlData.Queries -{ - //The OrderingQueries Contracts/Interfaces could be moved to a third assembly - //We're not putting this contract in the Domain layer assembly because - //queries/joins are just Application's needs and should not be limited - //to the Domain Model restrictions (Aggregates and Repositories restrictions). - // - //In this case we're using the same EF Context but another good approach - //is also to simply use SQL sentences for the queries with any Micro-ORM (like Dapper) or even just ADO.NET - // - //The point is that Queries are IDEMPOTENT and don't need to commit to DDD Domain restrictions - //so could be implemented in a completely orthogonal way in regards the Domain Layer (à la CQRS) - - public interface IOrderdingQueries - { - Task GetAllOrdersIncludingValueObjectsAndChildEntities(); - Task GetOrderById(Guid orderId); - } -} diff --git a/src/Services/Ordering/Ordering.SqlData/Queries/OrderingQueries.cs b/src/Services/Ordering/Ordering.SqlData/Queries/OrderingQueries.cs deleted file mode 100644 index c097acd82..000000000 --- a/src/Services/Ordering/Ordering.SqlData/Queries/OrderingQueries.cs +++ /dev/null @@ -1,98 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -using Microsoft.EntityFrameworkCore; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.Queries; - -namespace Microsoft.eShopOnContainers.Services.Ordering.SqlData.Queries -{ - //In this case, for the Application queries, we're using the same EF Context but another good approach - //is also to simply use SQL sentences for the queries with any Micro-ORM (like Dapper) or even just ADO.NET - // - //The point is that Queries are IDEMPOTENT and don't need to commit to DDD Domain restrictions - //so could be implemented in a completely orthogonal way in regards the Domain Layer (à la CQRS) - - public class OrderingQueries : IOrderdingQueries - { - private OrderingDbContext _dbContext; - - public OrderingQueries(OrderingDbContext orderingDbContext) - { - _dbContext = orderingDbContext; - } - - public async Task GetAllOrdersIncludingValueObjectsAndChildEntities() - { - var orders = await _dbContext.Orders - .Include(o => o.ShippingAddress) - .Include(o => o.BillingAddress) - .Include(o => o.OrderItems) - .ToListAsync(); - - // Dynamically generated a Response-Model that includes only the fields you need in the response. - // This keeps the JSON response minimal. - // Could also use var - dynamic response = orders.Select(o => new - { - id = o.Id, - orderNumber = o.OrderNumber, - buyerId = o.BuyerId, - orderDate = o.OrderDate, - status = o.Status, - shippingAddress = o.ShippingAddress, - billingAddress = o.BillingAddress, - orderItems = o.OrderItems.Select(i => new - { - id = i.Id, - productId = i.ProductId, - unitPrice = i.UnitPrice, - quantity = i.Quantity, - discount = i.Discount - } - ) - }); - - return response; - } - - public async Task GetOrderById(Guid orderId) - { - var order = await _dbContext.Orders - .Include(o => o.ShippingAddress) - .Include(o => o.BillingAddress) - .Include(o => o.OrderItems) - .Where(o => o.Id == orderId) - .SingleOrDefaultAsync(); - - // Dynamically generated a Response-Model that includes only the fields you need in the response. - // This keeps the JSON response minimal. - // Could also use var - dynamic response = new - { - id = order.Id, - orderNumber = order.OrderNumber, - buyerId = order.BuyerId, - orderDate = order.OrderDate, - status = order.Status, - shippingAddress = order.ShippingAddress, - billingAddress = order.BillingAddress, - orderItems = order.OrderItems.Select(i => new - { - id = i.Id, - productId = i.ProductId, - unitPrice = i.UnitPrice, - quantity = i.Quantity, - discount = i.Discount - } - ) - }; - - return response; - } - } -} diff --git a/src/Services/Ordering/Ordering.SqlData/Repositories/OrderRepository.cs b/src/Services/Ordering/Ordering.SqlData/Repositories/OrderRepository.cs deleted file mode 100644 index 7c8140d06..000000000 --- a/src/Services/Ordering/Ordering.SqlData/Repositories/OrderRepository.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.Contracts; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; -using Microsoft.EntityFrameworkCore; - -namespace Microsoft.eShopOnContainers.Services.Ordering.SqlData.Repositories -{ - //1:1 relationship between Repository and Aggregate (i.e. OrderRepository and Order) - public class OrderRepository : IOrderRepository - { - private readonly OrderingDbContext _context; - - public IUnitOfWork UnitOfWork => _context; - - public OrderRepository(OrderingDbContext orderingDbContext) - { - _context = orderingDbContext; - } - - public void Add(Order order) - { - _context.Orders.Add(order); - } - - public void Update(Order order) - { - _context.Orders.Update(order); - } - - public async Task Remove(Guid orderId) - { - var orderToRemove = await _context.Orders.Where(o => o.Id == orderId).SingleOrDefaultAsync(); - _context.Orders.Remove(orderToRemove); - } - - public async Task FindAsync(Guid id) - { - if (id != Guid.Empty) - return await _context.Set().FirstOrDefaultAsync(o => o.Id == id); - else - return null; - } - } - -}