Exemplo n.º 1
0
        public ActionResult Create(CategoryViewModel 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(model.MagazineId, user.UserId);

            if (!relation)
            {
                SetMessage("Lo sentimos, no tienes permisos para visualizar este contenido.", BootstrapAlertTypes.Danger);
                return(RedirectToAction("Index", "Magazines"));
            }

            if (!ModelState.IsValid)
            {
                SetMessage("Lo sentimos, favor de verificar los datos.", BootstrapAlertTypes.Danger);
                return(View(model));
            }

            var imageCode = "Expose_Default_Category.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.CreateCategory(model.Name, model.Permalink, imageCode, model.MagazineId, model.Width, model.Height, model.ParentCategoryId, model.showImage);

            if (create == null)
            {
                SetMessage("Lo sentimos, ha ocurrido un error al crear categoría.", BootstrapAlertTypes.Danger);
                return(RedirectToAction("Index", "Categories"));
            }

            SetMessage("Listo, categoría creada.", BootstrapAlertTypes.Success);
            return(RedirectToAction("Index", "Categories"));
        }
Exemplo n.º 2
0
        public ActionResult CreateCategory(CategoryViewModel 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 user     = UserService.GetCurrentUser();
            var relation = UserService.UserInMagazine(model.MagazineId, user.UserId);

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

            var imageCode = "Expose_Default_Category.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.CreateCategory(model.Name, model.Permalink, imageCode, model.MagazineId, model.Width, model.Height, null, model.showImage);

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