protected void btnSubmit_Click(object sender, EventArgs e) { AccountingLib.Entities.Login login = new AccountingLib.Entities.Login(); try { foreach (String fieldName in Request.Form) { if (fieldName.Contains("txtId")) { login.id = int.Parse(Request.Form[fieldName]); } if (fieldName.Contains("txtTenantId")) { login.tenantId = int.Parse(Request.Form[fieldName]); } if (fieldName.Contains("txtPassword")) { login.password = Request.Form[fieldName]; } if (fieldName.Contains("txtUsername")) { login.username = Request.Form[fieldName]; if (String.IsNullOrEmpty(login.username)) { throw new FormatException(); } } if (fieldName.Contains("cmbUserGroup")) { login.userGroup = int.Parse(Request.Form[fieldName]); } } } catch (System.FormatException) { EmbedClientScript.ShowErrorMessage(this, "Os valores informados não estão em um formato válido!"); return; } try { ResourceProtector.RectifyPassword(login); // caso o login seja novo gera a senha padrão loginDAO.SetLogin(login); EmbedClientScript.CloseWindow(this); } catch (Exception genericException) { if (genericException.Message.Contains("Violation of UNIQUE KEY")) { EmbedClientScript.ShowErrorMessage(this, "Este login já existe!"); return; } EmbedClientScript.ShowErrorMessage(this, genericException.Message); } }