public ActionResult Create(AdvertiseViewModel model) { if (Request.Cookies["MagazineId"].Value == null) { SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines")); } if (!UserService.UserInMagazine(int.Parse(Request.Cookies["MagazineId"].Value), UserService.GetCurrentUser().UserId)) { return(RedirectToAction("Index", "Magazines")); } if (!ModelState.IsValid) { SetMessage("Lo sentimos, favor de verificar los datos. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(View(model)); } var imageCode = "Expose_Default_New.jpg"; 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.CreateAd(model, imageCode, null); if (!create) { SetMessage("Ocurrió un error inesperado. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(View(model)); } SetMessage("Anuncio creado exitosamente", BootstrapAlertTypes.Success); return(RedirectToAction("Index", new { id = model.AdCategoryId })); }