private void btn_user_delete_Click(object sender, EventArgs e) { var user = new Four51WebUser(txt_sharedsecret.Text, txt_serviceid.Text) { InteropID = txt_user_interopid.Text, CompanyInteropID = txt_user_companyinteropid.Text }; try { user.Delete(); MessageBox.Show("Deleted: " + user.InteropID); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btn_user_save_Click(object sender, EventArgs e) { var user = new Four51WebUser(txt_sharedsecret.Text, txt_serviceid.Text) { InteropID = txt_user_interopid.Text == "" ? Guid.NewGuid().To <string>() : txt_user_interopid.Text, CompanyInteropID = txt_user_companyinteropid.Text, Active = chk_user_active.Checked, Email = txt_user_email.Text, FirstName = txt_user_firstname.Text, LastName = txt_user_lastname.Text, Password = txt_user_password.Text.Length > 0 ? txt_user_password.Text : null, PhoneNumber = txt_user_phonenumber.Text, TermsAccepted = chk_user_terms.Checked, UserName = txt_user_username.Text }; foreach (DataGridViewRow row in grid_user_address.Rows) { if (row.Cells[0].Value == null) { break; } user.Addresses.Add(new Four51WebAddressAssignment() { AddressInteropID = row.Cells[0].Value.To <string>(), UseForShipping = row.Cells[1].Value.To <bool>(), UseForBilling = row.Cells[2].Value.To <bool>() }); } foreach (DataGridViewRow row in grid_user_costcenters.Rows) { if (row.Cells[0].Value == null) { break; } user.CostCenters.Add(new Four51WebCostCenterAssignment() { CostCenterInteropID = row.Cells[0].Value.To <string>() }); } foreach (DataGridViewRow row in grid_user_groups.Rows) { if (row.Cells[0].Value == null) { break; } user.Groups.Add(new Four51WebGroupAssignment() { GroupInteropID = row.Cells[0].Value.To <string>(), Remove = row.Cells[1].Value.To <bool>() }); } foreach (DataGridViewRow row in grid_user_orderfields.Rows) { if (row.Cells[0].Value == null) { break; } user.OrderFields.Add(new Four51WebOrderFieldAssignment() { Name = row.Cells[0].Value.To <string>(), OptionInteropID = row.Cells[1].Value.To <string>() }); } try { if (!user.Password.IsNullOrWhiteSpace()) { user.Save(); } else { user.Sync(); } MessageBox.Show("Saved: " + user.InteropID); } catch (Exception ex) { MessageBox.Show(ex.Message); } }