public ActionResult CustomCreate(FormCollection form, HttpPostedFileBase files) { using (var context = new SiteContainer()) { if (files!=null) { var product = new Product(); TryUpdateModel(product, new[] { "SortOrder"}); product.Description = HttpUtility.HtmlDecode(form["Description"]); string fileName = IOHelper.GetUniqueFileName("~/Content/Images", files.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); GraphicsHelper.SaveOriginalImage(filePath, fileName, files, 1200); product.ImageSource = fileName; fileName = IOHelper.GetUniqueFileName("~/Content/Images", files.FileName); filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); int x1 = Convert.ToInt32(form["x1"]); int y1 = Convert.ToInt32(form["y1"]); int w = Convert.ToInt32(form["w"]); int h = Convert.ToInt32(form["h"]); GraphicsHelper.SaveCropPreview(filePath, fileName, files, x1, y1, w, h); product.PreviewImageSource = fileName; context.AddToProduct(product); context.SaveChanges(); } } return RedirectToAction("Index", "Home", new { area = "", id = "gallery" }); }
public ActionResult Create(FormCollection collection, HttpPostedFileBase fileUpload, HttpPostedFileBase previewFileUpload) { using (var context = new SiteContainer()) { if (fileUpload != null && previewFileUpload != null) { var product = new Product(); TryUpdateModel(product, new[] { "SortOrder" }); product.Description = HttpUtility.HtmlDecode(collection["Description"]); string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload, 500); product.ImageSource = fileName; fileName = IOHelper.GetUniqueFileName("~/Content/Images", previewFileUpload.FileName); filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); GraphicsHelper.SaveOriginalImage(filePath, fileName, previewFileUpload, 500); product.PreviewImageSource = fileName; context.AddToProduct(product); context.SaveChanges(); } return RedirectToAction("Index", "Home", new { area = "", id = "gallery" }); } }
/// <summary> /// Create a new Product object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="imageSource">Initial value of the ImageSource property.</param> /// <param name="previewImageSource">Initial value of the PreviewImageSource property.</param> /// <param name="sortOrder">Initial value of the SortOrder property.</param> public static Product CreateProduct(global::System.Int32 id, global::System.String imageSource, global::System.String previewImageSource, global::System.Int32 sortOrder) { Product product = new Product(); product.Id = id; product.ImageSource = imageSource; product.PreviewImageSource = previewImageSource; product.SortOrder = sortOrder; return product; }
/// <summary> /// Deprecated Method for adding a new object to the Product EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToProduct(Product product) { base.AddObject("Product", product); }