Skip to content

Commit

Permalink
create db
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatandrei committed May 2, 2020
1 parent 1095abc commit 5b9f87f
Showing 1 changed file with 20 additions and 0 deletions.
@@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -28,7 +29,26 @@ public async Task<int> CreateDb()
m.Date = DateTime.UtcNow;
m.Message = "starting";
this.Messages.Add(m);
var existCategory =await GetTopCategory();
if(existCategory == null)
{
existCategory = new Category()
{
Name = "Top"

};

this.Category.Add(existCategory);
}
return await this.SaveChangesAsync();
}
public async Task<Category> GetTopCategory()
{
var parentCategories= await Category.Where(it => it.Idparent == null).ToArrayAsync();
if (parentCategories.Length == 1)
return parentCategories[0];

return null;
}
}
}

0 comments on commit 5b9f87f

Please sign in to comment.