public ActionResult IncluirNoticia()
        {
            USUARIO usuario = new USUARIO();

            if ((String)Session["Ativa"] == null)
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }
            if ((USUARIO)Session["UserCredentials"] != null)
            {
                usuario = (USUARIO)Session["UserCredentials"];

                // Verfifica permissão
                if (usuario.PERFIL.PERF_SG_SIGLA != "ADM" || usuario.PERFIL.PERF_SG_SIGLA != "SIN" || usuario.PERFIL.PERF_SG_SIGLA != "CON")
                {
                    Session["MensNoticia"] = 2;
                    return(RedirectToAction("CarregarBase", "BaseAdmin"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }

            // Prepara view
            NOTICIA          item = new NOTICIA();
            NoticiaViewModel vm   = Mapper.Map <NOTICIA, NoticiaViewModel>(item);

            vm.ASSI_CD_ID       = (Int32)Session["IdAssinante"];
            vm.NOTC_DT_EMISSAO  = DateTime.Today.Date;
            vm.NOTC_IN_ATIVO    = 1;
            vm.NOTC_DT_VALIDADE = DateTime.Today.Date.AddDays(30);
            vm.NOTC_NR_ACESSO   = 0;
            return(View(vm));
        }
Пример #2
0
        public async Task <IActionResult> Edit(string id)
        {
            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    var respuesta = await apiServicio.SeleccionarAsync <Response>(id, new Uri(WebApp.BaseAddress),
                                                                                  "api/Noticias");

                    respuesta.Resultado = JsonConvert.DeserializeObject <Noticia>(respuesta.Resultado.ToString());

                    var item = new NoticiaViewModel
                    {
                        Noticia = (Noticia)respuesta.Resultado,
                    };

                    ViewData["Foto"] = item.Noticia.Foto;

                    if (respuesta.IsSuccess)
                    {
                        InicializarMensaje(null);
                        return(View(respuesta.Resultado));
                    }
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        public ActionResult EditarNoticia(Int32 id)
        {
            // Prepara view
            USUARIO usuario = new USUARIO();

            if ((String)Session["Ativa"] == null)
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }
            if ((USUARIO)Session["UserCredentials"] != null)
            {
                usuario = (USUARIO)Session["UserCredentials"];

                // Verfifica permissão
                if (usuario.PERFIL.PERF_SG_SIGLA != "ADM" || usuario.PERFIL.PERF_SG_SIGLA != "SIN" || usuario.PERFIL.PERF_SG_SIGLA != "CON")
                {
                    Session["MensAcesso"] = 2;
                    return(RedirectToAction("CarregarBase", "BaseAdmin"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }

            NOTICIA item = baseApp.GetItemById(id);

            objetoAntes        = item;
            Session["Noticia"] = item;
            Session["IdVolta"] = id;
            NoticiaViewModel vm = Mapper.Map <NOTICIA, NoticiaViewModel>(item);

            return(View(vm));
        }
        public ActionResult ExcluirNoticia(NoticiaViewModel vm)
        {
            if ((String)Session["Ativa"] == null)
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }
            try
            {
                // Executa a operação
                USUARIO usuarioLogado = (USUARIO)Session["UserCredentials"];
                NOTICIA item          = Mapper.Map <NoticiaViewModel, NOTICIA>(vm);
                Int32   volta         = baseApp.ValidateDelete(item, usuarioLogado);

                // Verifica retorno

                // Sucesso
                listaMaster             = new List <NOTICIA>();
                Session["ListaNoticia"] = null;
                Session["MensNoticia"]  = 0;
                return(RedirectToAction("MontarTelaNoticia"));
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
                return(View(objeto));
            }
        }
        public ActionResult ReativarNoticia(Int32 id)
        {
            USUARIO usuario = new USUARIO();

            if ((String)Session["Ativa"] == null)
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }
            if ((USUARIO)Session["UserCredentials"] != null)
            {
                usuario = (USUARIO)Session["UserCredentials"];

                // Verfifica permissão
                if (usuario.PERFIL.PERF_SG_SIGLA != "ADM")
                {
                    Session["MensNoticia"] = 2;
                    return(RedirectToAction("MontarTelaNoticia", "Noticia"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }

            // Prepara view
            NOTICIA          item = baseApp.GetItemById(id);
            NoticiaViewModel vm   = Mapper.Map <NOTICIA, NoticiaViewModel>(item);

            return(View(vm));
        }
Пример #6
0
        public IHttpActionResult ObterNoticias(int?idEditoria = null, int?idNoticia = null)
        {
            var noticia  = new NoticiaViewModel();
            var noticias = new List <NoticiaViewModel>();

            if (idNoticia != null)
            {
                noticia = NoticiasService.ObterNoticia(idNoticia.Value);

                if (noticia == null)
                {
                    return(Json(new { Falha = new { code = HttpStatusCode.NotFound, msg = "Notícia não encontada." } }));
                }

                noticias = NoticiasService.ObterNoticiasRelacionadas(idNoticia.Value);

                return(Json(new { Noticia = noticia, Relacionados = noticias }));
            }
            else
            {
                noticias = NoticiasService.ObterNoticias(idEditoria);
            }

            return(Json(noticias));
        }
Пример #7
0
        public IActionResult Create()
        {
            NoticiaViewModel model = new NoticiaViewModel();

            model.Categorias     = new SelectList(db.Categorias.OrderBy(c => c.Descricao), "Id", "Descricao");
            model.DataPublicacao = DateTime.Now;
            return(View(model));
        }
Пример #8
0
        // GET: Noticia/Create
        public async Task <IActionResult> Create(int?id)
        {
            var model = new NoticiaViewModel
            {
                Not_FechaCreacion = DateTime.Today,
                Not_Estado        = 'A',
            };

            return(View(model));
        }
Пример #9
0
        public async Task <ActionResult <NoticiaViewModel> > Adicionar(NoticiaViewModel noticiaViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }
            var result = await _noticiaService.Adicionar(_mapper.Map <Noticia>(noticiaViewModel));

            return(CustomResponse(noticiaViewModel));
        }
        public ActionResult Index()
        {
            if ((String)Session["Ativa"] == null)
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }
            NOTICIA          item = new NOTICIA();
            NoticiaViewModel vm   = Mapper.Map <NOTICIA, NoticiaViewModel>(item);

            return(View(vm));
        }
Пример #11
0
        public ActionResult Edit(NoticiaViewModel noticia)
        {
            if (ModelState.IsValid)
            {
                var noticiaDomain = Mapper.Map <NoticiaViewModel, Noticia>(noticia);
                _noticiaApp.Update(noticiaDomain);

                return(RedirectToAction("Index"));
            }

            return(View(noticia));
        }
Пример #12
0
        public IActionResult Atualizar([FromBody] NoticiaViewModel command)
        {
            if (!ModelState.IsValid)
            {
                NotifyModelStateErrors();
                return(Response(command));
            }

            _noticiaAppService.Atualizar(command);

            return(Response(command));
        }
Пример #13
0
 public async Task <Noticiastbl> ToNoticiaAsync(NoticiaViewModel model, bool IsNew, string path)
 {
     return(new Noticiastbl
     {
         Not_Titulo = model.Not_Titulo,
         Not_Autor = model.Not_Autor,
         Not_Descripcion = model.Not_Descripcion,
         Not_Fecha = model.Not_Fecha,
         Id = IsNew ? 0 : model.Id,
         ImageUrl = path,
         Not_Estado = 'A',
     });
 }
Пример #14
0
        public static NoticiaViewModel ObterNoticia(int idNoticia)
        {
            string key = primeKey + "ObterNoticia:" + idNoticia + ":TNoticias";

            NoticiaViewModel retorno = null;

            using (var db = new ModeloDados())
            {
                Func <object, NoticiaViewModel> funcao = t => ObterNoticia(db, idNoticia);
                retorno = Site.Services.RedisService.GetOrSetToRedis(key, funcao, 10);
            }

            return(retorno);
        }
        public ActionResult IncluirNoticia(NoticiaViewModel vm)
        {
            if ((String)Session["Ativa"] == null)
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    // Executa a operação
                    Int32   idAss         = (Int32)Session["IdAssinante"];
                    NOTICIA item          = Mapper.Map <NoticiaViewModel, NOTICIA>(vm);
                    USUARIO usuarioLogado = (USUARIO)Session["UserCredentials"];
                    Int32   volta         = baseApp.ValidateCreate(item, usuarioLogado);

                    // Verifica retorno

                    // Carrega foto e processa alteracao
                    item.NOTC_AQ_FOTO = "~/Imagens/p_big2.jpg";
                    volta             = baseApp.ValidateEdit(item, item, usuarioLogado);

                    // Cria pastas
                    String caminho = "/Imagens/" + idAss.ToString() + "/Noticias/" + item.NOTC_CD_ID.ToString() + "/Fotos/";
                    Directory.CreateDirectory(Server.MapPath(caminho));

                    // Sucesso
                    listaMaster               = new List <NOTICIA>();
                    Session["ListaNoticia"]   = null;
                    Session["VoltaNoticia"]   = 1;
                    Session["IdNoticiaVolta"] = item.NOTC_CD_ID;
                    Session["Noticia"]        = item;
                    Session["MensNoticia"]    = 0;
                    if ((Int32)Session["VoltaNoticia"] == 2)
                    {
                        return(RedirectToAction("VerCardsNoticias"));
                    }
                    return(RedirectToAction("MontarTelaNoticia"));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                    return(View(vm));
                }
            }
            else
            {
                return(View(vm));
            }
        }
Пример #16
0
        public ActionResult Create(NoticiaViewModel noticia)
        {
            Server.HtmlEncode(noticia.Conteudo);

            if (ModelState.IsValid)
            {
                var noticiaDomain = Mapper.Map <NoticiaViewModel, Noticia>(noticia);
                _noticiaApp.Add(noticiaDomain);

                return(RedirectToAction("List"));
            }

            ViewBag.UsuarioId = new SelectList(_usuarioApp.GetAll(), "UsuarioId", "Nome", noticia.UsuarioId);
            return(View(noticia));
        }
Пример #17
0
        public ActionResult EditarNoticia(NoticiaViewModel noticia)
        {
            Server.HtmlEncode(noticia.Conteudo);

            if (ModelState.IsValid)
            {
                var noticiaDomain = Mapper.Map <NoticiaViewModel, Noticia>(noticia);
                _noticiaApp.Update(noticiaDomain);

                return(RedirectToAction("MinhasNoticias"));
            }

            ViewBag.UsuarioId = new SelectList(_usuarioApp.GetAll().Where(n => n.UsuarioId == Convert.ToInt32(Session["usuarioLogadoID"])), "UsuarioId", "Nome", noticia.UsuarioId);
            return(View(noticia));
        }
Пример #18
0
        public async Task <IActionResult> Edit(NoticiaViewModel model)
        {
            if (ModelState.IsValid)
            {
                Noticia noticia = await db.Noticias.SingleOrDefaultAsync(n => n.Id == model.Id);

                noticia.CategoriaId = model.CategoriaId;

                db.Update(noticia);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Пример #19
0
        public async Task <ActionResult <NoticiaViewModel> > Atualizar(Guid id, NoticiaViewModel noticiaViewModel)
        {
            if (id != noticiaViewModel.Id)
            {
                NotificarErro("O id informado não é o mesmo que foi passado na query");
                return(CustomResponse(noticiaViewModel));
            }

            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }
            await _noticiaService.Atualizar(_mapper.Map <Noticia>(noticiaViewModel));

            return(CustomResponse(noticiaViewModel));
        }
        public IActionResult Upsert(int?id)
        {
            ViewData["idUserS"] = TempData["idUserS"].ToString();
            //TempData.Keep();
            ViewData["correoUserS"] = TempData["correoUserS"].ToString();
            TempData.Keep();
            var idU = ViewData["idUserS"].ToString();


            var c          = _db.Usuarios.FirstOrDefault(s => s.Id == idU);
            var f          = _db.Municipalidades.FirstOrDefault(a => a.id == c.municipalidadId);
            var listaRoles = _db.UserRoles.FirstOrDefault(m => m.UserId == c.Id);



            ViewBag.muni = f.nombreMunicipalidad;



            NoticiaViewModel modelo = new NoticiaViewModel
            {
                Noticia         = new Noticia(),
                Municipalidades = _controlador.Municipalidades.Listar().Select
                                  (
                    s => new SelectListItem
                {
                    Text  = s.nombreMunicipalidad,
                    Value = s.id.ToString()
                }
                                  )
            };

            if (id == null)
            {
                return(View(modelo));
            }
            else
            {
                modelo.Noticia = _controlador.Noticias.Buscar(id.GetValueOrDefault());
                if (modelo.Noticia == null)
                {
                    return(NotFound());
                }

                return(View(modelo));
            }
        }
        public ActionResult VerNoticia(Int32 id)
        {
            if ((String)Session["Ativa"] == null)
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }
            Session["IdVolta"] = id;
            NOTICIA item = baseApp.GetItemById(id);

            item.NOTC_NR_ACESSO = ++item.NOTC_NR_ACESSO;
            objetoAntes         = item;
            Int32 volta = baseApp.ValidateEdit(item, objetoAntes);

            NoticiaViewModel vm = Mapper.Map <NOTICIA, NoticiaViewModel>(item);

            return(View(vm));
        }
Пример #22
0
        public async Task <ActionResult> Create(NoticiaViewModel view, List <IFormFile> files)
        {
            if (files.Count > 0)
            {
                byte[] data;
                using (var br = new BinaryReader(files[0].OpenReadStream()))
                    data = br.ReadBytes((int)files[0].OpenReadStream().Length);

                var noticiatransfer = new NoticiaTransfer
                {
                    Titulo      = view.Titulo,
                    Fecha       = view.Fecha,
                    Descripcion = view.Descripcion,
                    Fichero     = data,
                };

                var respuesta = await CrearFichero(noticiatransfer);

                Noticia onoticia = JsonConvert.DeserializeObject <Noticia>(respuesta.Resultado.ToString());

                if (respuesta.IsSuccess)
                {
                    await uploadFileService.UploadFile(noticiatransfer.Fichero, "Noticias", Convert.ToString(onoticia.IdNoticia), "jpg");

                    onoticia.Foto = string.Format("{0}/{1}.{2}", "Noticias", Convert.ToString(onoticia.IdNoticia), "jpg");

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewData["Error"] = respuesta.Message;

                    var noticia = new Noticia
                    {
                        Titulo = view.Titulo,
                    };
                    InicializarMensaje(null);
                    return(View(noticia));
                }
            }

            return(BadRequest());
        }
Пример #23
0
        public async Task <ActionResult> Get([FromRoute] string tema, string start)
        {
            try
            {
                HttpClient cliente = new HttpClient();
                cliente.DefaultRequestHeaders.Add("User-Agent", "aspnetcoremaster.com");

                cliente.BaseAddress = new Uri("https://www.googleapis.com");

                string jsonFromGoogle = "";

                /*if(jsonFromGoogle.Equals("Deportes"))
                 *   jsonFromGoogle = await cliente.GetStringAsync("/customsearch/v1?key=AIzaSyBZLm0x5sKGSI0fex-zYdAcyuPe68OvjBk&cx=007020137502699158807:z6srbycjumm&q=" + tema + "&sort=date&start=" + start);
                 * else*/
                jsonFromGoogle = await cliente.GetStringAsync("/customsearch/v1?key=AIzaSyBZLm0x5sKGSI0fex-zYdAcyuPe68OvjBk&cx=007020137502699158807:twljqntbg80&q=" + tema + "&sort=date&start=" + start);

                Noticia noti     = JsonSerializer.Deserialize <Noticia>(jsonFromGoogle);
                var     noticias = new List <NoticiaViewModel>();
                var     noticia  = new NoticiaViewModel();
                foreach (ItemNoticia iten in noti.items)
                {
                    try
                    {
                        noticia             = new NoticiaViewModel();
                        noticia.Titulo      = iten.title;
                        noticia.Descripcion = iten.snippet;
                        noticia.Link        = iten.link;
                        noticia.LinkMostrar = iten.displayLink;
                        noticia.Imagen      = iten.pagemap.cse_thumbnail[0].src;
                        noticias.Add(noticia);
                    }
                    catch
                    {
                    }
                }

                return(Ok(noticias));
            }
            catch (Exception e)
            {
                return(BadRequest(e.InnerException != null ? e.InnerException.Message : e.Message));
            }
        }
        public ActionResult AddNoticia(NoticiaViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new SaludOcupacionalEntities())
            {
                Noticia oNoticia = new Noticia();

                oNoticia.titulo = model.titulo;
                oNoticia.texto  = model.texto;
                oNoticia.fecha  = DateTime.Now; // Fecha y hora del momento actual.

                db.Noticia.Add(oNoticia);

                if (model.archivo != null)
                {
                    Archivo oArchivo = new Archivo();

                    oArchivo.nombre = model.archivo.FileName;
                    oArchivo.tipo   = model.archivo.ContentType;

                    /* Las rutas del archivo se crean mediante la fecha y el nombre del archivo, así evitando que haya
                     * conflictos con archivos que se llamen igual.*/
                    string strDateTime = System.DateTime.Now.ToString("ddMMyyyHHMMss");
                    string filePath    = "\\UploadedFiles\\" + strDateTime + model.archivo.FileName;

                    model.archivo.SaveAs(Server.MapPath("~") + filePath);

                    oArchivo.filePath  = filePath;
                    oArchivo.idNoticia = oNoticia.idNoticia;

                    db.Archivo.Add(oArchivo);
                }

                db.SaveChanges();
            }

            return(Redirect(Url.Content("~/AdminNoticia")));
        }
Пример #25
0
        public async Task <IActionResult> Edit(NoticiaViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = model.ImageUrl;

                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsyncNoticia(model.ImageFile);
                }

                var noticia = await _converterHelper.ToNoticiaAsync(model, false, path);

                _context.Noticiastbls.Update(noticia);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
Пример #26
0
        public async Task <IActionResult> Create(NoticiaViewModel model)
        {
            if (ModelState.IsValid)
            {
                Noticia noticia = new Noticia()
                {
                    Titulo         = model.Titulo,
                    Corpo          = model.Corpo,
                    DataPublicacao = model.DataPublicacao,
                    Autor          = model.Autor,
                    Destaque       = model.Destaque,
                    CategoriaId    = model.CategoriaId
                };
                db.Add(noticia);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Пример #27
0
        public async Task <IActionResult> Create(NoticiaViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsyncNegocio(model.ImageFile);
                }

                var noticia = await _converterHelper.ToNoticiaAsync(model, true, path);

                _context.Noticiastbls.Add(noticia);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
Пример #28
0
        public ActionResult Create(NoticiaViewModel noticia)
        {
            if (ModelState.IsValid)
            {
                var noticiaDomain = Mapper.Map <NoticiaViewModel, Noticia>(noticia);
                var client        = new NoticiaServiceWCF.NoticiaServiceClient();
                client.Open();
                try
                {
                    client.GravarNoticia(noticiaDomain);
                }
                catch (FaultException <NoticiaService> )
                {
                }
                client.Close();
                //_noticiaApp.Add(noticiaDomain);

                return(RedirectToAction("Index"));
            }

            return(View(noticia));
        }
Пример #29
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Noticia noticia = await db.Noticias.SingleOrDefaultAsync(n => n.Id == id);

            if (noticia == null)
            {
                return(NotFound());
            }

            NoticiaViewModel model = new NoticiaViewModel
            {
                Id          = noticia.Id,
                CategoriaId = noticia.CategoriaId
            };

            return(View(model));
        }
        public ActionResult EditarNoticia(NoticiaViewModel vm)
        {
            if ((String)Session["Ativa"] == null)
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    // Executa a operação
                    Int32   idAss         = (Int32)Session["IdAssinante"];
                    USUARIO usuarioLogado = (USUARIO)Session["UserCredentials"];
                    NOTICIA item          = Mapper.Map <NoticiaViewModel, NOTICIA>(vm);
                    Int32   volta         = baseApp.ValidateEdit(item, objetoAntes, usuarioLogado, idAss);

                    // Verifica retorno

                    // Sucesso
                    listaMaster             = new List <NOTICIA>();
                    Session["ListaNoticia"] = null;
                    Session["MensNoticia"]  = 0;
                    if ((Int32)Session["VoltaNoticia"] == 2)
                    {
                        return(RedirectToAction("VerCardsNoticias"));
                    }
                    return(RedirectToAction("MontarTelaNoticia"));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                    return(View(vm));
                }
            }
            else
            {
                return(View(vm));
            }
        }