public ActionResult ProductPictureAdd(int pictureId, int displayOrder, string AltAttribute, string TitleAttribute, int productId) { if (pictureId == 0) { throw new ArgumentException(nameof(pictureId)); } var product = new ProductDao().GetProductById(productId); if (product == null) { throw new ArgumentNullException(); } var picture = new PictureDao().GetPictureById(pictureId); if (picture == null) { throw new ArgumentNullException(nameof(pictureId)); } picture.AltAttribute = AltAttribute; picture.TitleAttribute = TitleAttribute; picture.SeoFilename = product.MetaKeywords; var result = new PictureDao().UpdatePicture(picture); var productPictureMaping = new Product_Picture_Mapping { ProductId = product.Id, PictureId = picture.Id, DisplayOrder = displayOrder }; int Id = new Product_Picture_MappingDao().InsertProductPictureMapping(productPictureMaping); if (Id > 0) { return(Json(new { Result = true })); } else { return(Json(new { Result = false })); } }
public ActionResult PictureAdd(int PictureId, bool Visible, int DisplayOrder, string Url, string AltAttribute, string TitleAttribute, int SliderId) { if (PictureId == 0) { throw new ArgumentException(nameof(PictureId)); } var anywhereSlider = new AnywhereSliderDao().GetAnywhereSliderById(SliderId); if (anywhereSlider == null) { throw new ArgumentNullException(); } var picture = new PictureDao().GetPictureById(PictureId); if (picture == null) { throw new ArgumentNullException(nameof(PictureId)); } picture.AltAttribute = AltAttribute; picture.TitleAttribute = TitleAttribute; var result = new PictureDao().UpdatePicture(picture); var sliderImage = new SliderImage { DisplayText = TitleAttribute, Alt = AltAttribute, Url = Url, Visible = Visible, DisplayOrder = DisplayOrder, PictureId = picture.Id, SliderId = SliderId }; int Id = new SliderImageDao().InsertSliderImage(sliderImage); return(Json(new { Result = true })); }
public JsonResult AsyncUpload() { //if (!_permissionService.Authorize(StandardPermissionProvider.UploadPictures)) // return Json(new { success = false, error = "You do not have required permissions" }, "text/plain"); if (Request.Files.Count == 0) { return(Json(new { success = false, message = "No file uploaded", downloadGuid = Guid.Empty, })); } var httpPostedFile = Request.Files[0]; var fileName = httpPostedFile.FileName; fileName = Path.GetFileName(fileName); var contentType = httpPostedFile.ContentType; var fileExtension = Path.GetExtension(fileName); if (!string.IsNullOrEmpty(fileExtension)) { fileExtension = fileExtension.ToLowerInvariant(); } string path = Path.Combine(Server.MapPath("~/Uploads/images/"), fileName); httpPostedFile.SaveAs(path); byte[] fileBinary = null; using (var binaryReader = new BinaryReader(Request.Files[0].InputStream)) { fileBinary = binaryReader.ReadBytes(Request.Files[0].ContentLength); } //contentType is not always available //that's why we manually update it here //http://www.sfsu.edu/training/mimetype.htm if (string.IsNullOrEmpty(contentType)) { switch (fileExtension) { case ".bmp": contentType = MimeTypes.ImageBmp; break; case ".gif": contentType = MimeTypes.ImageGif; break; case ".jpeg": case ".jpg": case ".jpe": case ".jfif": case ".pjpeg": case ".pjp": contentType = MimeTypes.ImageJpeg; break; case ".png": contentType = MimeTypes.ImagePng; break; case ".tiff": case ".tif": contentType = MimeTypes.ImageTiff; break; default: break; } } var picture = new PictureDao().InsertPicture(fileBinary, contentType, null); //when returning JSON the mime-type must be set to text/plain //otherwise some browsers will pop-up a "Save As" dialog. return(Json(new { success = true, pictureId = picture.Id, imageUrl = "/Uploads/images/" + fileName, })); }
// GET: Admin/Picture public ActionResult Index() { PictureDao dao = new PictureDao(); return(View(dao.ListPicture())); }
public ActionResult DisplayPicture(int Id) { var picture = new PictureDao().GetPictureById(Id); return(File(picture.PictureBinary, picture.MimeType)); }