Create User API
This commit is contained in:
@@ -26,13 +26,20 @@ namespace Step.Database.Controllers
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
public void Create(string username, string password, string firstName, string lastName, CultureInfo language)
|
||||
public DTOUserModel Create(string username, string password, string firstName, string lastName, CultureInfo language)
|
||||
{
|
||||
UserModel user = CreateUserModel(username, password, firstName, lastName, language);
|
||||
// Add to database
|
||||
dbCtx.Users.Add(user);
|
||||
// Commit changes
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
using(MachinesUsersController machController = new MachinesUsersController())
|
||||
{
|
||||
machController.Create(MachineConfig.MachineId, user.UserId, 3);
|
||||
}
|
||||
|
||||
return GetUserInfo(user.UserId);
|
||||
}
|
||||
|
||||
public static UserModel CreateUserModel(int id, string username, string password, string firstName, string lastName, CultureInfo language)
|
||||
@@ -59,12 +66,17 @@ namespace Step.Database.Controllers
|
||||
{
|
||||
// Find user by Id with Role object included
|
||||
UserModel userDatabaseModel = dbCtx.Users.Where(u => u.UserId == userId).FirstOrDefault();
|
||||
if (userDatabaseModel == null)
|
||||
return null;
|
||||
|
||||
DTORoleModel roleModel = null;
|
||||
|
||||
// Find user role through machineUser table
|
||||
using (MachinesUsersController machinesUsersControler = new MachinesUsersController())
|
||||
{
|
||||
roleModel = machinesUsersControler.GetUserRoleData(MachineConfig.MachineId, userId);
|
||||
if (roleModel == null)
|
||||
return null;
|
||||
}
|
||||
|
||||
return new DTOUserModel() // Return DTOUserModel
|
||||
|
||||
Reference in New Issue
Block a user