private async Task InsertAdmin() { if (ValidateInputs()) { AdminInsertVM adminInsertVM = new AdminInsertVM() { Username = TbUsername.Text, Password = TbPassword.Password, FirstName = TbFirstName.Text, LastName = TbLastName.Text }; ls.LblLoading.Text = "Adding"; ls.Show(); bool success = await adminApi.InsertAdmin(adminInsertVM); ls.Close(); if (success) { Close(); } else { MessageBox.Show("Fail!"); } } else { MessageBox.Show("All input fields are required and Password must match Confirm password!"); } }
public async Task <bool> InsertAdmin(AdminInsertVM adminInsertVM) { StringContent content = GetStringContent(adminInsertVM); HttpClient request = new HttpClient(); HttpResponseMessage response = await request.PostAsync($"{ API_URL }/InsertAdmin", content); if (response.IsSuccessStatusCode) { bool result = await response.Content.ReadAsAsync <bool>(); return(result); } return(false); }
public bool InsertAdmin(AdminInsertVM adminInsertVM) { Password password = CreateHashedPasswordAndSalt(adminInsertVM.Password); Admin admin = new Admin() { Username = adminInsertVM.Username, PasswordHash = password.Hash, PasswordSalt = password.Salt, FirstName = adminInsertVM.FirstName, LastName = adminInsertVM.LastName }; unitOfWork.Admins.Add(admin); int success = unitOfWork.Complete(); return(success > 0); }