mirror of
https://github.com/guilhermewerner/gerencia-projetos
synced 2025-06-16 15:05:39 +00:00
New Migration
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,117 @@ namespace GerenciaProjetos.Controllers
|
||||
public BugsController(GerenciaContext ctx)
|
||||
{
|
||||
this.ctx = ctx;
|
||||
|
||||
Requisito dev = ctx.Requisitos.Find(1);
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
ViewBag.Bugs = ctx.Bugs;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult New()
|
||||
{
|
||||
ViewData["Title"] = "Novo";
|
||||
|
||||
ViewBag.Desenvolvedores = ctx.Desenvolvedores.OrderBy(d => d.Nome).Select(d => new SelectListItem
|
||||
{
|
||||
Text = d.Nome,
|
||||
Value = d.Id.ToString()
|
||||
});
|
||||
|
||||
ViewBag.Requisitos = ctx.Requisitos.OrderBy(r => r.Descricao).Select(r => new SelectListItem
|
||||
{
|
||||
Text = r.Descricao,
|
||||
Value = r.Id.ToString()
|
||||
});
|
||||
|
||||
return View("Form");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult New(Bug bug)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
bug.DataCadastro = DateTime.Now;
|
||||
|
||||
ctx.Bugs.Add(bug);
|
||||
ctx.SaveChanges();
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
else
|
||||
{
|
||||
return View("Form", bug);
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult Edit(int id)
|
||||
{
|
||||
ViewData["Title"] = "Editar";
|
||||
|
||||
ViewBag.Desenvolvedores = ctx.Desenvolvedores.OrderBy(d => d.Nome).Select(d => new SelectListItem
|
||||
{
|
||||
Text = d.Nome,
|
||||
Value = d.Id.ToString()
|
||||
});
|
||||
|
||||
ViewBag.Requisitos = ctx.Requisitos.OrderBy(r => r.Descricao).Select(r => new SelectListItem
|
||||
{
|
||||
Text = r.Descricao,
|
||||
Value = r.Id.ToString()
|
||||
});
|
||||
|
||||
Bug bug = ctx.Bugs.Find(id);
|
||||
|
||||
if (bug != null)
|
||||
{
|
||||
return View("Form", bug);
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public IActionResult Edit(Bug bug)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
/*
|
||||
ctx.Entry(bug).Property(r => r.DesenvolvedorId).IsModified = true;
|
||||
ctx.Entry(bug).Property(r => r.RequisitoId).IsModified = true;
|
||||
ctx.Entry(bug).Property(r => r.CriadorId).IsModified = true;
|
||||
ctx.Entry(bug).Property(r => r.Prioridade).IsModified = true;
|
||||
*/
|
||||
|
||||
bug.DataCadastro = DateTime.Now;
|
||||
|
||||
ctx.Bugs.Update(bug);
|
||||
ctx.SaveChanges();
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
else
|
||||
{
|
||||
return View("Form", bug);
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult Del(int id)
|
||||
{
|
||||
Bug bug = ctx.Bugs.Find(id);
|
||||
|
||||
if (bug != null)
|
||||
{
|
||||
ctx.Bugs.Remove(bug);
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user