public FileContentResult GetGalleryPhoto(int id) { var item = _gRepo.GetGallery(id); if (item != null) { return(File(item.GalleryData, item.GalleryMimeType)); } else { return(null); } }
public ActionResult Inscreaser(int type = 0, string folder = null, int id = 0, string selector = null, string jsonData = null) { ViewBag.result = 0; ViewBag.el = 0; if (type == 3 && folder != null) // ПАПКА { var path = Server.MapPath("~" + folder); var dir = new DirectoryInfo(path); var result = dir.GetFiles().Select(x => string.Concat(folder, x.Name)).ToList(); var json = JsonConvert.SerializeObject(result); //var formated =json; //var path1 = Server.MapPath("~/data.json"); //using (StreamWriter file = new StreamWriter(path1)) //{ // JsonSerializer serializer = new JsonSerializer(); // serializer.Serialize(file, formated); //} ViewBag.result = json; } else if (type == 2 && id != 0) // ГАЛЛЕРЕЯ { var result = _grep.GetGallery(id).Images.Select(x => x.ID).ToList(); var json = JsonConvert.SerializeObject(result); ViewBag.result = json; } else if (type == 1 && id != 0) // КАТАЛОГ { var item = _prep.Get(id); item.VisitesCount++; _prep.Save(); var cart = Session["Cart"] as Cart; var isAdded = cart != null?cart.Lines.Select(x => x.Product.ID).Contains(id) : false; JObject result = new JObject { { "id", id }, { "cat", ProductController.GetCatName(item.CategoryID) }, { "name", item.ProductName }, { "added", isAdded }, { "desc", item.Description }, { "mat", item.Material }, { "pack", item.Packaging }, { "fill", item.Fill }, { "packsize", item.PackagingSize }, { "weight", item.Weight }, { "manufacturer", item.Manufacturer }, { "disc", item.Discount }, { "size", item.Size }, { "si", new JArray { item.ProdImages.OrderByDescending(x => x.Sortindex).Select(x => new JObject { new JProperty("id", x.ID), new JProperty("src", x.ImageMimeType) }).ToArray() } }, { "price", item.Price.ToString("N", System.Globalization.CultureInfo.CreateSpecificCulture("ru")).Replace(",00", "") } }; var json = result.ToString(); ViewBag.result = json; ViewBag.Prod = item; } else // КОНТЕНТ { if (jsonData != null) { var obj = JObject.Parse(jsonData); ViewBag.el = obj["el"]; ViewBag.result = obj["pack"]; return(Json("", JsonRequestBehavior.AllowGet)); } } ViewBag.type = type; ViewBag.folder = folder; ViewBag.selector = selector; return(PartialView()); }
public void GetPhotoGalleryImage(int id, int width = 0, int height = 0, bool isGallery = true) { if (!isGallery) { var item = _gRep.GetImage(id); if (item.ImageData != null && width > 0) { //var halfHeight = height; //var halfWidth = width; //if (width > 1280) //{ // halfHeight = new WebImage(item.ImageData).Height / 2; // halfWidth = new WebImage(item.ImageData).Width / 2; //} //var fileExt = new WebImage(item.ImageData).ImageFormat; new WebImage(item.ImageData) .Resize(width, height, true, true) // Resizing the image to 100x100 px on the fly... .Crop(1, 1) // Cropping it to remove 1px border at top and left sides (bug in WebImage) .Write(); } else if (width == 0 && height == 0 && item.ImageData != null) { new WebImage(item.ImageData) .Resize(800, 600) // Resizing the image to 100x100 px on the fly... .Crop(1, 1) // Cropping it to remove 1px border at top and left sides (bug in WebImage) .Write(); } else { //var file = new FileInfo(Server.MapPath("/Content/main-images/photouser1.jpg")); new WebImage(Server.MapPath("/Content/main-images/photouser1.jpg")).Resize(width, height, false, true).Crop(1, 1).Write(); } } else { var item = _gRep.GetGallery(id); if (item.GalleryData != null) { if (width == 0) { new WebImage(item.GalleryData) .Crop(1, 1).Write(); } else { var halfHeight = height; var halfWidth = width; //if (width > 1600) //{ // halfHeight = new WebImage(item.GalleryData).Height / 2; // halfWidth = new WebImage(item.GalleryData).Width / 2; //} var fileExt = new WebImage(item.GalleryData).ImageFormat; var img = new WebImage(item.GalleryData) .Resize(halfWidth, halfHeight, false, false) // Resizing the image to 100x100 px on the fly... .Crop(1, 1) // Cropping it to remove 1px border at top and left sides (bug in WebImage) .Write(); } } else { //var file = new FileInfo(Server.MapPath("/Content/main-images/photouser1.jpg")); new WebImage(item.GalleryData) .Crop(1, 1).Write(); } } }