protected void gvSolicitacoes_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "ToggleResolvido") { int? rowId = int.Parse(e.CommandArgument.ToString()); if (rowId != null) { int solicitacaoId = (int) gvSolicitacoes.DataKeys[(int)rowId].Value; SISMedEntities modelo = new SISMedEntities(); Solicitacao solicitacao = modelo.Solicitacoes.Where(c => c.Id == solicitacaoId).First(); solicitacao.Resolvido = !solicitacao.Resolvido; modelo.SaveChanges(); gvSolicitacoes.DataBind(); } } }
protected void edsUsuario_Updating(object sender, EntityDataSourceChangingEventArgs e) { SISMed.Models.Usuario u = e.Entity as SISMed.Models.Usuario; using (var context = new SISMedEntities(e.Context.Connection as EntityConnection)) { var antigo = context.Pessoas.OfType <SISMed.Models.Usuario>().First(c => c.Id == u.Id); TextBox txbSenha = fvUsuario.FindControl("SenhaTextBox") as TextBox; if (string.IsNullOrWhiteSpace(txbSenha.Text)) { u.Senha = antigo.Senha; } else { u.Senha = Password.HashPassword(u.Senha); } } }
protected void edsMudarSenha_Updating(object sender, EntityDataSourceChangingEventArgs e) { SISMed.Models.Usuario novo = e.Entity as SISMed.Models.Usuario; using (var context = new SISMedEntities(e.Context.Connection as EntityConnection)) { var antigo = context.Pessoas.OfType <SISMed.Models.Usuario>().First(c => c.Id == novo.Id); TextBox txbSenhaAtual = fvMudarSenha.FindControl("txbSenhaAtual") as TextBox; if (antigo.Senha == Password.HashPassword(txbSenhaAtual.Text)) { novo.Senha = Password.HashPassword(novo.Senha); Response.Redirect("./Default.aspx?successPassword=U2VuaGEgYWx0ZXJhZGEgY29tIHN1Y2Vzc28u"); } else { Response.Redirect("./Default.aspx?errorPassword=QSBzZW5oYSBhdHVhbCBlc3TDoSBpbmNvcnJldGEu"); e.Cancel = true; } } }