mirror of
https://github.com/guilhermewerner/gerencia-projetos
synced 2025-06-16 15:05:39 +00:00
Requisitos Controller
This commit is contained in:
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using GerenciaProjetos.Models;
|
||||
using GerenciaContext = GerenciaProjetos.Data.GerenciaContext;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
|
||||
namespace GerenciaProjetos.Controllers
|
||||
{
|
||||
@ -16,13 +17,100 @@ namespace GerenciaProjetos.Controllers
|
||||
public RequisitosController(GerenciaContext ctx)
|
||||
{
|
||||
this.ctx = ctx;
|
||||
|
||||
Desenvolvedor dev = ctx.Desenvolvedores.Find(1);
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
ViewBag.Requisitos = ctx.Requisitos;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult New()
|
||||
{
|
||||
ViewData["Title"] = "Novo";
|
||||
|
||||
ViewBag.Projetos = ctx.Projetos.OrderBy(p => p.Nome).Select(p => new SelectListItem
|
||||
{
|
||||
Text = p.Nome,
|
||||
Value = p.Id.ToString()
|
||||
});
|
||||
|
||||
return View("Form");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult New(Requisito req)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
req.DataCadastro = DateTime.Now;
|
||||
|
||||
ctx.Requisitos.Add(req);
|
||||
ctx.SaveChanges();
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
else
|
||||
{
|
||||
return View("Form", req);
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult Edit(int id)
|
||||
{
|
||||
ViewData["Title"] = "Editar";
|
||||
|
||||
ViewBag.Projetos = ctx.Projetos.OrderBy(p => p.Nome).Select(p => new SelectListItem
|
||||
{
|
||||
Text = p.Nome,
|
||||
Value = p.Id.ToString()
|
||||
});
|
||||
|
||||
Requisito req = ctx.Requisitos.Find(id);
|
||||
|
||||
if (req != null)
|
||||
{
|
||||
return View("Form", req);
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public IActionResult Edit(Requisito req)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
ctx.Entry(req).Property(r => r.Descricao).IsModified = true;
|
||||
ctx.Entry(req).Property(r => r.Observacoes).IsModified = true;
|
||||
ctx.Entry(req).Property(r => r.ProjetoId).IsModified = true;
|
||||
ctx.Entry(req).Property(r => r.DataEntrega).IsModified = true;
|
||||
|
||||
ctx.SaveChanges();
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
else
|
||||
{
|
||||
return View("Form", req);
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult Del(int id)
|
||||
{
|
||||
Requisito req = ctx.Requisitos.Find(id);
|
||||
|
||||
if (req != null)
|
||||
{
|
||||
ctx.Requisitos.Remove(req);
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user