Browse Source

Progress

pull/1240/head
espent1004 5 years ago
parent
commit
c3f6bf3698
27 changed files with 516 additions and 38 deletions
  1. +2
    -0
      docker-compose.override.yml
  2. +2
    -0
      docker-compose.yml
  3. +5
    -0
      src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs
  4. +6
    -6
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs
  5. +15
    -2
      src/Services/TenantCustomisations/TenantACustomisations/Controllers/ValuesController.cs
  6. +34
    -0
      src/Services/TenantCustomisations/TenantACustomisations/Database/DbInitializer.cs
  7. +31
    -0
      src/Services/TenantCustomisations/TenantACustomisations/Database/TenantAContext.cs
  8. +12
    -0
      src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IRFIDService.cs
  9. +13
    -0
      src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IShippingService.cs
  10. +23
    -0
      src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/MockedShippingService.cs
  11. +12
    -0
      src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Fragility.cs
  12. +12
    -0
      src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Priority.cs
  13. +17
    -0
      src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/ShippingInformation.cs
  14. +10
    -1
      src/Services/TenantCustomisations/TenantACustomisations/Infrastructure/AutofacModules/ApplicationModule.cs
  15. +45
    -0
      src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs
  16. +60
    -0
      src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs
  17. +22
    -0
      src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs
  18. +62
    -0
      src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs
  19. +1
    -0
      src/Services/TenantCustomisations/TenantACustomisations/Program.cs
  20. +14
    -15
      src/Services/TenantCustomisations/TenantACustomisations/Startup.cs
  21. +0
    -4
      src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj
  22. +2
    -1
      src/Services/TenantCustomisations/TenantACustomisations/appsettings.json
  23. +41
    -0
      src/Web/WebMVC/Controllers/OrderController.cs
  24. +12
    -0
      src/Web/WebMVC/ViewModels/Customisation/Fragility.cs
  25. +12
    -0
      src/Web/WebMVC/ViewModels/Customisation/Priority.cs
  26. +17
    -0
      src/Web/WebMVC/ViewModels/Customisation/ShippingInformation.cs
  27. +34
    -9
      src/Web/WebMVC/Views/Order/Index.cshtml

+ 2
- 0
docker-compose.override.yml View File

@ -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"


+ 2
- 0
docker-compose.yml View File

@ -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}


+ 5
- 0
src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs View File

@ -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);


+ 6
- 6
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs View File

@ -12,7 +12,7 @@ using System;
namespace Ordering.API.Application.IntegrationEvents.EventHandling
{
public class UserCheckoutAcceptedIntegrationEventHandler : AbstractIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>
public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>
{
private readonly IMediator _mediator;
private readonly IEventBus _eventBus;
@ -20,7 +20,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
public UserCheckoutAcceptedIntegrationEventHandler(
IMediator mediator,
ILogger<UserCheckoutAcceptedIntegrationEventHandler> logger, IEventBus eventBus) : base(eventBus)
ILogger<UserCheckoutAcceptedIntegrationEventHandler> 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);
}
}
//}
}
}
}

+ 15
- 2
src/Services/TenantCustomisations/TenantACustomisations/Controllers/ValuesController.cs View File

@ -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<IEnumerable<string>> Get()
public async Task<ActionResult<IEnumerable<ShippingInformation>>> GetShippingInformation()
{
return new string[] { "value1", "value2" };
return await _context.ShippingInformation.ToListAsync();
}
// GET api/values/5


+ 34
- 0
src/Services/TenantCustomisations/TenantACustomisations/Database/DbInitializer.cs View File

@ -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();
}
}
}

+ 31
- 0
src/Services/TenantCustomisations/TenantACustomisations/Database/TenantAContext.cs View File

@ -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<TenantAContext> options)
: base(options)
{
}
public DbSet<ShippingInformation> ShippingInformation { get; set; }
}
public class TenantAContextDesignFactory : IDesignTimeDbContextFactory<TenantAContext>
{
public TenantAContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<TenantAContext>()
.UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.TenantADb;Integrated Security=true");
return new TenantAContext(optionsBuilder.Options);
}
}
}

+ 12
- 0
src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IRFIDService.cs View File

@ -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);
}
}

+ 13
- 0
src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IShippingService.cs View File

@ -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);
}
}

+ 23
- 0
src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/MockedShippingService.cs View File

