2016-11-24 14:58:37 +01:00
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure
|
2016-11-22 18:40:47 +01:00
|
|
|
|
{
|
|
|
|
|
using AspNetCore.Builder;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2016-11-24 14:58:37 +01:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain;
|
2016-11-22 18:40:47 +01:00
|
|
|
|
using Ordering.Infrastructure;
|
2016-11-24 14:58:37 +01:00
|
|
|
|
using System.Linq;
|
2016-11-22 18:40:47 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2017-01-17 18:32:40 -08:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
2016-11-22 18:40:47 +01:00
|
|
|
|
|
|
|
|
|
public class OrderingContextSeed
|
|
|
|
|
{
|
|
|
|
|
public static async Task SeedAsync(IApplicationBuilder applicationBuilder)
|
|
|
|
|
{
|
|
|
|
|
var context = (OrderingContext)applicationBuilder
|
|
|
|
|
.ApplicationServices.GetService(typeof(OrderingContext));
|
|
|
|
|
|
|
|
|
|
using (context)
|
|
|
|
|
{
|
|
|
|
|
context.Database.Migrate();
|
|
|
|
|
|
2016-11-24 14:58:37 +01:00
|
|
|
|
if (!context.CardTypes.Any())
|
|
|
|
|
{
|
|
|
|
|
context.CardTypes.Add(CardType.Amex);
|
|
|
|
|
context.CardTypes.Add(CardType.Visa);
|
|
|
|
|
context.CardTypes.Add(CardType.MasterCard);
|
|
|
|
|
|
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!context.OrderStatus.Any())
|
|
|
|
|
{
|
2017-05-20 12:35:16 -07:00
|
|
|
|
context.OrderStatus.Add(OrderStatus.Submitted);
|
2017-05-09 13:58:48 +02:00
|
|
|
|
context.OrderStatus.Add(OrderStatus.AwaitingValidation);
|
2017-05-15 19:14:37 +02:00
|
|
|
|
context.OrderStatus.Add(OrderStatus.StockConfirmed);
|
2017-05-09 13:58:48 +02:00
|
|
|
|
context.OrderStatus.Add(OrderStatus.Paid);
|
2016-11-24 14:58:37 +01:00
|
|
|
|
context.OrderStatus.Add(OrderStatus.Shipped);
|
2017-05-09 13:58:48 +02:00
|
|
|
|
context.OrderStatus.Add(OrderStatus.Cancelled);
|
2016-11-24 14:58:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 18:40:47 +01:00
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|