User Management updates
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
|
|
||||||
namespace LuminousSales.Business
|
|
||||||
{
|
|
||||||
public class MainBusiness
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@@ -17,9 +17,17 @@ namespace Business.Business.UserManagment.Controllers
|
|||||||
this.context = new LuminousContext();
|
this.context = new LuminousContext();
|
||||||
this.currentUser = currentUser;
|
this.currentUser = currentUser;
|
||||||
}
|
}
|
||||||
|
public void CreateInitialRoles()
|
||||||
|
{
|
||||||
|
var Admin = new Role("Admin");
|
||||||
|
var Manager = new Role("Manager");
|
||||||
|
var Cashier = new Role("Cashier");
|
||||||
|
context.Role.AddRange(Admin, Manager, Cashier);
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
public ICollection<Role> GetAll()
|
public ICollection<Role> GetAll()
|
||||||
{
|
{
|
||||||
if (currentUser != null || currentUser.RoleId == 3)
|
if (currentUser.RoleId == 3)
|
||||||
{
|
{
|
||||||
return context.Role.ToList();
|
return context.Role.ToList();
|
||||||
}
|
}
|
||||||
@@ -30,7 +38,7 @@ namespace Business.Business.UserManagment.Controllers
|
|||||||
}
|
}
|
||||||
public Role Get(int id)
|
public Role Get(int id)
|
||||||
{
|
{
|
||||||
if (currentUser != null || currentUser.RoleId == 3)
|
if (currentUser.RoleId == 3)
|
||||||
{
|
{
|
||||||
return context.Role.Find(id);
|
return context.Role.Find(id);
|
||||||
}
|
}
|
||||||
@@ -41,7 +49,7 @@ namespace Business.Business.UserManagment.Controllers
|
|||||||
}
|
}
|
||||||
public Role Get(string name)
|
public Role Get(string name)
|
||||||
{
|
{
|
||||||
if (currentUser != null || currentUser.RoleId == 3)
|
if (currentUser.RoleId == 3)
|
||||||
{
|
{
|
||||||
return context.Role.FirstOrDefault(u => u.Name == name);
|
return context.Role.FirstOrDefault(u => u.Name == name);
|
||||||
}
|
}
|
||||||
@@ -52,7 +60,7 @@ namespace Business.Business.UserManagment.Controllers
|
|||||||
}
|
}
|
||||||
public ICollection<Role> GetByApproximateName(string name)
|
public ICollection<Role> GetByApproximateName(string name)
|
||||||
{
|
{
|
||||||
if (currentUser != null || currentUser.RoleId == 3)
|
if (currentUser.RoleId == 3)
|
||||||
{
|
{
|
||||||
return context.Role.Where(u => u.Name.Contains(name)).ToList();
|
return context.Role.Where(u => u.Name.Contains(name)).ToList();
|
||||||
}
|
}
|
||||||
|
@@ -1,42 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Models;
|
|
||||||
using System.Linq;
|
|
||||||
using Models.Models;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Business.Business.UserManagment
|
|
||||||
{
|
|
||||||
public class CreateInitialUser
|
|
||||||
{
|
|
||||||
private LuminousContext context;
|
|
||||||
private string Username;
|
|
||||||
private string Password;
|
|
||||||
private UserController userctl;
|
|
||||||
public CreateInitialUser(string Username, string Password)
|
|
||||||
{
|
|
||||||
userctl = new UserController();
|
|
||||||
this.Username = Username;
|
|
||||||
this.Password = Password;
|
|
||||||
}
|
|
||||||
public void CreateRoles()
|
|
||||||
{
|
|
||||||
using (context = new LuminousContext())
|
|
||||||
{
|
|
||||||
var Admin = new Role("Admin");
|
|
||||||
var Manager = new Role("Manager");
|
|
||||||
var Cashier = new Role("Cashier");
|
|
||||||
context.Role.AddRange(Admin, Manager, Cashier);
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void CreateFirstUser()
|
|
||||||
{
|
|
||||||
using (context = new LuminousContext())
|
|
||||||
{
|
|
||||||
int roleToAttach = context.Role.FirstOrDefault(r => r.Name == "Admin").Id;
|
|
||||||
userctl.RegisterItem(this.Username, this.Password, roleToAttach);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
using Models;
|
|
||||||
using Models.Models;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Business.Business.UserManagment
|
|
||||||
{
|
|
||||||
public class UserValidator
|
|
||||||
{
|
|
||||||
private LuminousContext context;
|
|
||||||
public void CheckIfUserEverCreated()
|
|
||||||
{
|
|
||||||
using (context = new LuminousContext())
|
|
||||||
{
|
|
||||||
if (context.User.ToList().Any())
|
|
||||||
{
|
|
||||||
throw new ArgumentException("First user is already created!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void CheckPassword(string Password)
|
|
||||||
{
|
|
||||||
using (context = new LuminousContext())
|
|
||||||
{
|
|
||||||
if (context.User.ToList().Exists(user => user.Password == Password))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Invalid User!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user