Added NLog, Added UserService, Added database and seed seed

This commit is contained in:
Richárd Kunkli
2020-10-25 16:15:06 +01:00
parent 52667d913d
commit 1c61f5ec63
31 changed files with 728 additions and 150 deletions

View File

@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
namespace Birdmap.DAL.Entities.Configurations
{
public class ServiceConfiguration : IEntityTypeConfiguration<Service>
{
public void Configure(EntityTypeBuilder<Service> builder)
{
builder.Property(s => s.Name)
.IsRequired();
builder.Property(s => s.Uri)
.HasConversion(u => u.ToString(), u => new Uri(u))
.IsRequired();
builder.HasData(
new Service
{
Id = 1,
Name = "KMLabz services",
Uri = new Uri("https://birb.k8s.kmlabz.com/devices")
},
new Service
{
Id = 2,
Name = "Local Database",
Uri = new Uri("/health", UriKind.Relative)
});
}
}
}

View File

@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using static Birdmap.Common.PasswordHelper;
namespace Birdmap.DAL.Entities.Configurations
{
@ -7,6 +8,9 @@ namespace Birdmap.DAL.Entities.Configurations
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.HasIndex(u => u.Name)
.IsUnique();
builder.Property(u => u.Name)
.IsRequired();
@ -18,6 +22,26 @@ namespace Birdmap.DAL.Entities.Configurations
builder.Property(u => u.Role)
.IsRequired();
CreatePasswordHash("pass", out var hash, out var salt);
builder.HasData(
new User
{
Id = 1,
Name = "admin",
PasswordHash = hash,
PasswordSalt = salt,
Role = Roles.Admin,
},
new User
{
Id = 2,
Name = "user",
PasswordHash = hash,
PasswordSalt = salt,
Role = Roles.User,
});
}
}
}

View File

@ -0,0 +1,11 @@
using System;
namespace Birdmap.DAL.Entities
{
public class Service
{
public int Id { get; set; }
public string Name { get; set; }
public Uri Uri { get; set; }
}
}