@ -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;
}
}
}

+ 12
- 0
src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Fragility.cs View File

@ -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
}
}

+ 12
- 0
src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/Priority.cs View File

@ -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
}
}

+ 17
- 0
src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/Models/ShippingInformation.cs View File

@ -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; }
}
}

+ 10
- 1
src/Services/TenantCustomisations/TenantACustomisations/Infrastructure/AutofacModules/ApplicationModule.cs View File

@ -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<MockedShippingService>()
.As<IShippingService>()
.InstancePerLifetimeScope();
}
}
}

+ 45
- 0
src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs View File

@ -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<OrderStatusChangedToSubmittedIntegrationEvent>
{
private readonly ILogger<OrderStatusChangedToSubmittedIntegrationEventHandler> _logger;
private readonly IShippingService _shippingService;
private readonly TenantAContext _context;
public OrderStatusChangedToSubmittedIntegrationEventHandler(ILogger<OrderStatusChangedToSubmittedIntegrationEventHandler> 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();
}
}
}
}

+ 60
- 0
src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs View File

@ -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<UserCheckoutAcceptedIntegrationEvent>
{
private readonly IMediator _mediator;
private readonly IEventBus _eventBus;
private readonly ILogger<TenantAUserCheckoutAcceptedIntegrationEventHandler> _logger;
//private readonly TenantAContext _context;
//private readonly IShippingService _shippingService;
public TenantAUserCheckoutAcceptedIntegrationEventHandler(
IMediator mediator,
ILogger<TenantAUserCheckoutAcceptedIntegrationEventHandler> logger,
IEventBus eventBus
)
{
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
}
/// <summary>
/// Integration event handler which starts the create order process
/// </summary>
/// <param name="@event">
/// Integration event message which is sent by the
/// basket.api once it has successfully process the
/// order items.
/// </param>
/// <returns></returns>
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
}
}
}
}

+ 22
- 0
src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs View File

@ -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;
}
}
}

+ 62
- 0
src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs View File

@ -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;
}
}
}

+ 1
- 0
src/Services/TenantCustomisations/TenantACustomisations/Program.cs View File

@ -5,6 +5,7 @@ using Microsoft.Extensions.Configuration;
using Serilog;
using System;
using System.IO;
using TenantACustomisations.Database;
namespace Microsoft.eShopOnContainers.Services.TenantACustomisations
{


+ 14
- 15
src/Services/TenantCustomisations/TenantACustomisations/Startup.cs View File

@ -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<IServiceScopeFactory>().CreateScope())
{
var context = serviceScope.ServiceProvider.GetRequiredService<TenantAContext>();
context.Database.EnsureCreated();
}
}
@ -114,7 +122,9 @@
{
var eventBus = app.ApplicationServices.GetRequiredService<BuildingBlocks.EventBus.Abstractions.IEventBus>();
eventBus.Subscribe<CustomisationEvent, CustomisationEventHandler>();
//eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
eventBus.Subscribe<OrderStatusChangedToSubmittedIntegrationEvent, OrderStatusChangedToSubmittedIntegrationEventHandler>();
}
protected virtual void ConfigureAuth(IApplicationBuilder app)
@ -210,18 +220,8 @@
public static IServiceCollection AddCustomDbContext(this IServiceCollection services, IConfiguration configuration)
{
//services.AddEntityFrameworkSqlServer()
// .AddDbContext<OrderingContext>(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<TenantAContext>(options =>
options.UseSqlServer(configuration["ConnectionString"]));
services.AddDbContext<IntegrationEventLogContext>(options =>
{
@ -276,7 +276,6 @@
sp => (DbConnection c) => new IntegrationEventLogService(c));
//services.AddTransient<IOrderingIntegrationEventService, OrderingIntegrationEventService>();
if (configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
@ -387,7 +386,7 @@
}
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddTransient<CustomisationEventHandler>();
//services.AddTransient<TenantAUserCheckoutAcceptedIntegrationEventHandler>();
return services;
}


+ 0
- 4
src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj View File

@ -42,10 +42,6 @@
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="IntegrationEvents\Events\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj" />


+ 2
- 1
src/Services/TenantCustomisations/TenantACustomisations/appsettings.json View File

@ -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": {


+ 41
- 0
src/Web/WebMVC/Controllers/OrderController.cs View File

