Requisitos Controller

This commit is contained in:
GuiNerd
2019-09-22 08:30:34 -03:00
parent 0fbde86dcc
commit 07230df64b
38 changed files with 1205 additions and 353 deletions

View File

@ -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");
}
}
}