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