private void populateFields(int pGetID = 0) { mdc = new ModelDataContext(); try { if (pGetID > 0) { Model.Cursos curso = mdc.Cursos.First(cur => cur.idCurso == pGetID); tbCodigo.Text = pGetID.ToString(); tbNome.Text = curso.Nomec.Trim(); tbDescricao.Text = curso.Descricao.Trim(); } else { Response.Redirect("Curso.aspx"); } } catch (Exception) { throw; } finally { mdc.Dispose(); } }
private void onDelete() { mdc = new ModelDataContext(); try { Model.Cursos curso = mdc.Cursos.First(cur => cur.idCurso == int.Parse(tbCodigo.Text.Trim())); mdc.Cursos.DeleteOnSubmit(curso); mdc.SubmitChanges(); Response.Redirect("Curso.aspx"); } catch (Exception) { } finally { mdc.Dispose(); } }
private void onInsert() { try { using (ModelDataContext mdc = new ModelDataContext()) { Model.Cursos curso = new Model.Cursos() { Nomec = tbNome.Text.Trim(), Descricao = tbDescriao.Text.Trim(), dataCadastro = DateTime.Parse(DateTime.Now.ToShortDateString()) }; mdc.Cursos.InsertOnSubmit(curso); mdc.SubmitChanges(); Response.Redirect("Curso.aspx"); } } catch (Exception) { } }
private void onUpdate() { mdc = new ModelDataContext(); try { { Model.Cursos curso = mdc.Cursos.First(cur => cur.idCurso == int.Parse(tbCodigo.Text.Trim())); curso.Nomec = tbNome.Text.Trim(); curso.Descricao = tbDescricao.Text.Trim(); curso.dataAtualizacao = DateTime.Parse(DateTime.Now.ToShortDateString()); mdc.SubmitChanges(); Response.Redirect("Curso.aspx"); } } catch (Exception) { } finally { mdc.Dispose(); } }