public ActionResult Detalhes(int?id) { TarefaMod tarefa = null; try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } repository = new Repository(); tarefa = repository.Read(Convert.ToInt32(id)); if (tarefa == null) { return(HttpNotFound()); } } catch (Exception ex) { ViewBag.Falha = "O Cadastro da tarefa não foi realizado" + ex.Message; return(ViewBag()); } return(View(tarefa)); }
public ActionResult ExcluirConfirar(int id) { TarefaMod tarefa = null; try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } repository = new Repository(); tarefa = repository.Read(Convert.ToInt32(id)); if (tarefa == null) { return(HttpNotFound()); } repository.Delete(id); } catch (Exception) { throw; } return(RedirectToAction("ListarTodasTarefas")); }
public ActionResult NovaTarefa(TarefaMod tarefaMod) { repository = new Repository(); try { if (ModelState.IsValid) { if (repository.Create(tarefaMod)) { TempData["Sucesso"] = "Tarefa Cadastrada com sucesso!!"; } } else { ViewBag.Falha = "O cadastro da tarefa não foi realizada"; return(View()); } } catch (Exception ex) { ViewBag.Falha = "[ERRO] - Verifique:" + ex.Message; } return(RedirectToAction("NovaTarefa")); }
public TarefaMod Read(int Id) { TarefaMod tarefa = null; try { using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexaoPessoaDB"].ConnectionString)) { comando.Connection = con; comando.CommandType = CommandType.Text; comando.CommandText = @"SELECT Id, Nome, Prioridade, Concluido,Observacao FROM TAREFAS WHERE Id=@Id"; comando.Parameters.AddWithValue("@Id", Id); con.Open(); using (var dr = comando.ExecuteReader()) { if (dr.Read()) { tarefa = new TarefaMod() { Id = Convert.ToInt32(dr["id"]), Nome = Convert.ToString(dr["Nome"]), Prioridade = Convert.ToInt32(dr["Prioridade"]), Concluido = Convert.ToBoolean(dr["Concluido"]), Observacao = Convert.ToString(dr["Observacao"]) }; } } } } catch (Exception ex) { throw ex; } return(tarefa); }
public bool Create(TarefaMod tarefa) { try { comando.CommandType = CommandType.Text; comando.CommandText = @"INSERT INTO TAREFAS( Nome, Prioridade, Concluido, Observacao) VALUES(" + "@Nome,@Prioridade,@Concluido,@Observacao)"; comando.Parameters.AddWithValue("@Nome", tarefa.Nome.Trim().ToUpper()); comando.Parameters.AddWithValue("@Prioridade", tarefa.Prioridade); comando.Parameters.AddWithValue("@Concluido", tarefa.Concluido); comando.Parameters.AddWithValue("@Observacao", tarefa.Observacao); comando.Connection = conn; conn.Open(); result = comando.ExecuteNonQuery() >= 1 ? true : false; } catch (Exception ex) { throw ex; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } return(result); }
public bool Update(TarefaMod tarefa) { int total = 0; try { using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexaoPessoaDB"].ConnectionString)) { comando.Connection = conn; comando.CommandType = CommandType.Text; comando.CommandText = @"UPDATE TAREFAS SET Nome=@Nome,Prioridade=@Prioridade,Concluido=@Concluido, Observacao=@Observacao WHERE Id=@Id"; comando.Parameters.AddWithValue("Nome", tarefa.Nome); comando.Parameters.AddWithValue("Prioridade", tarefa.Prioridade); comando.Parameters.AddWithValue("Concluido", tarefa.Concluido); comando.Parameters.AddWithValue("Observacao", tarefa.Observacao); comando.Parameters.AddWithValue("Id", tarefa.Id); conn.Open(); total = Convert.ToInt32(comando.ExecuteScalar()); } } catch (Exception ex) { throw ex; } return(total > 0 ?true: false); }
public ActionResult Editar(TarefaMod tarefas) { try { if (ModelState.IsValid) { repository = new Repository(); repository.Update(tarefas); return(RedirectToAction("ListarTodasTarefas")); } } catch (Exception ex) { throw ex; } return(View(tarefas)); }
public List <TarefaMod> ReadAll() { List <TarefaMod> lista = new List <TarefaMod>(); try { using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexaoPessoaDB"].ConnectionString)) { comando.Connection = conn; comando.CommandType = CommandType.Text; comando.CommandText = @"SELECT *FROM TAREFAS ORDER BY PRIORIDADE"; conn.Open(); using (var dr = comando.ExecuteReader()) { while (dr.Read()) { var tarefa = new TarefaMod(); tarefa.Id = Convert.ToInt32(dr["id"]); tarefa.Nome = Convert.ToString(dr["nome"]); tarefa.Prioridade = Convert.ToInt32(dr["prioridade"]); tarefa.Concluido = Convert.ToBoolean(dr["Concluido"]); tarefa.Observacao = Convert.ToString(dr["Observacao"]); lista.Add(tarefa); } ; } } } catch (Exception ex) { throw ex; } return(lista); }