Create User API

This commit is contained in:
Lucio Maranta
2019-02-20 09:40:20 +01:00
parent c690f175f5
commit d82bf59cfb
3 changed files with 33 additions and 15 deletions
+13 -1
View File
@@ -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