chore: rework dbinit slightly
All checks were successful
continuous-integration/drone/push Build is passing

* fill the tables only if there's nothing in them already
This commit is contained in:
surtur 2020-12-31 11:28:56 +01:00
parent 0779d07d84
commit 8dda15cfac
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

View File

@ -1,4 +1,5 @@
using System;
using System.Linq;
using pwt_0x01_ng.Models.Database;
using System.Collections.Generic;
using pwt_0x01_ng.Models;
@ -10,15 +11,16 @@ namespace pwt_0x01_ng.Models.Database
public static void Init(DBContext dbContext)
{
if (dbContext.Database.EnsureCreated())
{
dbContext.Database.EnsureCreated();
if(dbContext.Carousel.Count() == 0){
IList<Carousel> carousels = CarouselHelper.GenerateCarousel();
foreach (var c in carousels)
{
dbContext.Carousel.Add(c);
}
dbContext.SaveChanges();
}
if(dbContext.Product.Count() == 0){
IList<Product> products = ProductHelper.GenerateProduct();
foreach (var p in products)
{