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;
|
|
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
{
|
|
|
|
|
context.OrderStatus.Add(OrderStatus.Canceled);
|
|
|
|
|
context.OrderStatus.Add(OrderStatus.InProcess);
|
|
|
|
|
context.OrderStatus.Add(OrderStatus.Shipped);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 18:40:47 +01:00
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|