From c3f6bf3698a58fdbaedf8f63e92b6abbe14868ea Mon Sep 17 00:00:00 2001 From: espent1004 Date: Sun, 19 Jan 2020 22:41:44 +0100 Subject: [PATCH] Progress --- docker-compose.override.yml | 2 + docker-compose.yml | 2 + .../EventBusRabbitMQ/EventBusRabbitMQ.cs | 5 ++ ...CheckoutAcceptedIntegrationEventHandler.cs | 12 ++-- .../Controllers/ValuesController.cs | 17 ++++- .../Database/DbInitializer.cs | 34 ++++++++++ .../Database/TenantAContext.cs | 31 ++++++++++ .../ExternalServices/IRFIDService.cs | 12 ++++ .../ExternalServices/IShippingService.cs | 13 ++++ .../ExternalServices/MockedShippingService.cs | 23 +++++++ .../ExternalServices/Models/Fragility.cs | 12 ++++ .../ExternalServices/Models/Priority.cs | 12 ++++ .../Models/ShippingInformation.cs | 17 +++++ .../AutofacModules/ApplicationModule.cs | 11 +++- ...angedToSubmittedIntegrationEventHandler.cs | 45 ++++++++++++++ ...CheckoutAcceptedIntegrationEventHandler.cs | 60 ++++++++++++++++++ ...tatusChangedToSubmittedIntegrationEvent.cs | 22 +++++++ .../UserCheckoutAcceptedIntegrationEvent.cs | 62 +++++++++++++++++++ .../TenantACustomisations/Program.cs | 1 + .../TenantACustomisations/Startup.cs | 29 +++++---- .../TenantACustomisations.csproj | 4 -- .../TenantACustomisations/appsettings.json | 3 +- src/Web/WebMVC/Controllers/OrderController.cs | 41 ++++++++++++ .../ViewModels/Customisation/Fragility.cs | 12 ++++ .../ViewModels/Customisation/Priority.cs | 12 ++++ .../Customisation/ShippingInformation.cs | 17 +++++ src/Web/WebMVC/Views/Order/Index.cshtml | 43 ++++++++++--- 27 files changed, 516 insertions(+), 38 deletions(-) create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/Database/DbInitializer.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/Database/TenantAContext.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IRFIDService.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IShippingService.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/MockedShippingService.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Fragility.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Priority.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/ShippingInformation.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs create mode 100644 src/Web/WebMVC/ViewModels/Customisation/Fragility.cs create mode 100644 src/Web/WebMVC/ViewModels/Customisation/Priority.cs create mode 100644 src/Web/WebMVC/ViewModels/Customisation/ShippingInformation.cs diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 8f408c722..37c19004a 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -68,6 +68,8 @@ 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.TenantADb;User Id=sa;Password=Pass@word} + ports: - "5116:80" diff --git a/docker-compose.yml b/docker-compose.yml index 2fbdf2781..4feb44ae0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -48,6 +48,8 @@ services: build: context: . dockerfile: src/Services/TenantCustomisations/TenantACustomisations/Dockerfile + depends_on: + - sql.data catalog.api: image: ${REGISTRY:-eshop}/catalog.api:${PLATFORM:-linux}-${TAG:-latest} diff --git a/src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs b/src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs index be7b8abd2..44137abae 100644 --- a/src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs +++ b/src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs @@ -12,6 +12,7 @@ using RabbitMQ.Client; using RabbitMQ.Client.Events; using RabbitMQ.Client.Exceptions; using System; +using System.Diagnostics; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; @@ -280,6 +281,10 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ else { var handler = scope.ResolveOptional(subscription.HandlerType); + if (eventName.Equals("OrderStatusChangedToSubmittedIntegrationEvent") || eventName.Equals("UserCheckoutAcceptedIntegrationEvent")) + { + Debug.WriteLine("Here"); + } if (handler == null) continue; var eventType = _subsManager.GetEventTypeByName(eventName); var integrationEvent = JsonConvert.DeserializeObject(message, eventType); diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs index 7c2615c25..314c35faa 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs @@ -12,7 +12,7 @@ using System; namespace Ordering.API.Application.IntegrationEvents.EventHandling { - public class UserCheckoutAcceptedIntegrationEventHandler : AbstractIntegrationEventHandler, IIntegrationEventHandler + public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHandler { private readonly IMediator _mediator; private readonly IEventBus _eventBus; @@ -20,7 +20,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling public UserCheckoutAcceptedIntegrationEventHandler( IMediator mediator, - ILogger logger, IEventBus eventBus) : base(eventBus) + ILogger logger, IEventBus eventBus) { _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); @@ -42,9 +42,9 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling { _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - var customised = await CheckIfCustomised(@event); - if (!customised) - { + //var customised = await CheckIfCustomised(@event); + //if (!customised) + //{ var result = false; if (@event.RequestId != Guid.Empty) @@ -81,7 +81,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling { _logger.LogWarning("Invalid IntegrationEvent - RequestId is missing - {@IntegrationEvent}", @event); } - } + //} } } } diff --git a/src/Services/TenantCustomisations/TenantACustomisations/Controllers/ValuesController.cs b/src/Services/TenantCustomisations/TenantACustomisations/Controllers/ValuesController.cs index e297683b6..ff8ef509b 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/Controllers/ValuesController.cs +++ b/src/Services/TenantCustomisations/TenantACustomisations/Controllers/ValuesController.cs @@ -3,6 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using TenantACustomisations.Database; +using TenantACustomisations.ExternalServices; namespace TenantACustomisations.Controllers { @@ -10,11 +13,21 @@ namespace TenantACustomisations.Controllers [ApiController] public class ValuesController : ControllerBase { + + private readonly TenantAContext _context; + + public ValuesController(TenantAContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context)); + } + + + // GET api/values [HttpGet] - public ActionResult> Get() + public async Task>> GetShippingInformation() { - return new string[] { "value1", "value2" }; + return await _context.ShippingInformation.ToListAsync(); } // GET api/values/5 diff --git a/src/Services/TenantCustomisations/TenantACustomisations/Database/DbInitializer.cs b/src/Services/TenantCustomisations/TenantACustomisations/Database/DbInitializer.cs new file mode 100644 index 000000000..acea47b5f --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/Database/DbInitializer.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using TenantACustomisations.ExternalServices; + +namespace TenantACustomisations.Database +{ + public class DbInitializer + { + public void Initialize(TenantAContext context) + { + context.Database.EnsureCreated(); + + if (context.ShippingInformation.Any()) + { + return; + } + + ShippingInformation shippingInformation = new ShippingInformation(); + shippingInformation.ShippingTime = DateTime.Today; + shippingInformation.ArrivalTime = DateTime.Today.AddDays(2); + shippingInformation.FragilityLevel = Fragility.Medium; + shippingInformation.PriorityLevel = Priority.High; + shippingInformation.ShippingInformationId = 1; + shippingInformation.OrderNumber = 1; + context.ShippingInformation.Add(shippingInformation); + + context.SaveChanges(); + + + } + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/Database/TenantAContext.cs b/src/Services/TenantCustomisations/TenantACustomisations/Database/TenantAContext.cs new file mode 100644 index 000000000..0f893e3b5 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/Database/TenantAContext.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using TenantACustomisations.ExternalServices; + +namespace TenantACustomisations.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.TenantADb;Integrated Security=true"); + + return new TenantAContext(optionsBuilder.Options); + } + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IRFIDService.cs b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IRFIDService.cs new file mode 100644 index 000000000..bc52c2fc3 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IRFIDService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TenantACustomisations.ExternalServices +{ + public interface IRFIDService + { + bool IsOrderRFIDTagged(int orderNumber); + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IShippingService.cs b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IShippingService.cs new file mode 100644 index 000000000..3db814143 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IShippingService.cs @@ -0,0 +1,13 @@ +using Ordering.API.Application.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TenantACustomisations.ExternalServices +{ + public interface IShippingService + { + ShippingInformation CalculateShippingInformation(int orderId); + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/MockedShippingService.cs b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/MockedShippingService.cs new file mode 100644 index 000000000..b3561d50b --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/MockedShippingService.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Ordering.API.Application.Models; + +namespace TenantACustomisations.ExternalServices +{ + public class MockedShippingService : IShippingService + { + public ShippingInformation CalculateShippingInformation(int orderId) + { + ShippingInformation shippingInformation = new ShippingInformation(); + shippingInformation.ShippingTime = DateTime.Today; + shippingInformation.ArrivalTime = DateTime.Today.AddDays(2); + shippingInformation.FragilityLevel = Fragility.Medium; + shippingInformation.PriorityLevel = Priority.High; + shippingInformation.OrderNumber = orderId; + + return shippingInformation; + } + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Fragility.cs b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Fragility.cs new file mode 100644 index 000000000..a2afffc22 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Fragility.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TenantACustomisations.ExternalServices +{ + public enum Fragility + { + Low, Medium, High + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Priority.cs b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Priority.cs new file mode 100644 index 000000000..cd0efcb73 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Priority.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TenantACustomisations.ExternalServices +{ + public enum Priority + { + Low, Medium, High + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/ShippingInformation.cs b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/ShippingInformation.cs new file mode 100644 index 000000000..f83a7d5cb --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/ShippingInformation.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TenantACustomisations.ExternalServices +{ + public class ShippingInformation + { + public int ShippingInformationId { get; set; } + public DateTime ArrivalTime { get; set; } + public DateTime ShippingTime { get; set; } + public Priority PriorityLevel {get;set;} + public Fragility FragilityLevel { get; set; } + public String OrderNumber { get; set; } + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/Infrastructure/AutofacModules/ApplicationModule.cs b/src/Services/TenantCustomisations/TenantACustomisations/Infrastructure/AutofacModules/ApplicationModule.cs index 69cc1d12a..ea46f0586 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/Infrastructure/AutofacModules/ApplicationModule.cs +++ b/src/Services/TenantCustomisations/TenantACustomisations/Infrastructure/AutofacModules/ApplicationModule.cs @@ -1,5 +1,8 @@ using Autofac; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using System.Reflection; +using TenantACustomisations.ExternalServices; +using TenantACustomisations.IntegrationEvents.Events; namespace Microsoft.eShopOnContainers.Services.TenantACustomisations.Infrastructure.AutofacModules { @@ -18,7 +21,13 @@ namespace Microsoft.eShopOnContainers.Services.TenantACustomisations.Infrastruct protected override void Load(ContainerBuilder builder) { - //TODO + builder.RegisterAssemblyTypes(typeof(UserCheckoutAcceptedIntegrationEvent).GetTypeInfo().Assembly) + .AsClosedTypesOf(typeof(IIntegrationEventHandler<>)); + + + builder.RegisterType() + .As() + .InstancePerLifetimeScope(); } } } diff --git a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs new file mode 100644 index 000000000..78cb7a46d --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs @@ -0,0 +1,45 @@ +using Microsoft.AspNetCore.SignalR; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Microsoft.Extensions.Logging; +using Serilog.Context; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; +using TenantACustomisations.Database; +using TenantACustomisations.ExternalServices; +using TenantACustomisations.IntegrationEvents.Events; + +namespace TenantACustomisations.IntegrationEvents.EventHandling +{ + public class OrderStatusChangedToSubmittedIntegrationEventHandler : + IIntegrationEventHandler + { + private readonly ILogger _logger; + private readonly IShippingService _shippingService; + private readonly TenantAContext _context; + + public OrderStatusChangedToSubmittedIntegrationEventHandler(ILogger logger, IShippingService shippingService, TenantAContext 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")) + { + _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at TenantA - ({@IntegrationEvent})", @event.Id, @event); + _logger.LogInformation("Hello"); + //TODO + Debug.WriteLine(@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(); + } + } + } +} \ No newline at end of file diff --git a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs new file mode 100644 index 000000000..fb8196ebf --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs @@ -0,0 +1,60 @@ +using MediatR; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions; +using Microsoft.Extensions.Logging; +using Ordering.API.Application.Behaviors; +using Serilog.Context; +using System.Threading.Tasks; +using System; +using System.Diagnostics; +using TenantACustomisations.IntegrationEvents.Events; +using TenantACustomisations.ExternalServices; +using TenantACustomisations.Database; + +namespace TenantACustomisations.IntegrationEvents.EventHandling +{ + public class TenantAUserCheckoutAcceptedIntegrationEventHandler : + IIntegrationEventHandler + { + private readonly IMediator _mediator; + private readonly IEventBus _eventBus; + private readonly ILogger _logger; + //private readonly TenantAContext _context; + //private readonly IShippingService _shippingService; + + public TenantAUserCheckoutAcceptedIntegrationEventHandler( + IMediator mediator, + ILogger logger, + IEventBus eventBus + ) + { + _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); + } + + /// + /// Integration event handler which starts the create order process + /// + /// + /// Integration event message which is sent by the + /// basket.api once it has successfully process the + /// order items. + /// + /// + public async Task Handle(UserCheckoutAcceptedIntegrationEvent @event) + { + using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA")) + { + _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at TenantA- ({@IntegrationEvent})", @event.Id, @event); + _logger.LogInformation("Hello"); + + //TODO + Debug.WriteLine(@event); + //Save shipping info + //Hard code view comp + //Retrieve shipping info and show + } + } + } +} \ No newline at end of file diff --git a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs new file mode 100644 index 000000000..12a759508 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs @@ -0,0 +1,22 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TenantACustomisations.IntegrationEvents.Events +{ + public class OrderStatusChangedToSubmittedIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToSubmittedIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs new file mode 100644 index 000000000..7f6fa4a36 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs @@ -0,0 +1,62 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using Ordering.API.Application.Models; +using System; + +namespace TenantACustomisations.IntegrationEvents.Events +{ + public class UserCheckoutAcceptedIntegrationEvent : IntegrationEvent + { + public string UserId { get; } + + public string UserName { get; } + + public string City { get; set; } + + public string Street { get; set; } + + public string State { get; set; } + + public string Country { get; set; } + + public string ZipCode { get; set; } + + public string CardNumber { get; set; } + + public string CardHolderName { get; set; } + + public DateTime CardExpiration { get; set; } + + public string CardSecurityNumber { get; set; } + + public int CardTypeId { get; set; } + + public string Buyer { get; set; } + + public Guid RequestId { get; set; } + + public CustomerBasket Basket { get; } + + public UserCheckoutAcceptedIntegrationEvent(string userId, string userName, string city, string street, + string state, string country, string zipCode, string cardNumber, string cardHolderName, + DateTime cardExpiration, string cardSecurityNumber, int cardTypeId, string buyer, Guid requestId, + CustomerBasket basket) + { + UserId = userId; + City = city; + Street = street; + State = state; + Country = country; + ZipCode = zipCode; + CardNumber = cardNumber; + CardHolderName = cardHolderName; + CardExpiration = cardExpiration; + CardSecurityNumber = cardSecurityNumber; + CardTypeId = cardTypeId; + Buyer = buyer; + Basket = basket; + RequestId = requestId; + UserName = userName; + } + + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/Program.cs b/src/Services/TenantCustomisations/TenantACustomisations/Program.cs index b3e34cf44..f1a3015e3 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/Program.cs +++ b/src/Services/TenantCustomisations/TenantACustomisations/Program.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Configuration; using Serilog; using System; using System.IO; +using TenantACustomisations.Database; namespace Microsoft.eShopOnContainers.Services.TenantACustomisations { diff --git a/src/Services/TenantCustomisations/TenantACustomisations/Startup.cs b/src/Services/TenantCustomisations/TenantACustomisations/Startup.cs index 8aad4f6ee..c8f551829 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/Startup.cs +++ b/src/Services/TenantCustomisations/TenantACustomisations/Startup.cs @@ -35,6 +35,9 @@ 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; public class Startup { @@ -107,6 +110,11 @@ }); ConfigureEventBus(app); + using (var serviceScope = app.ApplicationServices.GetService().CreateScope()) + { + var context = serviceScope.ServiceProvider.GetRequiredService(); + context.Database.EnsureCreated(); + } } @@ -114,7 +122,9 @@ { var eventBus = app.ApplicationServices.GetRequiredService(); - eventBus.Subscribe(); + //eventBus.Subscribe>(); + eventBus.Subscribe(); + } protected virtual void ConfigureAuth(IApplicationBuilder app) @@ -210,18 +220,8 @@ public static IServiceCollection AddCustomDbContext(this IServiceCollection services, IConfiguration configuration) { - //services.AddEntityFrameworkSqlServer() - // .AddDbContext(options => - // { - // options.UseSqlServer(configuration["ConnectionString"], - // sqlServerOptionsAction: sqlOptions => - // { - // sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name); - // sqlOptions.EnableRetryOnFailure(maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); - // }); - // }, - // ServiceLifetime.Scoped //Showing explicitly that the DbContext is shared across the HTTP request scope (graph of objects started in the HTTP request) - // ); + services.AddDbContext(options => + options.UseSqlServer(configuration["ConnectionString"])); services.AddDbContext(options => { @@ -276,7 +276,6 @@ sp => (DbConnection c) => new IntegrationEventLogService(c)); //services.AddTransient(); - if (configuration.GetValue("AzureServiceBusEnabled")) { services.AddSingleton(sp => @@ -387,7 +386,7 @@ } services.AddSingleton(); - services.AddTransient(); + //services.AddTransient(); return services; } diff --git a/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj b/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj index 44c3fe7ff..d21ad07f5 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj +++ b/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj @@ -42,10 +42,6 @@ - - - - diff --git a/src/Services/TenantCustomisations/TenantACustomisations/appsettings.json b/src/Services/TenantCustomisations/TenantACustomisations/appsettings.json index 76cd21c29..55e48a978 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/appsettings.json +++ b/src/Services/TenantCustomisations/TenantACustomisations/appsettings.json @@ -12,7 +12,8 @@ } }, "IdentityUrl": "http://localhost:5105", - "ConnectionString": "127.0.0.1", + //"ConnectionString": "127.0.0.1", + "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.TenantADb;User Id=sa;Password=Pass@word;", "AzureServiceBusEnabled": false, "SubscriptionClientName": "TenantACustomisation", "ApplicationInsights": { diff --git a/src/Web/WebMVC/Controllers/OrderController.cs b/src/Web/WebMVC/Controllers/OrderController.cs index cb5234e3c..1c3cff632 100644 --- a/src/Web/WebMVC/Controllers/OrderController.cs +++ b/src/Web/WebMVC/Controllers/OrderController.cs @@ -2,7 +2,14 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.eShopOnContainers.WebMVC.Services; using Microsoft.eShopOnContainers.WebMVC.ViewModels; +using Microsoft.eShopOnContainers.WebMVC.ViewModels.Customisation; +using Newtonsoft.Json; using Polly.CircuitBreaker; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.WebMVC.Controllers @@ -13,6 +20,8 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers private IOrderingService _orderSvc; private IBasketService _basketSvc; private readonly IIdentityParser _appUserParser; + private static String url = @"http://tenantacustomisation/"; + public OrderController(IOrderingService orderSvc, IBasketService basketSvc, IIdentityParser appUserParser) { _appUserParser = appUserParser; @@ -75,7 +84,39 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers { var user = _appUserParser.Parse(HttpContext.User); var vm = await _orderSvc.GetMyOrders(user); + List shippingInformation = GetShippingInfo(vm); + ViewData["ShippingInfo"] = shippingInformation; return View(vm); } + + private List GetShippingInfo(List orders) + { + List shippingInformation = new List(); + using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate })) + { + client.BaseAddress = new Uri(url); + try + { + HttpResponseMessage response = client.GetAsync("api/shippinginformation").Result; + response.EnsureSuccessStatusCode(); + string result = response.Content.ReadAsStringAsync().Result; + List results = JsonConvert.DeserializeObject>(result); + results.ForEach( s => + { + if(orders.Any(item => item.OrderNumber.Equals(s.OrderNumber))) + { + shippingInformation.Add(s); + } + }); + + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + + return shippingInformation; + } } } \ No newline at end of file diff --git a/src/Web/WebMVC/ViewModels/Customisation/Fragility.cs b/src/Web/WebMVC/ViewModels/Customisation/Fragility.cs new file mode 100644 index 000000000..f08ea09f8 --- /dev/null +++ b/src/Web/WebMVC/ViewModels/Customisation/Fragility.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.eShopOnContainers.WebMVC.ViewModels.Customisation +{ + public enum Fragility + { + Low, Medium, High + } +} diff --git a/src/Web/WebMVC/ViewModels/Customisation/Priority.cs b/src/Web/WebMVC/ViewModels/Customisation/Priority.cs new file mode 100644 index 000000000..a8060fcae --- /dev/null +++ b/src/Web/WebMVC/ViewModels/Customisation/Priority.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.eShopOnContainers.WebMVC.ViewModels.Customisation +{ + public enum Priority + { + Low, Medium, High + } +} diff --git a/src/Web/WebMVC/ViewModels/Customisation/ShippingInformation.cs b/src/Web/WebMVC/ViewModels/Customisation/ShippingInformation.cs new file mode 100644 index 000000000..a9c866b07 --- /dev/null +++ b/src/Web/WebMVC/ViewModels/Customisation/ShippingInformation.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.eShopOnContainers.WebMVC.ViewModels.Customisation +{ + public class ShippingInformation + { + public int ShippingInformationId { get; set; } + public DateTime ArrivalTime { get; set; } + public DateTime ShippingTime { get; set; } + public Priority PriorityLevel { get; set; } + public Fragility FragilityLevel { get; set; } + public String OrderNumber { get; set; } + } +} diff --git a/src/Web/WebMVC/Views/Order/Index.cshtml b/src/Web/WebMVC/Views/Order/Index.cshtml index d3247433c..48da48d1f 100644 --- a/src/Web/WebMVC/Views/Order/Index.cshtml +++ b/src/Web/WebMVC/Views/Order/Index.cshtml @@ -1,25 +1,31 @@ @using Microsoft.eShopOnContainers.WebMVC.ViewModels +@using Microsoft.eShopOnContainers.WebMVC.ViewModels.Customisation @model IEnumerable @{ - ViewData["Title"] = "My Orders"; - var headerList= new List
() { + ViewData["Title"] = "My Orders"; + var headerList = new List
() { new Header() { Controller = "Catalog", Text = "Back to catalog" }, new Header() { Text = " / " }, new Header() { Controller = "OrderManagement", Text = "Orders Management" } }; + var shippingInfo = ViewData["ShippingInfo"] as List; + }
- +
Order number
-
Date
-
Total
-
Status
+
Date
+
Total
+
Status
+
Shipping date
+
Estimated arrival date
+
@if (Model != null && Model.Any()) { @@ -27,9 +33,28 @@ {
@Html.DisplayFor(modelItem => item.OrderNumber)
-
@Html.DisplayFor(modelItem => item.Date)
-
$ @Html.DisplayFor(modelItem => item.Total)
-
@Html.DisplayFor(modelItem => item.Status)
+
@Html.DisplayFor(modelItem => item.Date)
+
$ @Html.DisplayFor(modelItem => item.Total)
+
@Html.DisplayFor(modelItem => item.Status)
+
+ @for (var i = 0; i < shippingInfo.Count(); i++) + { + var si = shippingInfo[i]; + if (si.OrderNumber.Equals(item.OrderNumber)){ + @si.ShippingTime + } + } +
+
+ @for (var i = 0; i < shippingInfo.Count(); i++) + { + var si = shippingInfo[i]; + if (si.OrderNumber.Equals(item.OrderNumber)) + { + @si.ArrivalTime + } + } +
Detail