Exemplo n.º 1
0
        public ActionResult Create(NewsViewModel model)
        {
            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);

            ViewBag.MagId = magId;
            if (!relation)
            {
                return(RedirectToAction("Index", "Magazines"));
            }

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

            if (!ModelState.IsValid)
            {
                SetMessage("Lo sentimos, favor de utilizar una imagen de menor peso debe de tener un máximo 1.6 Mb. Inténtelo de nuevo.", BootstrapAlertTypes.Danger);
                return(View(model));
            }

            var category = MagazineService.GetCategoryById(model.CategoryId);

            if (category == null)
            {
                SetMessage("No se encontró la categoría.", BootstrapAlertTypes.Danger);
                return(RedirectToAction("MyNews"));
            }

            var parsedDate = (!String.IsNullOrEmpty(model.CreationDate) ? DateTime.ParseExact(model.CreationDate, "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture) : DateTime.Now);

            var create = MagazineService.CreateNews(model.Title, model.Description, model.MainImage, model.Thumbnail, model.Body,
                                                    model.CategoryId, model.Permalink, model.MetaDesc, model.MetaTags, model.Alt, model.VideoEmbed, parsedDate);

            if (create == null)
            {
                SetMessage(MagazineService.ServiceTempData);
                SetMessage("Ocurrió un error inesperado. Inténtelo de nuevo.", BootstrapAlertTypes.Danger);
                return(RedirectToAction("MyNews"));
            }

            if (user == null)
            {
                TweetNews("http://www.expose.mx/noticia/" + create.NewsId + "/tw/" + 2 + " " + create.Description);
            }
            else
            {
                TweetNews("Expose.mx http://www.expose.mx/noticia/" + create.NewsId + "/tw/" + user.UserId + " " + create.Description);
            }

            SetMessage("Noticia creada exitosamente", BootstrapAlertTypes.Success);
            return(RedirectToAction("MyNews"));
        }
Exemplo n.º 2
0
        public ActionResult CreateNew(NewsViewModel model)
        {
            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);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var category = MagazineService.GetCategoryById(model.CategoryId);

            if (category == null)
            {
                return(RedirectToAction("Index", "Magazines"));
            }

            var imageCode = "Expose_Default_New.png";

            if (model.Image != null && model.Image.ContentLength > 0)
            {
                var imageModel = ResourceService.SaveImage(Server.MapPath("~/content/data/"), model.Image, false);
                if (imageModel == null)
                {
                    ModelState.AddModelError("", "No se pudo guardar la imagen. Intentalo de nuevo.");
                    return(View(model));
                }
                imageCode = imageModel.FullFileName;
            }

            var create = MagazineService.CreateNews(model.Title, model.Description, model.MainImage, model.Thumbnail, model.Body,
                                                    model.CategoryId, model.Permalink, model.MetaDesc, model.MetaTags, model.Alt, model.VideoEmbed, DateTime.Now);

            if (create == null)
            {
                SetMessage(MagazineService.ServiceTempData);
                return(RedirectToAction("Index", "Magazines"));
            }

            var user = MagazineService.GetCurrentUser();

            if (user == null)
            {
                TweetNews("http://www.expose.mx/noticia/" + create.NewsId + "/tw/" + 2 + " " + create.Description);
            }
            else
            {
                TweetNews("Expose.mx http://www.expose.mx/noticia/" + create.NewsId + "/tw/" + user.UserId + " " + create.Description);
            }

            return(RedirectToAction("MagazineNews", "News", new { id = create.Category.MagazineId }));
        }
Exemplo n.º 3
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"));
            }

            var category = MagazineService.GetCategoryById(id);

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

            ViewBag.MagazineId = new SelectList(MagazineService.GetCurrentUserMagazines(), "MagazineId", "Title", category.MagazineId);
            var categories = MagazineService.GetCategoriesByMagazineId(magId);

            ViewBag.ParentCategory = category.ParentCategoryId ?? null;
            var model = new CategoryViewModel
            {
                Name              = category.Name,
                CategoryId        = category.CategoryId,
                LogoImage         = category.Image,
                MagazineId        = category.MagazineId,
                Permalink         = category.Permalink,
                ParentsCategories = categories
            };

            return(View(model));
        }
Exemplo n.º 4
0
        public ActionResult Categories(Int32 id)
        {
            var category = MagazineService.GetCategoryById(id);

            if (category == null)
            {
                SetMessage("No se encontró la categoría.", BootstrapAlertTypes.Danger);
                return(Redirect("/"));
            }

            var newsByCategories = MagazineService.GetNewsesByCategoryId(id);

            var model = new CategoriesViewModel
            {
                NewsByCategories = newsByCategories,
                Category         = category
            };

            return(View(model));
        }