static public async Task <EUserAuth> CreateUserFromMobile(EBaseEntity eNewUser) { try { EUserAuth eUserAuth = new EUserAuth { }; using (var context = new SMySQLContext()) { if (context.BaseUsers.Any(x => x.email == eNewUser.email)) { eUserAuth.respCreateUser = (int)RespCreateUser.EmailExists; return(eUserAuth); } eNewUser.id = Guid.NewGuid().ToString(); eNewUser.creationDateUTC = DateTime.UtcNow; eNewUser.modificationDateUTC = DateTime.UtcNow; eNewUser.lastAccessUTC = DateTime.UtcNow; eNewUser.status = (int)UserStatus.Enabled; EBaseEntity result = context.BaseUsers.AddAsync(eNewUser).Result.Entity; await context.SaveChangesAsync(); eUserAuth.id = result.id; eUserAuth.cpf = result.cpf; eUserAuth.name = result.name; eUserAuth.token = STokens.GenerateToken(eNewUser.email); eUserAuth.authenticated = true; eUserAuth.respCreateUser = (int)RespCreateUser.Ok; } return(eUserAuth); } catch (Exception e) { SLogger.LogError(e); } return(null); }
static private EUserAuth GetUserAuthFromBaseEntity(EBaseEntity eBaseEntity) { EUserAuth eUserAuth = new EUserAuth { id = eBaseEntity.id, companyID = eBaseEntity.companyID, cpf = eBaseEntity.cpf, name = eBaseEntity.name, token = STokens.GenerateToken(eBaseEntity.email + "-" + eBaseEntity.password) }; return(eUserAuth); }