Added Validator and User Controller
This commit is contained in:
@@ -9,13 +9,25 @@ namespace Business.Business.UserManagment
|
|||||||
public class CreateInitialUser
|
public class CreateInitialUser
|
||||||
{
|
{
|
||||||
private LuminousContext context;
|
private LuminousContext context;
|
||||||
|
private string RoleName;
|
||||||
|
private string Username;
|
||||||
|
private string Password;
|
||||||
|
private UserController userctl;
|
||||||
|
public CreateInitialUser(string RoleName, string Username, string Password)
|
||||||
|
{
|
||||||
|
userctl = new UserController();
|
||||||
|
this.RoleName = RoleName;
|
||||||
|
this.Username = Username;
|
||||||
|
this.Password = Password;
|
||||||
|
}
|
||||||
public void CreatePermissions()
|
public void CreatePermissions()
|
||||||
{
|
{
|
||||||
|
|
||||||
using (context = new LuminousContext())
|
using (context = new LuminousContext())
|
||||||
{
|
{
|
||||||
var admin = new Permission("Admin");
|
var admin = new Permission("Admin");
|
||||||
var roleChanger = new Permission("Role Changer");
|
var roleChanger = new Permission("Role Creator");
|
||||||
var userCreation = new Permission("User Creation");
|
var userCreation = new Permission("User Creator");
|
||||||
var report = new Permission("Report");
|
var report = new Permission("Report");
|
||||||
var stock = new Permission("Stock");
|
var stock = new Permission("Stock");
|
||||||
var sell = new Permission("Sell");
|
var sell = new Permission("Sell");
|
||||||
@@ -33,22 +45,20 @@ namespace Business.Business.UserManagment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateFirstRole(string Name, ICollection<Permission> Permissions)
|
public void CreateFirstRole()
|
||||||
{
|
{
|
||||||
using (context = new LuminousContext())
|
using (context = new LuminousContext())
|
||||||
{
|
{
|
||||||
var firstRole = new Role(Name, Permissions);
|
var AdminRole = context.Permission.Where(p => p.Name == "Admin").FirstOrDefault();
|
||||||
context.Role.Add(firstRole);
|
userctl.CreateRole(this.RoleName , new List<Permission> { AdminRole });
|
||||||
context.SaveChanges();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void CreateFirstUser(string Name, string Password, Role Role)
|
public void CreateFirstUser()
|
||||||
{
|
{
|
||||||
using (context = new LuminousContext())
|
using (context = new LuminousContext())
|
||||||
{
|
{
|
||||||
var firstUser = new User(Name, Password, Role);
|
var roleToAttach = context.Role.Where(r => r.Name == this.RoleName).FirstOrDefault();
|
||||||
context.User.Add(firstUser);
|
userctl.CreateUser(this.Username, this.Password, roleToAttach);
|
||||||
context.SaveChanges();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,32 @@
|
|||||||
|
using Models;
|
||||||
|
using Models.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Business.Business.UserManagment
|
||||||
|
{
|
||||||
|
public class UserController
|
||||||
|
{
|
||||||
|
private LuminousContext context;
|
||||||
|
public void CreateRole(string RoleName, ICollection<Permission> Permissions)
|
||||||
|
{
|
||||||
|
using (context = new LuminousContext())
|
||||||
|
{
|
||||||
|
var firstRole = new Role(RoleName, Permissions);
|
||||||
|
context.Role.Add(firstRole);
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void CreateUser(string Username, string Password, Role Role)
|
||||||
|
{
|
||||||
|
using (context = new LuminousContext())
|
||||||
|
{
|
||||||
|
var firstUser = new User(Username, Password, Role);
|
||||||
|
context.User.Add(firstUser);
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -7,7 +7,7 @@ namespace Display
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var InitialCreation = new CreateInitialUser();
|
var InitialCreation = new CreateInitialUser("Admin", "Admin", "pass123");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user