コード例 #1
0
        public ActionResult ListarNoticias()
        {
            _repositorio = new NoticiaRepository();

            _repositorio.ListarNoticias();

            ModelState.Clear();

            return(View(_repositorio.ListarNoticias()));
        }
コード例 #2
0
        public void GravarNoticia(Noticia noticia)
        {
            INoticiaRepository noticiaRepository = new NoticiaRepository();

            Domain.Interfaces.Services.INoticiaService noticiaService = new Domain.Services.NoticiaService(noticiaRepository);

            NoticiaAppService noticiaAppService = new NoticiaAppService(noticiaService);

            noticiaAppService.Add(noticia);
        }
コード例 #3
0
        public ActionResult DeNoticia(int codNoticia)
        {
            try
            {
                _repositorio = new NoticiaRepository();

                if (_repositorio.DeletarNoticia(codNoticia))
                {
                    ViewBag.Mesagem = "Noticia Deletada com Sucesso!";
                }

                return(RedirectToAction("ListarNoticias"));
            }
            catch (Exception e)
            {
                return(View("ListarNoticias"));
            }
        }
コード例 #4
0
        public ActionResult UpNoticia(int codNoticia, NoticiaModel noticia)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _repositorio = new NoticiaRepository();

                    //Metodo para excluri imagem.
                    ExcluirImagem(noticia);

                    //Esse metodo Que salva o nome da imagem(com mais um monte de validacoes)
                    SalvarImagem(noticia);

                    _repositorio.AtualizarNoticia(noticia);
                }

                return(RedirectToAction("ListarNoticias"));
            }
            catch (Exception e)
            {
                return(View("ListarNoticias"));
            }
        }
コード例 #5
0
        public ActionResult InNoticia(NoticiaModel noticia)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _repositorio = new NoticiaRepository();

                    //Esse metodo Que salva o nome da imagem(com mais um monte de validacoes)
                    SalvarImagem(noticia);

                    if (_repositorio.InserirNoticia(noticia))
                    {
                        ViewBag.MessageCadastroSucesso = "Noticia Cadastrada com Sucesso!";
                    }
                }

                return(View());
            }
            catch (Exception e)
            {
                return(View("ListarNoticias"));
            }
        }
コード例 #6
0
        /// <summary>
        /// Action para renderizar a página inicial do projeto.
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            IndexNoticiasViewModel model = new IndexNoticiasViewModel();
            NoticiaRepository _noticiaRepository = new NoticiaRepository();

            model.NoticiaList = _noticiaRepository.FindAll().ToList();

            return View(model);
        }
コード例 #7
0
 public ActionResult UpNoticia(int codNoticia)
 {
     _repositorio = new NoticiaRepository();
     return(View(_repositorio.ListarNoticias().Find(l => l.cod_noticia.Equals(codNoticia))));
 }
コード例 #8
0
 public NoticiaController(NoticiaRepository repo, IMapper mapper, PortalNoticiasContext context)
 {
     _repo    = repo;
     _mapper  = mapper;
     _context = context;
 }