New Migration

This commit is contained in:
GuiNerd
2019-09-22 09:00:10 -03:00
parent 07230df64b
commit f9c65d9a91
33 changed files with 1199 additions and 198 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,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");
}
}
}