public HttpResponseMessage addUser([FromBody] UserInsertModel model) { //try connecting to the DB try { //insert values into table string Command = "INSERT INTO[dbo].[User_Info] ([SystemID], [UserID], [Password], [Email], [PhoneNumber], [Admin], [isAllowed],[Username]) VALUES(" + model.SystemID + ", " + model.UserID + ", '" + model.Password + "', '" + model.Email + "', " + model.PhoneNumber + ", " + model.Admin + ", " + model.Allowed + ", '" + model.userName + "');"; using (SqlConnection myConnection = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|GOB_DB.mdf;Integrated Security=True")) { myConnection.Open(); SqlCommand myCommand = new SqlCommand(Command, myConnection); myCommand.ExecuteNonQuery(); } //create response var response = this.Request.CreateResponse(HttpStatusCode.Created); response.Headers.Add("Access-Control-Allow-Origin", "http://localhost:3000"); response.Headers.Add("SuccessfulyAddedToDB", "True"); response.Headers.Date = DateTime.Now.ToUniversalTime(); //let user know all went well response.Content = new StringContent("Successfully added entry to the database"); response.Headers.Date = DateTime.Now.ToUniversalTime(); return(response); } catch (Exception ex) { //let user know if something went wrong var response = this.Request.CreateResponse(HttpStatusCode.BadRequest); response.Headers.Add("Access-Control-Allow-Origin", "http://localhost:3000"); response.Headers.Add("SuccessfulyAddedToDB", "False"); response.Headers.Date = DateTime.Now.ToUniversalTime(); response.Content = new StringContent("Something went wrong with the database"); return(response); } }
/// <summary> /// Update User /// </summary> public async Task <UserModel> Update(UserInsertModel userInsertModel) { userInsertModel.Password = userInsertModel.Password.HashPassword(); var user = _mapper.Map <User>(userInsertModel); user.UserRoles.First().RoleId = userInsertModel.RoleId; _efContext.User.Update(user); await _efContext.SaveChangesAsync(); return(_mapper.Map <UserModel>(user)); }
/// <summary> /// Create User /// </summary> public async Task <UserModel> Create(UserInsertModel userInsertModel) { userInsertModel.Password = userInsertModel.Password.HashPassword(); var user = _mapper.Map <User>(userInsertModel); user.UserRoles.Add(new UserRole { UserId = user.Id, RoleId = userInsertModel.RoleId }); await _efContext.User.AddAsync(user); await _efContext.SaveChangesAsync(); return(_mapper.Map <UserModel>(user)); }
public async Task <IActionResult> Create([FromBody] UserInsertModel insertData) { //Check user's permission to see if user can create another user or not //_permissionService.CheckHasAccess var user = await _userService.Get(insertData.Username); var result = new UserModel(); if (user == null) { result = await _userService.Create(insertData); } else { result = await _userService.Update(insertData); } return(Ok(result)); }
public IActionResult Insert(UserInsertModel userInsert) { if (userInsert == null) { return(BadRequest("User info must not be null")); } int result = _user.Insert(userInsert); if (result == 0) { return(BadRequest("Faulthy user info.")); } if (result == 1) { return(BadRequest("This user is already in the system")); } return(Ok("Insert user " + userInsert.Email)); }
public object InsertUser(object administratorId, UserInsertModel model) { if (administratorId is null) { throw new ArgumentNullException(nameof(administratorId)); } if (model is null) { throw new ArgumentNullException(nameof(model)); } lock (dataAccessLock) { CheckAdministratorId(administratorId); object newId; newId = dataProvider.InsertUser(model); WriteAdminLog(administratorId, $"New user with ID \"{newId.ToString()}\" was created."); return(newId); } }
private static UserModel UpdateUserByEmailTest(Iatec.Accounts.Client.Configuration apiConfig, string email, UserInsertModel user) { try { var api = new UserApi(apiConfig); return(api.UpdateUserByEmail(email, user)); } catch (ApiException ex) { throw ex; } }
private static UserModel UpdateUserByIdTest(Iatec.Accounts.Client.Configuration apiConfig, Guid id, UserInsertModel user) { try { var api = new UserApi(apiConfig); return(api.UpdateUserById(id, user)); } catch (ApiException ex) { throw ex; } }
private static void Main(string[] args) { const string CLIENT_ID = "00000000000000000000000000000000"; const string CLIENT_SECRET = "secretsecretsecretsecretsecretsecretsecretsecret"; var discoveryClient = new DiscoveryClient("https://login-dev.sdasystems.org"); var discovery = discoveryClient.GetAsync().Result; var tokenClient = new TokenClient(discovery.TokenEndpoint, CLIENT_ID, CLIENT_SECRET); var tokens = tokenClient.RequestClientCredentialsAsync("scope").Result; // ---------------------------------------------------------------------------------------------------------- // var apiConfig = new Iatec.Accounts.Client.Configuration() { AccessToken = tokens.AccessToken, BasePath = "https://ws-accounts-dev.sdasystems.org", }; var user = CreateUserTest(apiConfig); ResetPasswordByEmailTest(apiConfig, user.Email); ResetPasswordByUsernameTest(apiConfig, user.Username); Console.WriteLine(user.ToString()); var newUser = new UserInsertModel() { Email = "*****@*****.**", FirstName = "Azeite", LastName = "Mouras", Password = "******", UserName = "******", }; var user1 = UpdateUserByIdTest(apiConfig, user.Id, newUser); Console.WriteLine(user1.ToString()); user1.Username = "******"; var user2 = UpdateUserByUsernameTest(apiConfig, user1.Username, newUser); Console.WriteLine(user2.ToString()); user2.Email = "*****@*****.**"; var user3 = UpdateUserByEmailTest(apiConfig, user2.Email, newUser); Console.WriteLine(user3?.ToString()); var a = GetUserByEmailTest(apiConfig, user?.Email); Console.WriteLine(a?.ToString() ?? "Not Found!"); //ChagePasswordByIdTest(apiConfig, user.Id); //if (user != null && false) //{ // var a = GetUserByEmailTest(apiConfig, user.Email); // var b = GetUserByIdTest(apiConfig, user.Id); // var c = GetUserByUsernameTest(apiConfig, user.UserName); // Console.WriteLine(c.ToString()); //} var userList = GetUsersByFilter(apiConfig, "william"); Console.WriteLine(userList.ToString()); foreach (var item in userList.Items) { Console.WriteLine("*"); Console.WriteLine(item.ToString()); Console.WriteLine("*"); } DeleteUserTest(apiConfig, user.Id); var b = GetUserByIdTest(apiConfig, user.Id); if (b == null) { Console.WriteLine("Delete works"); } Console.WriteLine("-- END --"); Console.ReadLine(); }