Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using CadastroTarefas2.Models;
- using CadastroTarefas2.repositorio;
- namespace CadastroTarefas2.Controllers
- {
- public class TarefasController : Controller
- {
- // GET: Tarefas
- private TarefaRepositorio tarefaRepositorio;
- public ActionResult ObterTarefas()
- {
- tarefaRepositorio = new TarefaRepositorio();
- ModelState.Clear();
- return View(tarefaRepositorio.ObterTarefas());
- }
- [HttpGet]
- public ActionResult IncluirTarefa()
- {
- return View("ObterTarefas");
- }
- [HttpPost]
- public ActionResult IncluirTarefa(Tarefas tarefa)
- {
- try
- {
- if (ModelState.IsValid)
- {
- tarefaRepositorio = new TarefaRepositorio();
- if (tarefaRepositorio.AdicionarTarefa(tarefa))
- {
- ViewBag.Mensagem = "Tarefa cadastrada com sucesso";
- }
- }
- return RedirectToAction("ObterTarefas");
- }
- catch (Exception)
- {
- return View("ObterTarefas");
- }
- }
- [HttpGet]
- public ActionResult EditarTarefa(int id)
- {
- tarefaRepositorio = new TarefaRepositorio();
- return View(tarefaRepositorio.ObterTarefas().Find(t => t.ID == id));
- }
- [HttpPost]
- public ActionResult EditarTarefa(int id, Tarefas tarefa)
- {
- try
- {
- tarefaRepositorio = new TarefaRepositorio();
- tarefaRepositorio.AtualizarTarefa(tarefa);
- return RedirectToAction("ObterTarefas");
- } catch (Exception)
- {
- return View("ObterTarefas");
- }
- }
- public ActionResult ExcluirTarefa(int id)
- {
- try
- {
- tarefaRepositorio = new TarefaRepositorio();
- if (tarefaRepositorio.ExcluirTarefa(id))
- {
- //ViewBag.Mensagem = "Tarefa excluida com sucesso";
- }
- return RedirectToAction("ObterTarefas");
- }
- catch (Exception)
- {
- return View("ObterTarefas");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement