You are on page 1of 3

using CRCRJ.Application.

Interfaces;
using CRCRJ.Application.ViewModels;
using System;
using System.Net;
using System.Web.Mvc;

namespace CRCRJ.Presentation.Controllers
{
public class NoticiasController : Controller
{
private readonly INoticiaAppService _appService;

public NoticiasController(INoticiaAppService appService)


{
_appService = appService;
}

// GET: Categorias
public ActionResult Index()
{
return View(_appService.ObterTodos());
}

// GET: Categorias/Details/5
public ActionResult Details(int id = 0)
{
if (id == 0)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var objeto = _appService.ObterPorId(id);
if (objeto == null)
{
return HttpNotFound();
}
return View(objeto);
}

// GET: Categorias/Create
public ActionResult Create()
{
return View();
}

// POST: Categorias/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(NoticiaViewModel objeto)
{
var o = objeto;
if (ModelState.IsValid)
{
// _appService.Adicionar(objeto);

return RedirectToAction("Index");
}

return View(objeto);
}
// GET: Categorias/Edit/5
public ActionResult Edit(int id = 0)
{
if (id == 0)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var objeto = _appService.ObterPorId(id);
if (objeto == null)
{
return HttpNotFound();
}
return View(objeto);
}

// POST: Categorias/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(NoticiaViewModel objeto)
{
var o = objeto;
if (ModelState.IsValid)
{
_appService.Alterar(objeto);

return RedirectToAction("Index");
}
return View(objeto);
}

// GET: Categorias/Delete/5
public ActionResult Delete(int id = 0)
{
if (id == 0)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var objeto = _appService.ObterPorId(id);
if (objeto == null)
{
return HttpNotFound();
}
return View(objeto);
}

// POST: Categorias/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id = 0)
{
_appService.Remover(_appService.ObterPorId(id));

return RedirectToAction("Index");
}

protected override void Dispose(bool disposing)


{
if (disposing)
{
_appService.Dispose();
}
base.Dispose(disposing);
}
}
}

You might also like