// GET: Products/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Product product = db.Products.Find(id); if (product == null) { return(HttpNotFound()); } ProductImages productImage = new ProductImages { ImageId = product.Id, Name = product.Name }; productImage.ImageId = product.Id; productImage.Name = product.Name; string imagePath = "~/ProductImages/" + "stockPhoto" + product.Id + ".png"; try { productImage.Image = imagePath; } catch { productImage.Image = "~/ProductImages/yourPhotoHere.jpg"; } return(View(product)); }
public ActionResult DeleteProductImage(int?id) { try { ProductImages img = db.ProductImages.Find(id); if (System.IO.File.Exists(Server.MapPath(img.ImagePath))) { System.IO.File.Delete(Server.MapPath(img.ImagePath)); } if (System.IO.File.Exists(Server.MapPath(img.ImagePath.Replace("uploads/Products/OS", "uploads/Products/L")))) { System.IO.File.Delete(Server.MapPath(img.ImagePath.Replace("uploads/Products/OS", "uploads/Products/L"))); } if (System.IO.File.Exists(Server.MapPath(img.ImagePath.Replace("uploads/Products/OS", "uploads/Products/S")))) { System.IO.File.Delete(Server.MapPath(img.ImagePath.Replace("uploads/Products/OS", "uploads/Products/S"))); } db.ProductImages.Remove(img); db.SaveChanges(); } catch (Exception) { return(Json("-1", JsonRequestBehavior.AllowGet)); } return(Json("1", JsonRequestBehavior.AllowGet)); }
public ProductImages AddProductImages(ProductImages request) { var command = dbContext.CreateCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "sp_ProductImages_i"; command.AddParameter("@Description", request.Description, DbType.String); command.AddParameter("@IsDisplay", request.IsDisplay, DbType.Boolean); command.AddParameter("@DisplayOrder", request.DisplayOrder, DbType.Int32); command.AddParameter("@ImageName", request.ImageName, DbType.String); command.AddParameter("@ImagePath", request.ImagePath, DbType.String); command.AddParameter("@ThumbnailPath", request.ThumbnailPath, DbType.String); try { command.OpenConnection(); var reader = command.OpenReader(); while (reader.Read()) { request.RowId = reader.ValidateColumnExistExtractAndCastTo <int>("RowId"); } ; } finally { command.CloseConnection(); } return(request); }
// Use this for initialization void Start() { buttonComponent.onClick.AddListener(HandleClick); buttonController = controller.GetComponent <ProductButtonController>(); images = controller.GetComponent <ProductImages>(); myProdId = -1; }
async Task ExecuteRefreshCommand() { if (IsBusy) { return; } IsBusy = true; try { var productImages = await _service.GetProductImageByProductId(_item.Id); ProductImages.Clear(); foreach (var pr in productImages) { ProductImages.Add(pr); } } catch (Exception ex) { Acr.UserDialogs.UserDialogs.Instance.ShowError(ex.Message); } finally { IsBusy = false; } }
public async Task <ActionResult> Edit([Bind(Include = "ProductID,ProductCode,ProductName,ShortDescription,LongDescription,Quantity,MSRP,Price,WildmanPrice,Length,Width,Height,ParcelPost,InactiveProduct,NoBackOrders,LimitOne,New,KeepInventory,SpecialOrder,FeaturedProduct,ClassID")] Product product, HttpPostedFileBase[] files, string returnUrl) { for (int i = 0; i < files.Length; i++) { if (files[i] != null && files[i].ContentLength > 0) { var extension = Path.GetExtension(files[i].FileName); if (extension != ".png" && extension != ".jpg" && extension != ".jpeg") { ViewBag.Message = "One or more files has an invalid file extension"; return(View(product)); } } } if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; await db.SaveChangesAsync(); for (int i = 0; i < files.Length; i++) { if (files[i] != null && files[i].ContentLength > 0) { var fileName = Path.GetFileName(files[i].FileName); path = Path.Combine(Server.MapPath("~/images"), fileName); ProductImages image = new ProductImages(); image.Path = "~/images/" + fileName; image.ProductID = product.ProductID; image.Featured = false; files[i].SaveAs(path); if (i == 0) { /*Ensure that at least one image is set as featured*/ ProductImages images = ModelLists.ProductImages.Where(x => x.ProductID == product.ProductID && x.Featured == true).OrderByDescending(x => x.Featured).SingleOrDefault(); if (images == null) { image.Featured = true; } } db.ProductImages.Add(image); await db.SaveChangesAsync(); } } ModelLists.NewModelList(); HierarchicalModelLists.NewHierarchicalModelLists(); if (product.InactiveProduct) { return(RedirectToAction("Index")); } if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Edit(int?id) { EditProduct editProduct; if (id.HasValue) { editProduct = Mapper.Map <EditProduct>(Products.GetByID(id.Value)); editProduct.Text = HttpUtility.HtmlDecode(editProduct.Text); editProduct.GroupUrlPerfix = Groups.GetByID(editProduct.GroupID.Value).UrlPerfix; editProduct.Groups = ProductGroups.GetByProductID(editProduct.ID).Select(item => item.GroupID).ToList(); editProduct.Images = ProductImages.GetByProductID(editProduct.ID); editProduct.Files = ProductFiles.GetByProductID(editProduct.ID); editProduct.Marks = ProductMarks.GetByProductID(editProduct.ID); editProduct.Points = ProductPoints.GetByProductID(editProduct.ID); editProduct.Keywords = ProductKeywords.GetByProductID(editProduct.ID); editProduct.Notes = ProductNotes.GetByProductID(editProduct.ID); editProduct.ProductPricesLinks = ProductPricesLinks.GetByProductID(editProduct.ID); editProduct.Supplies = ProductSupplies.GetByProductID(editProduct.ID); editProduct.Prices = ProductPrices.GetByProductID(editProduct.ID); editProduct.Varients = ProductVarients.GetByProductID(editProduct.ID); editProduct.Discounts = ProductDiscounts.GetAllByProductID(editProduct.ID); } else { editProduct = new EditProduct(); editProduct.userID = UserID; } return(View(editProduct)); }
private static void SaveImages(EditProduct editProduct, int productID) { var curList = ProductImages.GetByProductID(productID); foreach (var image in editProduct.Images) { if (!curList.Any(item => item.ID == image.ID)) { var productImage = Mapper.Map <ProductImage>(image); productImage.ProductID = productID; ProductImages.Insert(productImage); } else { ProductImages.UpdateProductImagePlace(image.ID, image.ProductImagePlace); curList.Remove(curList.Single(cls => cls.ID == image.ID)); } } foreach (var item in curList) { ProductImages.Delete(item.ID); } }
public ActionResult Create(ProductInfo pro) { if (ModelState.IsValid) { ProductInfo product = new ProductInfo(); if (pro.ColorId != null) { product.ColorId = pro.ColorId; } product.Price = pro.Price; if (pro.SizeId != null) { product.SizeId = pro.SizeId; } product.SalePercent = pro.SalePercent; if (pro.SaleBannerId != null) { product.SaleBannerId = pro.SaleBannerId; } product.ProductId = pro.ProductId; product.isTopSelling = pro.isTopSelling; product.isNew = pro.isNew; product.Quantity = pro.Quantity; product.CreateDate = DateTime.Now; db.ProductInfos.Add(product); db.SaveChanges(); foreach (HttpPostedFileBase image in pro.ImageFile) { string imgName = DateTime.Now.ToString("ddMMyyyyHHmmssfff") + image.FileName; string imgPath = Path.Combine(Server.MapPath("~/Uploads/Product/"), imgName); image.SaveAs(imgPath); ProductImages img = new ProductImages(); img.Name = imgName; img.ProductInfoId = product.Id; db.ProductImages.Add(img); db.SaveChanges(); } for (int i = 0; i < pro.SizeOptKey.Length; i++) { SizeOption option = new SizeOption(); option.productInfoId = product.Id; option.Key = pro.SizeOptKey[i]; option.Value = pro.SizeOptValue[i]; db.SizeOption.Add(option); db.SaveChanges(); } return(RedirectToAction("Index")); } ViewBag.Product = db.Product.ToList(); ViewBag.Color = db.Colors.ToList(); ViewBag.Size = db.Size.ToList(); ViewBag.Sale = db.SaleBanner.ToList(); return(View(pro)); }
private void ImgDragEnter(object sender, DragEventArgs e) { Image Img = (Image)e.Source; int WhereToDrop = imgPanel.Children.IndexOf(Img); int StartLocation = imgPanel.Children.IndexOf(Image_To_Drag); imgPanel.Children.Remove(Image_To_Drag); imgPanel.Children.Insert(WhereToDrop, Image_To_Drag); foreach (var item in imgPanel.Children) { Image image = item as Image; image.Height = imgPanel.Children.IndexOf(image) != 0 ? DefaultHeight : FirstImageHeight; image.Width = imgPanel.Children.IndexOf(image) != 0 ? DefaultWidth : FirstImageWidth; } ProductImages temporary = Model.Images.Single(x => x.ImageOrder == StartLocation); ProductImages temporary2 = Model.Images.Single(x => x.ImageOrder == WhereToDrop); temporary.ImageOrder = WhereToDrop; temporary2.ImageOrder = StartLocation; Model.Images = Model.Images.OrderBy(x => x.ImageOrder).ToList(); }
public void Delete(int productImagesId) { ProductImages productImages = GetById(productImagesId); _productImagesRepository.Delete(productImages); _unitOfWork.Complete(); }
internal void Apply(ImageAddedEvent @event) { var image = new ProductImage(); image.Route(@event); ProductImages.Add(image); }
public ActionResult Update(ProductImages model) { if (ModelState.IsValid) { var obj = ServiceFactory.ImageProductManager.Get(new ProductImages { ProductImageId = model.ProductImageId }); if (obj != null) { try { ServiceFactory.ImageProductManager.Update(model, obj); return(RedirectToAction("Search", "ImageProduct")); } catch (Exception ex) { //throw; } } } var categories = ServiceFactory.ProductManager.ProductGetAllActive(Culture); ViewBag.Categories = new SelectList(categories, "ProductId", "HlevelTitle"); ViewBag.IsEdit = true; return(View(model)); }
public ActionResult Create() { ProductImages data = new ProductImages(); var categories = ServiceFactory.ProductManager.ProductGetAllActive(Culture); ViewBag.Categories = new SelectList(categories, "ProductId", "HlevelTitle"); return(View("Update", data)); }
public static ProductImagesWM MaptoWM(ProductImages entity) { return(new ProductImagesWM() { ProductImageID = entity.ProductImageID, ProductPicture = entity.ProductPicture }); }
public ActionResult SaveEditedProduct(EditProductViewModel model) { var proDB = _unitOfWork.Product.GetProductById(model.Id); List <ProductImages> images = new List <ProductImages>(); var pathToSave = _unitOfWork.ProductImage.GetProductImageByProductId(model.Id).FilePath; var path = "~/" + pathToSave; var imgPath = ""; for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0 && HttpPostedFileBaseExtensions.IsImage(file)) { var fileName = Path.GetFileName(file.FileName); ProductImages fileDetail = new ProductImages() { FileName = fileName, Extension = Path.GetExtension(fileName), FileNameNoExt = Path.GetFileNameWithoutExtension(fileName), FilePath = pathToSave }; images.Add(fileDetail); imgPath = Path.Combine(Server.MapPath(path), fileDetail.FileName); file.SaveAs(imgPath); } } var newImages = proDB.Images.Concat(images).ToList(); var PdfPathToSave = ""; if (model.document != null && model.document.ContentLength > 0) { string folderDate = DateTime.Now.ToString("yyyyMMddHHmmss"); Directory.CreateDirectory(Server.MapPath("~/DynamicContent/ProductPDFs/Product" + folderDate)); var PdfPath = Path.Combine(Server.MapPath("~/DynamicContent/ProductPDFs/Product" + folderDate), model.document.FileName); PdfPathToSave = "DynamicContent/ProductPDFs/Product" + folderDate; model.document.SaveAs(PdfPath); proDB.DocumentPath = PdfPathToSave; proDB.DocumentName = model.document.FileName; } proDB.Images = newImages; proDB.isActive = model.isActive; proDB.Name = model.Name; proDB.Subtitle = model.Subtitle; proDB.Text = model.Text; proDB.Price = model.Price; proDB.MetaDescription = model.MetaDescription; proDB.MetaKeywords = model.MetaKeywords; _unitOfWork.Complete(); return(RedirectToAction("EditProduct", new { id = model.Id })); }
public IActionResult Add(ProductViewModel productViewModel) { if (ModelState.IsValid) { var productIsValid = _productServices.GetByName(productViewModel.product.Name); if (productIsValid != null) { return(RedirectToAction("GetProducts")); } var NewProduct = new Product { Name = productViewModel.product.Name, AddedBy = "iso", AddedDate = DateTime.Now, Explanation = productViewModel.product.Explanation, CategoryId = productViewModel.product.CategoryId, Height = productViewModel.product.Height, Weight = productViewModel.product.Weight, Width = productViewModel.product.Width }; try { var AddedProduct = _productServices.Add(NewProduct); if (productViewModel.FormFiles != null) { foreach (var image in productViewModel.FormFiles) { var uniqFileName = Guid.NewGuid().ToString() + "_" + image.FileName; var FilePath = Path.DirectorySeparatorChar.ToString() + "ProductImages" + Path.DirectorySeparatorChar.ToString() + uniqFileName; var uploadsFolder = Path.Combine(_env.WebRootPath, "ProductImages"); var filePathCopy = Path.Combine(uploadsFolder, uniqFileName); image.CopyTo(new FileStream(filePathCopy, FileMode.Create)); var ProductImageForAdd = new ProductImages { AddedBy = "iso", AddedDate = DateTime.Now, FileName = uniqFileName, FilePath = FilePath, ProductId = AddedProduct.Id }; _productImageServices.Add(ProductImageForAdd); } } return(RedirectToAction("GetProducts")); } catch (Exception ex) { return(RedirectToAction("GetProducts")); } } return(RedirectToAction("GetProducts")); }
public IActionResult UpdateImage(string ImageName, string ModuleName, int RowId) { var response = new OperationResponse <ProductImages>(); try { string OriginalImagePath = _configuration["ImagePathConfiguration:OriginalImagePath"]; string ThumbnailImagePath = _configuration["ImagePathConfiguration:ThumbnailImagePath"]; if (Request.Form.Files.Count > 0) { var file = Request.Form.Files[0]; var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), OriginalImagePath); var fullPath = Path.Combine(pathToSave, ImageName); if (System.IO.File.Exists(fullPath)) { ImageCompressHelper.CompressImage(OriginalImagePath, ThumbnailImagePath, file, ImageName); } else { int MaxId = _productImageService.GetMaxProductImageId(); var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fileExt = fileName.Remove(0, fileName.LastIndexOf('.')); fileName = (MaxId + 1).ToString() + fileExt; ImageCompressHelper.CompressImage(OriginalImagePath, ThumbnailImagePath, file, fileName); ProductImages request = new ProductImages(); request.ImageName = fileName; request.ImagePath = Path.Combine(OriginalImagePath, fileName); request.ThumbnailPath = Path.Combine(ThumbnailImagePath, fileName); request.Description = ""; request.DisplayOrder = 1; request.IsDisplay = true; response.Data = _productImageService.AddProductImages(request); // Update Image in Module as well _productImageService.UpdateImage(request.RowId, ModuleName, RowId); } } else { response.Messages.Add("Please upload Image"); } } catch (Exception exception) { response.State = ResponseState.Error; response.Messages.Add(exception.Message); _logger.LogError(exception, "Error in UpdateImage ==>" + exception.StackTrace); } return(new JsonResult(response)); }
public IActionResult UploadMultipleFiles(int ProductId) { var response = new OperationResponse <ProductImages>(); try { if (Request.Form.ContainsKey("ProductId")) { ProductId = Convert.ToInt32(Request.Form["ProductId"].ToString()); } if (Request.Form.Files.Count > 0) { foreach (var item in Request.Form.Files) { int MaxId = _productImageService.GetMaxProductImageId(); var file = item; string OriginalImagePath = _configuration["ImagePathConfiguration:OriginalImagePath"]; string ThumbnailImagePath = _configuration["ImagePathConfiguration:ThumbnailImagePath"]; var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fileExt = fileName.Remove(0, fileName.LastIndexOf('.')); fileName = (MaxId + 1).ToString() + fileExt; ImageCompressHelper.CompressImage(OriginalImagePath, ThumbnailImagePath, file, fileName); ProductImages request = new ProductImages(); request.ImageName = fileName; request.ImagePath = Path.Combine(OriginalImagePath, fileName); request.ThumbnailPath = Path.Combine(ThumbnailImagePath, fileName); request.Description = ""; request.DisplayOrder = 1; request.IsDisplay = true; response.Data = _productImageService.AddProductImages(request); ProductImageProduct request2 = new ProductImageProduct(); request2.ProductId = Convert.ToInt32(ProductId); request2.ProductImageId = response.Data.RowId; _productImageService.AddProductImage_Product(request2); } } else { response.Messages.Add("Please upload Image"); } } catch (Exception exception) { response.State = ResponseState.Error; response.Messages.Add(exception.Message); } return(new JsonResult(response)); }
public override string ToString() { var message = "Product Name = " + ProductName + " Product Code = " + ProductCode + " with ID " + Id; if ((ProductImages != null) && ProductImages.Any()) { message += " Total Photos " + ProductImages.Count(); } return(message); }
public ProductResponse(Product prd, HttpRequest req) { Product_ID = prd.Product_ID; Category = prd.Category; StichingType = prd.StichingType; Fabric = prd.Fabric; StichingType = prd.StichingType; Description = prd.Description; Cost_Price = prd.Cost_Price; AddTime = prd.AddTime; CustomerMarginRupees = prd.CustomerMarginRupees; CustomerShippingCost = prd.CustomerShippingCost; TraderMarginRupees = prd.TraderMarginRupees; VendorShippingCost = prd.VendorShippingCost; Cost_Price = prd.Cost_Price; IsActive = prd.IsActive; ProductImageDir = prd.ProductImageDir; UpdateTime = prd.UpdateTime; Vendor = prd.Vendor; AddDate = prd.AddDate; UpdateDate = prd.UpdateDate; CustomerPrice = prd.CustomerPrice; TraderPrice = prd.TraderPrice; prdDesignRes = new List <ProductDesignResponse>(); Image_Urls = new List <ProductImagesRespose>(); foreach (ProductImages PrdDesign in prd.product_images) { ProductImages PrdImg = PrdDesign; Image_Urls.Add(new ProductImagesRespose() { id = PrdImg.id, url = String.Format("{0}://{1}{2}/images/{3}/{4}", req.Scheme, req.Host, req.PathBase, PrdImg.folderName + "/" + "watermark", Path.GetFileName(PrdImg.Physicalurl)) }); } foreach (ProductDesign PrdDes in prd.productDesign) { List <ProductImagesRespose> p = new List <ProductImagesRespose>(); if (PrdDes.product_design_images.Count() > 0) { p = (List <ProductImagesRespose>)(from pop in PrdDes.product_design_images select new ProductImagesRespose() { id = pop.ProductImagesId, url = String.Format("{0}://{1}{2}/images/{3}/{4}", req.Scheme, req.Host, req.PathBase, pop.ProductImage.folderName + "/" + "watermark", Path.GetFileName(pop.ProductImage.Physicalurl)) }).ToList(); } prdDesignRes.Add(new ProductDesignResponse() { Id = PrdDes.Id, productColor = PrdDes.productColor, productSize = PrdDes.productSize, Quantity = PrdDes.Quantity, Image_Urls = p }); } }
public void Remove(ProductImages item) { var comm = this.GetCommand("sp_Images_Delete"); if (comm == null) { return; } comm.AddParameter <int>(this.Factory, "ProductImageId", item.ProductImageId); comm.SafeExecuteNonQuery(); }
public async Task <IActionResult> AddProduct([FromForm] List <IFormFile> files, [FromForm] string product) { if (!ModelState.IsValid) { return(Ok(new Response { IsError = true, Status = 400, Message = "Sai dữ liệu đầu vào" })); } Products products = JsonConvert.DeserializeObject <Products>(product); products.CreateAt = DateTime.Now; products.Discontinued = true; products.DisplayIndex = false; products.Stock = 0; products.UnitPrice = 0; _context.Products.Add(products); var imageList = await Files.UploadAsync(files, _environment.ContentRootPath); //upload image foreach (var image in imageList) { var productImages = new ProductImages { ProductId = products.ProductId, Url = image, IsThumbnail = true, CreateAt = DateTime.Now }; await _context.ProductImages.AddAsync(productImages); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(Ok(new Response { IsError = true, Status = 409, Message = "Không thể lưu dữ liệu" })); } return(Ok(new Response { Status = 201 })); }
public void AddImage(string url, int order) { if (ProductImages.Any(x => x.ShowOrder == order)) { throw new BusinessException($"Image order already defined for Product:{Id}"); } RaiseEvent( ProductImage.ImageAddedToProduct(this, url, order) ); }
public IActionResult UploadMultipleFiles(int ProductId) { var response = new OperationResponse <ProductImages>(); try { if (Request.Form.Files.Count > 0) { foreach (var item in Request.Form.Files) { int MaxId = _productImageService.GetMaxProductImageId(); var file = item; string OriginalImagePath = _configuration["ImagePathConfiguration:OriginalImagePath"]; string ThumbnailImagePath = _configuration["ImagePathConfiguration:ThumbnailImagePath"]; var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fileExt = fileName.Remove(0, fileName.LastIndexOf('.')); fileName = (MaxId + 1).ToString() + fileExt; ImageCompressHelper.CompressImage(OriginalImagePath, ThumbnailImagePath, file, fileName); //var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), "Resources"); //var fullPath = Path.Combine(pathToSave, fileName); //using (var stream = new FileStream(fullPath, FileMode.Create)) //{ // file.CopyTo(stream); //} ProductImages request = new ProductImages(); request.ImageName = fileName; request.ImagePath = Path.Combine(OriginalImagePath, fileName); request.ThumbnailPath = Path.Combine(ThumbnailImagePath, fileName); request.Description = ""; request.DisplayOrder = 1; request.IsDisplay = true; response.Data = _productImageService.AddProductImages(request); } } else { response.Messages.Add("Please upload Image"); } } catch (Exception exception) { response.State = ResponseState.Error; response.Messages.Add(exception.Message); _logger.LogError(exception, "Error in AddProductCategory ==>" + exception.StackTrace); } return(new JsonResult(response)); }
public virtual void AddProductImage(Image image, int position) { var productImage = new ProductImage { Image = image, Position = position, Product = this }; image.ProductImages.Add(productImage); ProductImages.Add(productImage); }
public void SetProductImages(List <ProductImage> productImages, string imageUrlPattern) { // first set default product image Product.DefaultImage = GetImageUrl(Product.DefaultImage, imageUrlPattern); // now set optional images if (productImages.Any()) { ProductImages = productImages.Where(p => p.ProductId == Product.ProductId).ToList(); ProductImages.ForEach(i => i.Image = GetImageUrl(i.Image, imageUrlPattern)); } }
public void DeleteProductImage(ProductImages entity) { try { _uow.ProductImages.Remove(entity); _uow.Complete(); } catch (Exception ex) { throw new Exception(ex.ToString()); } }
public ActionResult ImagesRemove(int id) { ProductImages productImages = db.ProductImageses.FirstOrDefault(x => x.Id == id); if (System.IO.File.Exists(Server.MapPath(productImages.ImagesUrl))) { System.IO.File.Delete(Server.MapPath(productImages.ImagesUrl)); } db.ProductImageses.Remove(productImages); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult ImageUpload() { var User = Session["AdminLoginUser"] as User; int pid = Convert.ToInt16(Request.UrlReferrer.Segments[4]); bool isSavedSuccessfully = true; string fName = ""; try { foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName]; fName = file.FileName; if (file != null && file.ContentLength > 0) { //var path = Path.Combine(Server.MapPath("~/MyImages")); //string pathString = System.IO.Path.Combine(path.ToString()); //bool isExists = System.IO.Directory.Exists(pathString); //if (!isExists) System.IO.Directory.CreateDirectory(pathString); //var uploadpath = string.Format("{0}\\{1}", pathString, file.FileName); //file.SaveAs(uploadpath); ProductImages productImages = new ProductImages(); productImages.ProductId = pid; productImages.CreateDateTime = DateTime.Now; productImages.CreateUserId = User.Id; productImages.ImagesUrl = _functions.ImageUpload(file, 300, "~/Content/Images/Products/"); productImages.ImagesUrl = _functions.ImageUpload(file, 900, "~/Content/Images/Products/Great/"); db.ProductImageses.Add(productImages); } } db.SaveChanges(); } catch (Exception ex) { isSavedSuccessfully = false; } if (isSavedSuccessfully) { return(Json(new { Message = fName })); } else { return(Json(new { Message = "Error in saving file" })); } }