public ActionResult Images(GaleryImage model, Int32 isAnEdit) { Boolean forEdit = false; if (isAnEdit == 1) { forEdit = true; } if (!GaleryService.AddImageToGalery(model, forEdit)) { SetMessage("Lo sentimos, no hemos podido agregar la imagen a la galería. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(View(model)); } return(RedirectToAction("Images", new { id = model.GaleryId })); }
public ActionResult UploadImagesToGallery(Int32 id) { var getGallery = GaleryService.GetGallery(id); bool isSavedSuccessfully = true; string fName = ""; try { foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName]; //Save file content goes here fName = file.FileName; if (file != null && file.ContentLength > 0) { var originalDirectory = new DirectoryInfo(string.Format("{0}\\Content\\Data", Server.MapPath(@"\"))); string pathString = System.IO.Path.Combine(originalDirectory.ToString(), ""); var fileName1 = Path.GetFileName(file.FileName); bool isExists = System.IO.Directory.Exists(pathString); if (!isExists) { System.IO.Directory.CreateDirectory(pathString); } var path = string.Format("{0}\\{1}", pathString, file.FileName); file.SaveAs(path); var IP = Request.UserHostAddress; var saveImage = GaleryService.SaveImage(getGallery.Alt, file.FileName, getGallery.Title, IP); var newModel = new GaleryImage() { CreationDate = saveImage.UploadDate, ImageId = saveImage.ImageId, GaleryId = id, Description = getGallery.Description, Title = getGallery.Title, Order = 1, }; var SaveImageInGallery = GaleryService.AddImageToGalery(newModel, false); } } } catch (Exception ex) { isSavedSuccessfully = false; } if (isSavedSuccessfully) { return(Json(new { Message = fName })); } else { return(Json(new { Message = "Error in saving file" })); } }