From 309e3b23eb7974b79dd0256247cd37a27d3f0de1 Mon Sep 17 00:00:00 2001 From: espent1004 Date: Mon, 10 Feb 2020 22:41:37 +0100 Subject: [PATCH] More microservices for tenants --- docker-compose.override.yml | 11 + docker-compose.yml | 10 + eShopOnContainers-ServicesAndWebApps.sln | 51 +++ .../Controllers/SavedEventsController.cs | 10 - .../AutofacModules/ApplicationModule.cs | 10 +- .../TenantACustomisations/Startup.cs | 3 +- .../TenantACustomisations.csproj | 4 + .../ShippingInformationsController.cs | 106 +++++ .../Database/DbInitializer.cs | 7 +- .../Database/TenantAContext.cs | 20 +- .../ExternalServices/IShippingService.cs | 8 +- .../ExternalServices/MockedShippingService.cs | 7 +- .../AutofacModules/ApplicationModule.cs | 6 +- ...tatusChangedToSubmittedIntegrationEvent.cs | 6 +- .../Models/Fragility.cs | 7 +- .../Models/Priority.cs | 7 +- .../Models/ShippingInformation.cs | 5 +- .../TenantAShippingInformation/Startup.cs | 20 +- .../appsettings.json | 2 +- .../ShippingInformationsController.cs | 106 +++++ .../Database/DbInitializer.cs | 6 +- .../Database/TenantAContext.cs | 28 -- .../Database/TenantBContext.cs | 28 ++ .../TenantBShippingInformation/Dockerfile | 4 +- .../ExternalServices/IShippingService.cs | 4 +- .../ExternalServices/MockedShippingService.cs | 4 +- .../AutofacModules/ApplicationModule.cs | 10 +- .../AutofacModules/MediatorModule.cs | 2 +- .../Filters/AuthorizeCheckOperationFilter.cs | 2 +- .../Filters/HttpGlobalExceptionFilter.cs | 2 +- ...angedToSubmittedIntegrationEventHandler.cs | 22 +- .../Models/Fragility.cs | 2 +- .../Models/Priority.cs | 2 +- .../Models/ShippingInformation.cs | 2 +- .../TenantBShippingInformation/Program.cs | 87 ++++ .../Properties/launchSettings.json | 27 ++ .../TenantBShippingInformation/Startup.cs | 414 ++++++++++++++++++ .../TenantBShippingInformation.csproj | 56 +++ .../appsettings.Development.json | 9 + .../appsettings.json | 29 ++ .../TenantManager/Database/DbInitializer.cs | 3 - src/Web/WebMVC/Controllers/OrderController.cs | 15 +- src/Web/WebMVC/Views/Order/Index.cshtml | 113 +++-- 43 files changed, 1098 insertions(+), 179 deletions(-) create mode 100644 src/Services/TenantCustomisations/TenantAShippingInformation/Controllers/ShippingInformationsController.cs create mode 100644 src/Services/TenantCustomisations/TenantBShippingInformation/Controllers/ShippingInformationsController.cs delete mode 100644 src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantAContext.cs create mode 100644 src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantBContext.cs create mode 100644 src/Services/TenantCustomisations/TenantBShippingInformation/Program.cs create mode 100644 src/Services/TenantCustomisations/TenantBShippingInformation/Properties/launchSettings.json create mode 100644 src/Services/TenantCustomisations/TenantBShippingInformation/Startup.cs create mode 100644 src/Services/TenantCustomisations/TenantBShippingInformation/TenantBShippingInformation.csproj create mode 100644 src/Services/TenantCustomisations/TenantBShippingInformation/appsettings.Development.json create mode 100644 src/Services/TenantCustomisations/TenantBShippingInformation/appsettings.json diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 1ee9cd03e..9dd111b8a 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -78,9 +78,20 @@ services: - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - AzureServiceBusEnabled=False + - ConnectionString=${ESHOP_AZURE_CATALOG_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.TenantAShippingInformationDb;User Id=sa;Password=Pass@word} ports: - "5117:80" + tenantbshippinginformation: + environment: + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} + - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} + - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} + - AzureServiceBusEnabled=False + - ConnectionString=${ESHOP_AZURE_CATALOG_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.TenantBShippingInformationDb;User Id=sa;Password=Pass@word} + ports: + - "5118:80" + basket.api: environment: - ASPNETCORE_ENVIRONMENT=Development diff --git a/docker-compose.yml b/docker-compose.yml index 45401646e..7a4d35b12 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -56,6 +56,16 @@ services: build: context: . dockerfile: src/Services/TenantCustomisations/TenantAShippingInformation/Dockerfile + depends_on: + - sql.data + + tenantbshippinginformation: + image: ${REGISTRY:-eshop}/tenantbshippinginformation:${PLATFORM:-linux}-${TAG:-latest} + build: + context: . + dockerfile: src/Services/TenantCustomisations/TenantBShippingInformation/Dockerfile + depends_on: + - sql.data catalog.api: image: ${REGISTRY:-eshop}/catalog.api:${PLATFORM:-linux}-${TAG:-latest} diff --git a/eShopOnContainers-ServicesAndWebApps.sln b/eShopOnContainers-ServicesAndWebApps.sln index 7202f9703..538f67c9f 100644 --- a/eShopOnContainers-ServicesAndWebApps.sln +++ b/eShopOnContainers-ServicesAndWebApps.sln @@ -160,6 +160,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TenantACustomisations", "sr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TenantAShippingInformation", "src\Services\TenantCustomisations\TenantAShippingInformation\TenantAShippingInformation.csproj", "{6228E4B8-4672-4253-9F9F-2F75BD40623B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TenantBShippingInformation", "src\Services\TenantCustomisations\TenantBShippingInformation\TenantBShippingInformation.csproj", "{B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Ad-Hoc|Any CPU = Ad-Hoc|Any CPU @@ -1950,6 +1952,54 @@ Global {6228E4B8-4672-4253-9F9F-2F75BD40623B}.Release|x64.Build.0 = Release|Any CPU {6228E4B8-4672-4253-9F9F-2F75BD40623B}.Release|x86.ActiveCfg = Release|Any CPU {6228E4B8-4672-4253-9F9F-2F75BD40623B}.Release|x86.Build.0 = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|x64.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Ad-Hoc|x86.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|ARM.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|ARM.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|iPhone.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|x64.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|x64.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|x86.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.AppStore|x86.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|ARM.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|ARM.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|iPhone.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|x64.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|x64.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|x86.ActiveCfg = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Debug|x86.Build.0 = Debug|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|Any CPU.Build.0 = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|ARM.ActiveCfg = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|ARM.Build.0 = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|iPhone.ActiveCfg = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|iPhone.Build.0 = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|x64.ActiveCfg = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|x64.Build.0 = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|x86.ActiveCfg = Release|Any CPU + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2021,6 +2071,7 @@ Global {773A0C2A-CA6F-4D4A-860B-C518EFA6FACB} = {91CF7717-08AB-4E65-B10E-0B426F01E2E8} {76651DAE-FF27-44A4-AF84-34689E2FFDF2} = {773A0C2A-CA6F-4D4A-860B-C518EFA6FACB} {6228E4B8-4672-4253-9F9F-2F75BD40623B} = {773A0C2A-CA6F-4D4A-860B-C518EFA6FACB} + {B18DE120-E00E-4456-AAA3-ECFDD01FAEAA} = {773A0C2A-CA6F-4D4A-860B-C518EFA6FACB} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {25728519-5F0F-4973-8A64-0A81EB4EA8D9} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/Controllers/SavedEventsController.cs b/src/Services/TenantCustomisations/TenantACustomisations/Controllers/SavedEventsController.cs index a90a8df7c..705520092 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/Controllers/SavedEventsController.cs +++ b/src/Services/TenantCustomisations/TenantACustomisations/Controllers/SavedEventsController.cs @@ -24,7 +24,6 @@ namespace TenantACustomisations.Controllers private List types = new List() { - typeof(OrderStatusChangedToSubmittedIntegrationEvent), typeof(OrderStatusChangedToAwaitingValidationIntegrationEvent) }; @@ -74,15 +73,6 @@ namespace TenantACustomisations.Controllers found = true; } } - else if(e is OrderStatusChangedToSubmittedIntegrationEvent) - { - OrderStatusChangedToSubmittedIntegrationEvent evt = (OrderStatusChangedToSubmittedIntegrationEvent)e; - if (evt.OrderId == Int32.Parse(orderId)) - { - found = true; - - } - } }); if (!found) diff --git a/src/Services/TenantCustomisations/TenantACustomisations/Infrastructure/AutofacModules/ApplicationModule.cs b/src/Services/TenantCustomisations/TenantACustomisations/Infrastructure/AutofacModules/ApplicationModule.cs index ea46f0586..0bea344cc 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/Infrastructure/AutofacModules/ApplicationModule.cs +++ b/src/Services/TenantCustomisations/TenantACustomisations/Infrastructure/AutofacModules/ApplicationModule.cs @@ -21,13 +21,9 @@ namespace Microsoft.eShopOnContainers.Services.TenantACustomisations.Infrastruct protected override void Load(ContainerBuilder builder) { - builder.RegisterAssemblyTypes(typeof(UserCheckoutAcceptedIntegrationEvent).GetTypeInfo().Assembly) - .AsClosedTypesOf(typeof(IIntegrationEventHandler<>)); - - - builder.RegisterType() - .As() - .InstancePerLifetimeScope(); + /*builder.RegisterAssemblyTypes(typeof(UserCheckoutAcceptedIntegrationEvent).GetTypeInfo().Assembly) + .AsClosedTypesOf(typeof(IIntegrationEventHandler<>));*/ + } } } diff --git a/src/Services/TenantCustomisations/TenantACustomisations/Startup.cs b/src/Services/TenantCustomisations/TenantACustomisations/Startup.cs index b61568d67..468e377f7 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/Startup.cs +++ b/src/Services/TenantCustomisations/TenantACustomisations/Startup.cs @@ -34,7 +34,6 @@ using Microsoft.eShopOnContainers.Services.TenantACustomisations.Infrastructure.Filters; using global::TenantACustomisations.Infrastructure.Filters; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - using global::TenantACustomisations.IntegrationEvents.EventHandling; using global::TenantACustomisations.IntegrationEvents.Events; using global::TenantACustomisations.ExternalServices; using global::TenantACustomisations.Database; @@ -123,7 +122,7 @@ var eventBus = app.ApplicationServices.GetRequiredService(); //eventBus.Subscribe>(); - eventBus.Subscribe(); + //eventBus.Subscribe(); } diff --git a/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj b/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj index 855195623..91d5a7cb4 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj +++ b/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj @@ -56,4 +56,8 @@ + + + + diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Controllers/ShippingInformationsController.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Controllers/ShippingInformationsController.cs new file mode 100644 index 000000000..cab194e82 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Controllers/ShippingInformationsController.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using TenantAShippingInformation.Database; +using TenantAShippingInformation.Models; + +namespace TenantAShippingInformation.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ShippingInformationsController : ControllerBase + { + private readonly TenantAContext _context; + + public ShippingInformationsController(TenantAContext context) + { + _context = context; + } + + // GET: api/ShippingInformations + [HttpGet] + public async Task>> GetShippingInformation() + { + return await _context.ShippingInformation.ToListAsync(); + } + + // GET: api/ShippingInformations/5 + [HttpGet("{id}")] + public async Task> GetShippingInformation(int id) + { + var shippingInformation = await _context.ShippingInformation.FindAsync(id); + + if (shippingInformation == null) + { + return NotFound(); + } + + return shippingInformation; + } + + // PUT: api/ShippingInformations/5 + [HttpPut("{id}")] + public async Task PutShippingInformation(int id, ShippingInformation shippingInformation) + { + if (id != shippingInformation.ShippingInformationId) + { + return BadRequest(); + } + + _context.Entry(shippingInformation).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!ShippingInformationExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/ShippingInformations + [HttpPost] + public async Task> PostShippingInformation(ShippingInformation shippingInformation) + { + _context.ShippingInformation.Add(shippingInformation); + await _context.SaveChangesAsync(); + + return CreatedAtAction("GetShippingInformation", new { id = shippingInformation.ShippingInformationId }, shippingInformation); + } + + // DELETE: api/ShippingInformations/5 + [HttpDelete("{id}")] + public async Task> DeleteShippingInformation(int id) + { + var shippingInformation = await _context.ShippingInformation.FindAsync(id); + if (shippingInformation == null) + { + return NotFound(); + } + + _context.ShippingInformation.Remove(shippingInformation); + await _context.SaveChangesAsync(); + + return shippingInformation; + } + + private bool ShippingInformationExists(int id) + { + return _context.ShippingInformation.Any(e => e.ShippingInformationId == id); + } + } +} diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Database/DbInitializer.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Database/DbInitializer.cs index 1c2aa2da7..33b06d0c6 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/Database/DbInitializer.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Database/DbInitializer.cs @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; -using TenantACustomisations.ExternalServices; +using TenantAShippingInformation.Models; -namespace TenantACustomisations.Database +namespace TenantAShippingInformation.Database { public class DbInitializer { @@ -28,7 +26,6 @@ namespace TenantACustomisations.Database context.SaveChanges(); - } } } diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Database/TenantAContext.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Database/TenantAContext.cs index 222d63dd8..022772bd1 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/Database/TenantAContext.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Database/TenantAContext.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; -using TenantACustomisations.ExternalServices; -using TenantACustomisations.IntegrationEvents.Events; +using TenantAShippingInformation.Models; -namespace TenantACustomisations.Database +namespace TenantAShippingInformation.Database { public class TenantAContext : DbContext { @@ -17,12 +12,7 @@ namespace TenantACustomisations.Database } public DbSet ShippingInformation { get; set; } - - public DbSet SavedEvent - { - get; - set; - } + } public class TenantAContextDesignFactory : IDesignTimeDbContextFactory @@ -30,7 +20,7 @@ namespace TenantACustomisations.Database public TenantAContext CreateDbContext(string[] args) { var optionsBuilder = new DbContextOptionsBuilder() - .UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.TenantADb;Integrated Security=true"); + .UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.TenantAShippingInformationDb;Integrated Security=true"); return new TenantAContext(optionsBuilder.Options); } diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/IShippingService.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/IShippingService.cs index 3db814143..a7ad190fb 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/IShippingService.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/IShippingService.cs @@ -1,10 +1,6 @@ -using Ordering.API.Application.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using TenantAShippingInformation.Models; -namespace TenantACustomisations.ExternalServices +namespace TenantAShippingInformation.ExternalServices { public interface IShippingService { diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/MockedShippingService.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/MockedShippingService.cs index 7dc39a90b..6ae7e1f1d 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/MockedShippingService.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/MockedShippingService.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Ordering.API.Application.Models; +using TenantAShippingInformation.Models; -namespace TenantACustomisations.ExternalServices +namespace TenantAShippingInformation.ExternalServices { public class MockedShippingService : IShippingService { diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs index 54fc370be..7d4cf74bb 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs @@ -1,6 +1,7 @@ using Autofac; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using System.Reflection; +using TenantAShippingInformation.ExternalServices; using TenantAShippingInformation.IntegrationEvents.EventHandling; namespace TenantAShippingInformation.Infrastructure.AutofacModules @@ -20,9 +21,12 @@ namespace TenantAShippingInformation.Infrastructure.AutofacModules protected override void Load(ContainerBuilder builder) { - builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToAwaitingValidationIntegrationEventHandler).GetTypeInfo().Assembly) + builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToSubmittedIntegrationEventHandler).GetTypeInfo().Assembly) .AsClosedTypesOf(typeof(IIntegrationEventHandler<>)); + builder.RegisterType() + .As() + .InstancePerLifetimeScope(); } } } diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs index 1b929c3c4..042746d89 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs @@ -1,10 +1,6 @@ using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace TenantACustomisations.IntegrationEvents.Events +namespace TenantAShippingInformation.IntegrationEvents.Events { public class OrderStatusChangedToSubmittedIntegrationEvent : IntegrationEvent { diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Fragility.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Fragility.cs index a2afffc22..17c04e0c0 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Fragility.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Fragility.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace TenantACustomisations.ExternalServices +namespace TenantAShippingInformation.Models { public enum Fragility { diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Priority.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Priority.cs index cd0efcb73..b5c245641 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Priority.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Priority.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace TenantACustomisations.ExternalServices +namespace TenantAShippingInformation.Models { public enum Priority { diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Models/ShippingInformation.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/ShippingInformation.cs index f83a7d5cb..8361e1786 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/Models/ShippingInformation.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/ShippingInformation.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace TenantACustomisations.ExternalServices +namespace TenantAShippingInformation.Models { public class ShippingInformation { diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Startup.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Startup.cs index 09b3a0aeb..71dfd33d0 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/Startup.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Startup.cs @@ -27,8 +27,12 @@ using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; using RabbitMQ.Client; using Swashbuckle.AspNetCore.Swagger; +using TenantAShippingInformation.Database; using TenantAShippingInformation.Infrastructure.AutofacModules; +using TenantAShippingInformation; using TenantAShippingInformation.Infrastructure.Filters; +using TenantAShippingInformation.IntegrationEvents.EventHandling; +using TenantAShippingInformation.IntegrationEvents.Events; namespace TenantAShippingInformation { @@ -103,11 +107,11 @@ namespace TenantAShippingInformation }); ConfigureEventBus(app); - //using (var serviceScope = app.ApplicationServices.GetService().CreateScope()) - //{ - // var context = serviceScope.ServiceProvider.GetRequiredService(); - // context.Database.EnsureCreated(); - //} + using (var serviceScope = app.ApplicationServices.GetService().CreateScope()) + { + var context = serviceScope.ServiceProvider.GetRequiredService(); + context.Database.EnsureCreated(); + } } @@ -116,7 +120,7 @@ namespace TenantAShippingInformation var eventBus = app.ApplicationServices.GetRequiredService(); //eventBus.Subscribe>(); - //eventBus.Subscribe(); + eventBus.Subscribe(); } @@ -213,8 +217,8 @@ namespace TenantAShippingInformation public static IServiceCollection AddCustomDbContext(this IServiceCollection services, IConfiguration configuration) { - //services.AddDbContext(options => - // options.UseSqlServer(configuration["ConnectionString"])); + services.AddDbContext(options => + options.UseSqlServer(configuration["ConnectionString"])); services.AddDbContext(options => { diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/appsettings.json b/src/Services/TenantCustomisations/TenantAShippingInformation/appsettings.json index 6dc768b13..8cb02be2a 100644 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/appsettings.json +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/appsettings.json @@ -13,7 +13,7 @@ }, "IdentityUrl": "http://localhost:5105", //"ConnectionString": "127.0.0.1", - "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.TenantADb;User Id=sa;Password=Pass@word;", + "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.TenantAShippingInformationDb;User Id=sa;Password=Pass@word;", "AzureServiceBusEnabled": false, "SubscriptionClientName": "TenantAShippingInformation", "ApplicationInsights": { diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Controllers/ShippingInformationsController.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Controllers/ShippingInformationsController.cs new file mode 100644 index 000000000..b10fa80b7 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Controllers/ShippingInformationsController.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using TenantBShippingInformation.Database; +using TenantBShippingInformation.Models; + +namespace TenantBShippingInformation.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ShippingInformationsController : ControllerBase + { + private readonly TenantBContext _context; + + public ShippingInformationsController(TenantBContext context) + { + _context = context; + } + + // GET: api/ShippingInformations + [HttpGet] + public async Task>> GetShippingInformation() + { + return await _context.ShippingInformation.ToListAsync(); + } + + // GET: api/ShippingInformations/5 + [HttpGet("{id}")] + public async Task> GetShippingInformation(int id) + { + var shippingInformation = await _context.ShippingInformation.FindAsync(id); + + if (shippingInformation == null) + { + return NotFound(); + } + + return shippingInformation; + } + + // PUT: api/ShippingInformations/5 + [HttpPut("{id}")] + public async Task PutShippingInformation(int id, ShippingInformation shippingInformation) + { + if (id != shippingInformation.ShippingInformationId) + { + return BadRequest(); + } + + _context.Entry(shippingInformation).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!ShippingInformationExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/ShippingInformations + [HttpPost] + public async Task> PostShippingInformation(ShippingInformation shippingInformation) + { + _context.ShippingInformation.Add(shippingInformation); + await _context.SaveChangesAsync(); + + return CreatedAtAction("GetShippingInformation", new { id = shippingInformation.ShippingInformationId }, shippingInformation); + } + + // DELETE: api/ShippingInformations/5 + [HttpDelete("{id}")] + public async Task> DeleteShippingInformation(int id) + { + var shippingInformation = await _context.ShippingInformation.FindAsync(id); + if (shippingInformation == null) + { + return NotFound(); + } + + _context.ShippingInformation.Remove(shippingInformation); + await _context.SaveChangesAsync(); + + return shippingInformation; + } + + private bool ShippingInformationExists(int id) + { + return _context.ShippingInformation.Any(e => e.ShippingInformationId == id); + } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Database/DbInitializer.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Database/DbInitializer.cs index 33b06d0c6..91de72708 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/Database/DbInitializer.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Database/DbInitializer.cs @@ -1,12 +1,12 @@ using System; using System.Linq; -using TenantAShippingInformation.Models; +using TenantBShippingInformation.Models; -namespace TenantAShippingInformation.Database +namespace TenantBShippingInformation.Database { public class DbInitializer { - public void Initialize(TenantAContext context) + public void Initialize(TenantBContext context) { context.Database.EnsureCreated(); diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantAContext.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantAContext.cs deleted file mode 100644 index 022772bd1..000000000 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantAContext.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Design; -using TenantAShippingInformation.Models; - -namespace TenantAShippingInformation.Database -{ - public class TenantAContext : DbContext - { - public TenantAContext(DbContextOptions options) - : base(options) - { - } - - public DbSet ShippingInformation { get; set; } - - - } - public class TenantAContextDesignFactory : IDesignTimeDbContextFactory - { - public TenantAContext CreateDbContext(string[] args) - { - var optionsBuilder = new DbContextOptionsBuilder() - .UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.TenantAShippingInformationDb;Integrated Security=true"); - - return new TenantAContext(optionsBuilder.Options); - } - } -} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantBContext.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantBContext.cs new file mode 100644 index 000000000..e0fcc711f --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantBContext.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using TenantBShippingInformation.Models; + +namespace TenantBShippingInformation.Database +{ + public class TenantBContext : DbContext + { + public TenantBContext(DbContextOptions options) + : base(options) + { + } + + public DbSet ShippingInformation { get; set; } + + + } + public class TenantBContextDesignFactory : IDesignTimeDbContextFactory + { + public TenantBContext CreateDbContext(string[] args) + { + var optionsBuilder = new DbContextOptionsBuilder() + .UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.TenantBShippingInformationDb;Integrated Security=true"); + + return new TenantBContext(optionsBuilder.Options); + } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Dockerfile b/src/Services/TenantCustomisations/TenantBShippingInformation/Dockerfile index cb6d18737..cf42e4609 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/Dockerfile +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Dockerfile @@ -48,7 +48,7 @@ COPY test/ServicesTests/LoadTest/LoadTest.csproj test/ServicesTests/LoadTest/ RUN dotnet restore eShopOnContainers-ServicesAndWebApps.sln COPY . . -WORKDIR /src/src/Services/TenantCustomisations/TenantAShippingInformation +WORKDIR /src/src/Services/TenantCustomisations/TenantBShippingInformation RUN dotnet publish --no-restore -c Release -o /app FROM build AS publish @@ -56,4 +56,4 @@ FROM build AS publish FROM base AS final WORKDIR /app COPY --from=publish /app . -ENTRYPOINT ["dotnet", "TenantAShippingInformation.dll"] +ENTRYPOINT ["dotnet", "TenantBShippingInformation.dll"] diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/IShippingService.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/IShippingService.cs index a7ad190fb..644669089 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/IShippingService.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/IShippingService.cs @@ -1,6 +1,6 @@ -using TenantAShippingInformation.Models; +using TenantBShippingInformation.Models; -namespace TenantAShippingInformation.ExternalServices +namespace TenantBShippingInformation.ExternalServices { public interface IShippingService { diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/MockedShippingService.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/MockedShippingService.cs index 6ae7e1f1d..c00201d5c 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/MockedShippingService.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/MockedShippingService.cs @@ -1,7 +1,7 @@ using System; -using TenantAShippingInformation.Models; +using TenantBShippingInformation.Models; -namespace TenantAShippingInformation.ExternalServices +namespace TenantBShippingInformation.ExternalServices { public class MockedShippingService : IShippingService { diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs index 54fc370be..05e1956cc 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs @@ -1,9 +1,10 @@ using Autofac; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using System.Reflection; -using TenantAShippingInformation.IntegrationEvents.EventHandling; +using TenantBShippingInformation.ExternalServices; +using TenantBShippingInformation.IntegrationEvents.EventHandling; -namespace TenantAShippingInformation.Infrastructure.AutofacModules +namespace TenantBShippingInformation.Infrastructure.AutofacModules { public class ApplicationModule @@ -20,9 +21,12 @@ namespace TenantAShippingInformation.Infrastructure.AutofacModules protected override void Load(ContainerBuilder builder) { - builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToAwaitingValidationIntegrationEventHandler).GetTypeInfo().Assembly) + builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToSubmittedIntegrationEventHandler).GetTypeInfo().Assembly) .AsClosedTypesOf(typeof(IIntegrationEventHandler<>)); + builder.RegisterType() + .As() + .InstancePerLifetimeScope(); } } } diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/MediatorModule.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/MediatorModule.cs index 8f8fe2da2..13f0e267e 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/MediatorModule.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/MediatorModule.cs @@ -1,6 +1,6 @@ using Autofac; -namespace TenantAShippingInformation.Infrastructure.AutofacModules +namespace TenantBShippingInformation.Infrastructure.AutofacModules { public class MediatorModule : Autofac.Module { diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs index 2c694dfbd..8d8614867 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace TenantAShippingInformation.Infrastructure.Filters +namespace TenantBShippingInformation.Infrastructure.Filters { public class AuthorizeCheckOperationFilter : IOperationFilter { diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/HttpGlobalExceptionFilter.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/HttpGlobalExceptionFilter.cs index d1b84d2fd..d8b3b65f9 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/HttpGlobalExceptionFilter.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/HttpGlobalExceptionFilter.cs @@ -1,4 +1,4 @@ -namespace TenantAShippingInformation.Infrastructure.Filters +namespace TenantBShippingInformation.Infrastructure.Filters { using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs index 2409cdd84..8e7f4e5d7 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs @@ -7,7 +7,10 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using TenantBShippingInformation.Database; +using TenantBShippingInformation.ExternalServices; using TenantBShippingInformation.IntegrationEvents.Events; +using TenantBShippingInformation.Models; namespace TenantBShippingInformation.IntegrationEvents.EventHandling { @@ -15,19 +18,28 @@ namespace TenantBShippingInformation.IntegrationEvents.EventHandling IIntegrationEventHandler { private readonly ILogger _logger; + private readonly IShippingService _shippingService; + private readonly TenantBContext _context; - public OrderStatusChangedToSubmittedIntegrationEventHandler(ILogger logger) + public OrderStatusChangedToSubmittedIntegrationEventHandler(ILogger logger, IShippingService shippingService, TenantBContext context) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _shippingService = shippingService ?? throw new ArgumentNullException(nameof(shippingService)); + _context = context ?? throw new ArgumentNullException(nameof(shippingService)); } public async Task Handle(OrderStatusChangedToSubmittedIntegrationEvent @event) { - using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA")) + using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantB")) { - //TODO - Debug.WriteLine(@event); - + using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantB")) + { + _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at TenantB - ({@IntegrationEvent})", @event.Id, @event); + ShippingInformation shippingInformation = _shippingService.CalculateShippingInformation(@event.OrderId); + _context.ShippingInformation.Add(shippingInformation); + _logger.LogInformation("----- Saving shipping information: {IntegrationEventId} at TenantA - ({@IntegrationEvent}) - {@ShippingInformation}", @event.Id, @event, shippingInformation); + _context.SaveChanges(); + } } } } diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Fragility.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Fragility.cs index 17c04e0c0..bc5a89a9f 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Fragility.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Fragility.cs @@ -1,4 +1,4 @@ -namespace TenantAShippingInformation.Models +namespace TenantBShippingInformation.Models { public enum Fragility { diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Priority.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Priority.cs index b5c245641..49d3ccad0 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Priority.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Priority.cs @@ -1,4 +1,4 @@ -namespace TenantAShippingInformation.Models +namespace TenantBShippingInformation.Models { public enum Priority { diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Models/ShippingInformation.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/ShippingInformation.cs index 8361e1786..07907c0b0 100644 --- a/src/Services/TenantCustomisations/TenantBShippingInformation/Models/ShippingInformation.cs +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/ShippingInformation.cs @@ -1,6 +1,6 @@ using System; -namespace TenantAShippingInformation.Models +namespace TenantBShippingInformation.Models { public class ShippingInformation { diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Program.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Program.cs new file mode 100644 index 000000000..4d3409fd1 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Program.cs @@ -0,0 +1,87 @@ +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Serilog; +using System; +using System.IO; + +namespace TenantBShippingInformation +{ + public class Program + { + public static readonly string Namespace = typeof(Program).Namespace; + public static readonly string AppName = Namespace; + + public static int Main(string[] args) + { + var configuration = GetConfiguration(); + + Log.Logger = CreateSerilogLogger(configuration); + + try + { + Log.Information("Configuring web host ({ApplicationContext})...", AppName); + var host = BuildWebHost(configuration, args); + + Log.Information("Starting web host ({ApplicationContext})...", AppName); + host.Run(); + + return 0; + } + catch (Exception ex) + { + Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName); + return 1; + } + finally + { + Log.CloseAndFlush(); + } + } + + private static IWebHost BuildWebHost(IConfiguration configuration, string[] args) => + WebHost.CreateDefaultBuilder(args) + .CaptureStartupErrors(false) + .UseStartup() + .UseApplicationInsights() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseConfiguration(configuration) + .UseSerilog() + .Build(); + + private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration) + { + var seqServerUrl = configuration["Serilog:SeqServerUrl"]; + var logstashUrl = configuration["Serilog:LogstashgUrl"]; + return new LoggerConfiguration() + .MinimumLevel.Verbose() + .Enrich.WithProperty("ApplicationContext", AppName) + .Enrich.FromLogContext() + .WriteTo.Console() + .WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl) + .WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl) + .ReadFrom.Configuration(configuration) + .CreateLogger(); + } + + private static IConfiguration GetConfiguration() + { + var builder = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddEnvironmentVariables(); + + var config = builder.Build(); + + if (config.GetValue("UseVault", false)) + { + builder.AddAzureKeyVault( + $"https://{config["Vault:Name"]}.vault.azure.net/", + config["Vault:ClientId"], + config["Vault:ClientSecret"]); + } + + return builder.Build(); + } + } +} \ No newline at end of file diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Properties/launchSettings.json b/src/Services/TenantCustomisations/TenantBShippingInformation/Properties/launchSettings.json new file mode 100644 index 000000000..68fc74a22 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:50373", + "sslPort": 44351 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "TenantBShippingInformation": { + "commandName": "Project", + "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Startup.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Startup.cs new file mode 100644 index 000000000..50f3e3434 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Startup.cs @@ -0,0 +1,414 @@ +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.IdentityModel.Tokens.Jwt; +using System.Reflection; +using Autofac; +using Autofac.Extensions.DependencyInjection; +using HealthChecks.UI.Client; +using Microsoft.ApplicationInsights.Extensibility; +using Microsoft.ApplicationInsights.ServiceFabric; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Azure.ServiceBus; +using Microsoft.EntityFrameworkCore; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; +using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; +using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Logging; +using RabbitMQ.Client; +using Swashbuckle.AspNetCore.Swagger; +using TenantBShippingInformation.Infrastructure.AutofacModules; +using TenantBShippingInformation.Infrastructure.Filters; +using TenantBShippingInformation.Database; +using TenantBShippingInformation.IntegrationEvents.Events; +using TenantBShippingInformation.IntegrationEvents.EventHandling; + +namespace TenantBShippingInformation +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + public IServiceProvider ConfigureServices(IServiceCollection services) + { + services.AddApplicationInsights(Configuration) + .AddCustomMvc() + .AddHealthChecks(Configuration) + .AddCustomDbContext(Configuration) + .AddCustomSwagger(Configuration) + .AddCustomIntegrations(Configuration) + .AddCustomConfiguration(Configuration) + .AddEventBus(Configuration) + .AddCustomAuthentication(Configuration); + + //configure autofac + + var container = new ContainerBuilder(); + container.Populate(services); + + container.RegisterModule(new MediatorModule()); + container.RegisterModule(new ApplicationModule(Configuration["ConnectionString"])); + + return new AutofacServiceProvider(container.Build()); + } + + + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) + { + //loggerFactory.AddAzureWebAppDiagnostics(); + //loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); + + var pathBase = Configuration["PATH_BASE"]; + if (!string.IsNullOrEmpty(pathBase)) + { + loggerFactory.CreateLogger().LogDebug("Using PATH BASE '{pathBase}'", pathBase); + app.UsePathBase(pathBase); + } + + app.UseCors("CorsPolicy"); + + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + + app.UseHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + + ConfigureAuth(app); + + app.UseMvcWithDefaultRoute(); + + app.UseSwagger() + .UseSwaggerUI(c => + { + c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Ordering.API V1"); + c.OAuthClientId("orderingswaggerui"); + c.OAuthAppName("Ordering Swagger UI"); + }); + + ConfigureEventBus(app); + using (var serviceScope = app.ApplicationServices.GetService().CreateScope()) + { + var context = serviceScope.ServiceProvider.GetRequiredService(); + context.Database.EnsureCreated(); + } + } + + + private void ConfigureEventBus(IApplicationBuilder app) + { + var eventBus = app.ApplicationServices.GetRequiredService(); + + //eventBus.Subscribe>(); + eventBus.Subscribe(); + + } + + protected virtual void ConfigureAuth(IApplicationBuilder app) + { + if (Configuration.GetValue("UseLoadTest")) + { + //app.UseMiddleware(); + //TODO + } + + app.UseAuthentication(); + } + } + + static class CustomExtensionsMethods + { + public static IServiceCollection AddApplicationInsights(this IServiceCollection services, IConfiguration configuration) + { + services.AddApplicationInsightsTelemetry(configuration); + var orchestratorType = configuration.GetValue("OrchestratorType"); + + if (orchestratorType?.ToUpper() == "K8S") + { + // Enable K8s telemetry initializer + services.AddApplicationInsightsKubernetesEnricher(); + } + if (orchestratorType?.ToUpper() == "SF") + { + // Enable SF telemetry initializer + services.AddSingleton((serviceProvider) => + new FabricTelemetryInitializer()); + } + + return services; + } + + public static IServiceCollection AddCustomMvc(this IServiceCollection services) + { + // Add framework services. + services.AddMvc(options => + { + options.Filters.Add(typeof(HttpGlobalExceptionFilter)); + }) + .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) + .AddControllersAsServices(); //Injecting Controllers themselves thru DI + //For further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services + + services.AddCors(options => + { + options.AddPolicy("CorsPolicy", + builder => builder + .SetIsOriginAllowed((host) => true) + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials()); + }); + + return services; + } + + public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration) + { + var hcBuilder = services.AddHealthChecks(); + + hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); + + hcBuilder + .AddSqlServer( + configuration["ConnectionString"], + name: "OrderingDB-check", + tags: new string[] { "orderingdb" }); + + if (configuration.GetValue("AzureServiceBusEnabled")) + { + hcBuilder + .AddAzureServiceBusTopic( + configuration["EventBusConnection"], + topicName: "eshop_event_bus", + name: "ordering-servicebus-check", + tags: new string[] { "servicebus" }); + } + else + { + hcBuilder + .AddRabbitMQ( + $"amqp://{configuration["EventBusConnection"]}", + name: "ordering-rabbitmqbus-check", + tags: new string[] { "rabbitmqbus" }); + } + + return services; + } + + public static IServiceCollection AddCustomDbContext(this IServiceCollection services, IConfiguration configuration) + { + services.AddDbContext(options => + options.UseSqlServer(configuration["ConnectionString"])); + + services.AddDbContext(options => + { + options.UseSqlServer(configuration["ConnectionString"], + sqlServerOptionsAction: sqlOptions => + { + sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name); + //Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency + sqlOptions.EnableRetryOnFailure(maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); + }); + }); + + return services; + } + + public static IServiceCollection AddCustomSwagger(this IServiceCollection services, IConfiguration configuration) + { + services.AddSwaggerGen(options => + { + options.DescribeAllEnumsAsStrings(); + options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info + { + Title = "Ordering HTTP API", + Version = "v1", + Description = "The Ordering Service HTTP API", + TermsOfService = "Terms Of Service" + }); + + options.AddSecurityDefinition("oauth2", new OAuth2Scheme + { + Type = "oauth2", + Flow = "implicit", + AuthorizationUrl = $"{configuration.GetValue("IdentityUrlExternal")}/connect/authorize", + TokenUrl = $"{configuration.GetValue("IdentityUrlExternal")}/connect/token", + Scopes = new Dictionary() + { + { "orders", "Ordering API" } + } + }); + + options.OperationFilter(); + }); + + return services; + } + + public static IServiceCollection AddCustomIntegrations(this IServiceCollection services, IConfiguration configuration) + { + services.AddSingleton(); + //services.AddTransient(); + services.AddTransient>( + sp => (DbConnection c) => new IntegrationEventLogService(c)); + + //services.AddTransient(); + if (configuration.GetValue("AzureServiceBusEnabled")) + { + services.AddSingleton(sp => + { + var logger = sp.GetRequiredService>(); + + var serviceBusConnectionString = configuration["EventBusConnection"]; + var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString); + + return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger); + }); + } + else + { + services.AddSingleton(sp => + { + var logger = sp.GetRequiredService>(); + + + var factory = new ConnectionFactory() + { + HostName = configuration["EventBusConnection"], + DispatchConsumersAsync = true + }; + + if (!string.IsNullOrEmpty(configuration["EventBusUserName"])) + { + factory.UserName = configuration["EventBusUserName"]; + } + + if (!string.IsNullOrEmpty(configuration["EventBusPassword"])) + { + factory.Password = configuration["EventBusPassword"]; + } + + factory.VirtualHost = "TenantB"; + + var retryCount = 5; + if (!string.IsNullOrEmpty(configuration["EventBusRetryCount"])) + { + retryCount = int.Parse(configuration["EventBusRetryCount"]); + } + + return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount); + }); + } + + return services; + } + + public static IServiceCollection AddCustomConfiguration(this IServiceCollection services, IConfiguration configuration) + { + services.AddOptions(); + //services.Configure(configuration); + services.Configure(options => + { + options.InvalidModelStateResponseFactory = context => + { + var problemDetails = new ValidationProblemDetails(context.ModelState) + { + Instance = context.HttpContext.Request.Path, + Status = StatusCodes.Status400BadRequest, + Detail = "Please refer to the errors property for additional details." + }; + + return new BadRequestObjectResult(problemDetails) + { + ContentTypes = { "application/problem+json", "application/problem+xml" } + }; + }; + }); + + return services; + } + + public static IServiceCollection AddEventBus(this IServiceCollection services, IConfiguration configuration) + { + var subscriptionClientName = configuration["SubscriptionClientName"]; + +/* if (configuration.GetValue("AzureServiceBusEnabled")) + { + services.AddSingleton(sp => + { + var serviceBusPersisterConnection = sp.GetRequiredService(); + var iLifetimeScope = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var eventBusSubcriptionsManager = sp.GetRequiredService(); + + return new EventBusServiceBus(serviceBusPersisterConnection, logger, + eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope); + }); + } + else*/ + { + services.AddSingleton(sp => + { + var rabbitMQPersistentConnection = sp.GetRequiredService(); + var iLifetimeScope = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var eventBusSubcriptionsManager = sp.GetRequiredService(); + + var retryCount = 5; + if (!string.IsNullOrEmpty(configuration["EventBusRetryCount"])) + { + retryCount = int.Parse(configuration["EventBusRetryCount"]); + } + + return new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, iLifetimeScope, eventBusSubcriptionsManager, "TenantB", subscriptionClientName, retryCount); + }); + } + + services.AddSingleton(); + //services.AddTransient(); + + return services; + } + + public static IServiceCollection AddCustomAuthentication(this IServiceCollection services, IConfiguration configuration) + { + // prevent from mapping "sub" claim to nameidentifier. + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub"); + + var identityUrl = configuration.GetValue("IdentityUrl"); + + services.AddAuthentication(options => + { + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + + }).AddJwtBearer(options => + { + options.Authority = identityUrl; + options.RequireHttpsMetadata = false; + options.Audience = "orders"; + }); + + return services; + } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/TenantBShippingInformation.csproj b/src/Services/TenantCustomisations/TenantBShippingInformation/TenantBShippingInformation.csproj new file mode 100644 index 000000000..90e7fe142 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/TenantBShippingInformation.csproj @@ -0,0 +1,56 @@ + + + + netcoreapp2.2 + InProcess + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/appsettings.Development.json b/src/Services/TenantCustomisations/TenantBShippingInformation/appsettings.Development.json new file mode 100644 index 000000000..e203e9407 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/appsettings.json b/src/Services/TenantCustomisations/TenantBShippingInformation/appsettings.json new file mode 100644 index 000000000..d5a5d2b55 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/appsettings.json @@ -0,0 +1,29 @@ +{ + "Serilog": { + "SeqServerUrl": null, + "LogstashgUrl": null, + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft": "Warning", + "Microsoft.eShopOnContainers": "Information", + "System": "Warning" + } + } + }, + "IdentityUrl": "http://localhost:5105", + //"ConnectionString": "127.0.0.1", + "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.TenantBShippingInformationDb;User Id=sa;Password=Pass@word;", + "AzureServiceBusEnabled": false, + "SubscriptionClientName": "TenantBShippingInformation", + "ApplicationInsights": { + "InstrumentationKey": "" + }, + "EventBusRetryCount": 5, + "UseVault": false, + "Vault": { + "Name": "eshop", + "ClientId": "your-clien-id", + "ClientSecret": "your-client-secret" + } +} \ No newline at end of file diff --git a/src/Services/TenantManager/TenantManager/Database/DbInitializer.cs b/src/Services/TenantManager/TenantManager/Database/DbInitializer.cs index 1345882b5..ab3899910 100644 --- a/src/Services/TenantManager/TenantManager/Database/DbInitializer.cs +++ b/src/Services/TenantManager/TenantManager/Database/DbInitializer.cs @@ -17,12 +17,10 @@ namespace TenantManager.Database var tenant1 = new Tenant { TenantName = "Tekna" }; context.Tenant.Add(tenant1); - var method1 = new Method { MethodName = "OrderStatusChangedToSubmittedIntegrationEvent" }; var method2 = new Method { MethodName = "OrderStatusChangedToAwaitingValidationIntegrationEvent" }; var methods = new[] { - method1, method2 }; @@ -33,7 +31,6 @@ namespace TenantManager.Database var customisations = new[] { - new Customisation {Tenant=tenant1, Method=method1, CustomisationUrl = @"http://tenantacustomisation/api/savedevents"}, new Customisation {Tenant=tenant1, Method=method2, CustomisationUrl = @"http://tenantacustomisation/api/savedevents"} }; diff --git a/src/Web/WebMVC/Controllers/OrderController.cs b/src/Web/WebMVC/Controllers/OrderController.cs index 501276513..0011b2411 100644 --- a/src/Web/WebMVC/Controllers/OrderController.cs +++ b/src/Web/WebMVC/Controllers/OrderController.cs @@ -23,6 +23,8 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers private IBasketService _basketSvc; private readonly IIdentityParser _appUserParser; private static String tenantACustomisationsUrl = @"http://tenantacustomisation/"; + private static String tenantAShippingInformationUrl = @"http://tenantashippinginformation/"; + private static String tenantBShippingInformationUrl = @"http://tenantbshippinginformation/"; private readonly ILogger _logger; @@ -99,11 +101,18 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers if (user.TenantId == 1) { - List shippingInformation = GetShippingInfo(vm); + List shippingInformation = GetShippingInfo(vm, tenantAShippingInformationUrl); + _logger.LogInformation("----- Shipping info{@ShippingInformation}", shippingInformation); + ViewData["ShippingInfo"] = shippingInformation; + } + else if (user.TenantId == 2) + { + List shippingInformation = GetShippingInfo(vm, tenantBShippingInformationUrl); _logger.LogInformation("----- Shipping info{@ShippingInformation}", shippingInformation); ViewData["ShippingInfo"] = shippingInformation; } + ViewData["TenantID"] = user.TenantId; return View(vm); } @@ -130,13 +139,13 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers } } - private List GetShippingInfo(List orders) + private List GetShippingInfo(List orders, String url) { List shippingInformation = new List(); using (var client = new HttpClient(new HttpClientHandler {AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate})) { - client.BaseAddress = new Uri(tenantACustomisationsUrl); + client.BaseAddress = new Uri(url); try { HttpResponseMessage response = client.GetAsync("api/shippinginformations").Result; diff --git a/src/Web/WebMVC/Views/Order/Index.cshtml b/src/Web/WebMVC/Views/Order/Index.cshtml index f365baf2e..074b2b093 100644 --- a/src/Web/WebMVC/Views/Order/Index.cshtml +++ b/src/Web/WebMVC/Views/Order/Index.cshtml @@ -12,6 +12,7 @@ new Header() {Controller = "OrderManagement", Text = "Orders Management"} }; var shippingInfo = ViewData["ShippingInfo"] as List; + var tenantId = (int)ViewData["TenantId"]; }
@@ -23,11 +24,16 @@
Date
Total
Status
- @if (shippingInfo != null) + @if (shippingInfo != null && tenantId == 1) {
Shipping date
Estimated arrival date
} + @if (shippingInfo != null && tenantId == 2) + { +
Priority
+
Fragility
+ }
@@ -35,48 +41,73 @@ { foreach (var item in Model) { -
-
@Html.DisplayFor(modelItem => item.OrderNumber)
-
@item.Date.ToShortDateString()
-
$ @Html.DisplayFor(modelItem => item.Total)
-
@Html.DisplayFor(modelItem => item.Status)
- @if (shippingInfo != null) +
+
@Html.DisplayFor(modelItem => item.OrderNumber)
+
@item.Date.ToShortDateString()
+
$ @Html.DisplayFor(modelItem => item.Total)
+
@Html.DisplayFor(modelItem => item.Status)
+ @if (shippingInfo != null && tenantId == 1) + { +
+ @for (var i = 0; i < shippingInfo.Count(); i++) + { + var si = shippingInfo[i]; + if (si.OrderNumber.Equals(item.OrderNumber)) + { + @si.ShippingTime.ToShortDateString() + ; + break; + } + } +
+
+ @for (var i = 0; i < shippingInfo.Count(); i++) + { + var si = shippingInfo[i]; + if (si.OrderNumber.Equals(item.OrderNumber)) + { + @si.ArrivalTime.ToShortDateString() + ; + break; + } + } +
+ } + @if (shippingInfo != null && tenantId == 2) + { +
+ @for (var i = 0; i < shippingInfo.Count(); i++) + { + var si = shippingInfo[i]; + if (si.OrderNumber.Equals(item.OrderNumber)) + { + @si.PriorityLevel.ToString(); + break; + } + } +
+
+ @for (var i = 0; i < shippingInfo.Count(); i++) + { + var si = shippingInfo[i]; + if (si.OrderNumber.Equals(item.OrderNumber)) { -
- @for (var i = 0; i < shippingInfo.Count(); i++) - { - var si = shippingInfo[i]; - if (si.OrderNumber.Equals(item.OrderNumber)) - { - @si.ShippingTime.ToShortDateString() - ; - break; - } - } -
-
- @for (var i = 0; i < shippingInfo.Count(); i++) - { - var si = shippingInfo[i]; - if (si.OrderNumber.Equals(item.OrderNumber)) - { - @si.ArrivalTime.ToShortDateString() - ; - break; - } - } -
+ @si.FragilityLevel.ToString(); + break; } -
- Detail -
-
- @if (item.Status.ToLower() == "submitted") - { - Cancel - } -
-
+ } + + } +
+ Detail +
+
+ @if (item.Status.ToLower() == "submitted") + { + Cancel + } +
+
} }