Exemplo n.º 1
0
        public ActionResult Edit(Int32 id)
        {
            if (Request.Cookies["MagazineId"].Value == null)
            {
                SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines"));
            }
            int magId = Int32.Parse(Request.Cookies["MagazineId"].Value);

            var user     = UserService.GetCurrentUser();
            var relation = UserService.UserInMagazine(magId, user.UserId);

            if (!relation || !ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Magazines"));
            }

            Slide Slides = db.SlidesList.Include(x => x.News).Where(x => x.SlideId == id).SingleOrDefault();

            if (Slides == null)
            {
                return(HttpNotFound());
            }

            var noticia = MagazineService.GetNewsById(Slides.NewsId);

            if (noticia == null)
            {
                SetMessage("No se encontró la noticia.", BootstrapAlertTypes.Danger);
                return(RedirectToAction("Index", "Magazines"));
            }

            ViewBag.MagId  = noticia.Category.MagazineId;
            ViewBag.NewsId = new SelectList(db.NewsesList.Include(x => x.Category).Where(x => !x.IsDeleted).Where(x => x.Category.MagazineId == noticia.Category.MagazineId).ToList(), "NewsId", "Title", Slides.NewsId);
            return(View(Slides));
        }
Exemplo n.º 2
0
        public ActionResult Edit(Int32 id, Int32?newMagId)
        {
            if (newMagId.HasValue)
            {
                Request.Cookies.Remove("MagazineId");
                SetCookie("MagazineId", newMagId, true);
            }

            if (Request.Cookies["MagazineId"].Value == null)
            {
                SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines"));
            }
            int magId = Int32.Parse(Request.Cookies["MagazineId"].Value);

            ViewBag.MagId = magId;
            var user     = UserService.GetCurrentUser();
            var relation = UserService.UserInMagazine(magId, user.UserId);

            if (!relation)
            {
                return(RedirectToAction("Index", "Magazines"));
            }

            var news = MagazineService.GetNewsById(id);

            if (news == null)
            {
                SetMessage("Lo sentimos, no se encontró la noticia", BootstrapAlertTypes.Danger);
                return(RedirectToAction("MyNews"));
            }

            ViewBag.CategoryId = new SelectList(MagazineService.GetCategoriesByMagazineId(magId), "CategoryId", "Name", news.CategoryId);

            var model = new NewsViewModel
            {
                Body         = news.Body,
                CategoryId   = news.CategoryId,
                Description  = news.Description,
                LogoImage    = news.Image,
                NewsId       = news.NewsId,
                Title        = news.Title,
                Alt          = news.Alt,
                MetaDesc     = news.MetaDesc,
                MetaTags     = news.Keywords,
                Permalink    = news.Permalink,
                IsClon       = news.IsClon,
                ThankNote    = news.ThankNote,
                VideoEmbed   = news.VideoEmbed,
                CreationDate = news.CreationDate.ToString()
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public JsonResult AddComment(Int32 id, String comment)
        {
            var noticia = MagazineService.GetNewsById(id);

            if (noticia == null)
            {
                return(Json("Lo sentimos, el artículo no existe. Inténtelo con otro distinto.", JsonRequestBehavior.AllowGet));
            }

            if (!ModelState.IsValid)
            {
                return(Json("Lo sentimos, los datos no son válidos. Inténtelo de nuevo.", JsonRequestBehavior.AllowGet));
            }

            if (!MagazineService.CreateComment(comment, id))
            {
                return(Json("Lo sentimos, no se pudo guardar el comentario. Inténtelo de nuevo.", JsonRequestBehavior.AllowGet));
            }

            return(Json("Comentario públicado exitosamente.", JsonRequestBehavior.AllowGet));
        }