@ -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<ApplicationUser> _appUserParser;
private static String url = @"http://tenantacustomisation/";
public OrderController(IOrderingService orderSvc, IBasketService basketSvc, IIdentityParser<ApplicationUser> 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> shippingInformation = GetShippingInfo(vm);
ViewData["ShippingInfo"] = shippingInformation;
return View(vm);
}
private List<ShippingInformation> GetShippingInfo(List<Order> orders)
{
List<ShippingInformation> shippingInformation = new List<ShippingInformation>();
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<ShippingInformation> results = JsonConvert.DeserializeObject<List<ShippingInformation>>(result);
results.ForEach( s =>
{
if(orders.Any(item => item.OrderNumber.Equals(s.OrderNumber)))
{
shippingInformation.Add(s);
}
});
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
return shippingInformation;
}
}
}

+ 12
- 0
src/Web/WebMVC/ViewModels/Customisation/Fragility.cs View File

@ -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
}
}

+ 12
- 0
src/Web/WebMVC/ViewModels/Customisation/Priority.cs View File

@ -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
}
}

+ 17
- 0
src/Web/WebMVC/ViewModels/Customisation/ShippingInformation.cs View File

@ -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; }
}
}

+ 34
- 9
src/Web/WebMVC/Views/Order/Index.cshtml View File

@ -1,25 +1,31 @@
@using Microsoft.eShopOnContainers.WebMVC.ViewModels
@using Microsoft.eShopOnContainers.WebMVC.ViewModels.Customisation
@model IEnumerable<Microsoft.eShopOnContainers.WebMVC.ViewModels.Order>
@{
ViewData["Title"] = "My Orders";
var headerList= new List<Header>() {
ViewData["Title"] = "My Orders";
var headerList = new List<Header>() {
new Header() { Controller = "Catalog", Text = "Back to catalog" },
new Header() { Text = " / " },
new Header() { Controller = "OrderManagement", Text = "Orders Management" } };
var shippingInfo = ViewData["ShippingInfo"] as List<ShippingInformation>;
}
<div class="esh-orders">
<partial name="_Header" model="headerList"/>
<partial name="_Header" model="headerList" />
<div class="container">
<article class="esh-orders-titles row">
<section class="esh-orders-title col-2">Order number</section>
<section class="esh-orders-title col-4">Date</section>
<section class="esh-orders-title col-2">Total</section>
<section class="esh-orders-title col-2">Status</section>
<section class="esh-orders-title col-2">Date</section>
<section class="esh-orders-title col-1">Total</section>
<section class="esh-orders-title col-1">Status</section>
<section class="esh-orders-title col-2">Shipping date</section>
<section class="esh-orders-title col-2">Estimated arrival date</section>
<section class="esh-orders-title col-2"></section>
</article>
@if (Model != null && Model.Any())
{
@ -27,9 +33,28 @@
{
<article class="esh-orders-items row">
<section class="esh-orders-item col-2">@Html.DisplayFor(modelItem => item.OrderNumber)</section>
<section class="esh-orders-item col-4">@Html.DisplayFor(modelItem => item.Date)</section>
<section class="esh-orders-item col-2">$ @Html.DisplayFor(modelItem => item.Total)</section>
<section class="esh-orders-item col-2">@Html.DisplayFor(modelItem => item.Status)</section>
<section class="esh-orders-item col-2">@Html.DisplayFor(modelItem => item.Date)</section>
<section class="esh-orders-item col-1">$ @Html.DisplayFor(modelItem => item.Total)</section>
<section class="esh-orders-item col-1">@Html.DisplayFor(modelItem => item.Status)</section>
<section class="esh-orders-item col-2">
@for (var i = 0; i < shippingInfo.Count(); i++)
{
var si = shippingInfo[i];
if (si.OrderNumber.Equals(item.OrderNumber)){
@si.ShippingTime
}
}
</section>
<section class="esh-orders-item col-2">
@for (var i = 0; i < shippingInfo.Count(); i++)
{
var si = shippingInfo[i];
if (si.OrderNumber.Equals(item.OrderNumber))
{
@si.ArrivalTime
}
}
</section>
<section class="esh-orders-item col-1">
<a class="esh-orders-link" asp-controller="Order" asp-action="Detail" asp-route-orderId="@item.OrderNumber">Detail</a>
</section>


Loading…
Cancel
Save