public ActionResult Edit(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(magId, 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)); } ViewBag.MagazineId = new SelectList(MagazineService.GetCurrentUserMagazines(), "MagazineId", "Title", model.MagazineId); var imageCode = model.LogoImage; 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; } if (!MagazineService.EditCategory(model.CategoryId, model.Name, model.Permalink, imageCode, model.MagazineId)) { SetMessage(MagazineService.ServiceTempData); SetMessage("Lo sentimos, ha ocurrido un error al editar categoría.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Categories")); } SetMessage("Listo, categoría editada.", BootstrapAlertTypes.Success); return(RedirectToAction("Index", "Categories")); }