Exemplo n.º 1
0
        public ActionResult Create(int categoryId, FormCollection form)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var category = context.Category.First(c => c.Id == categoryId);
                    var product = new Product { Category = category, ImageSource = "" };
                    TryUpdateModel(product, new[] { "Title", "Discount", "Price", "Structure", "Consistence", "Producer", "Nap", "PageTitle" });

                    product.Description = HttpUtility.HtmlDecode(form["Description"]);
                    product.DiscountText = HttpUtility.HtmlDecode(form["DiscountText"]);

                    for (int i = 0; i < Request.Files.Count; i++)
                    {

                        var file = Request.Files[i];

                        if (file == null) continue;
                        if (string.IsNullOrEmpty(file.FileName)) continue;

                        var pi = new ProductImage();
                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                        string filePath = Server.MapPath("~/Content/Images");


                        filePath = Path.Combine(filePath, fileName);
                        GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                        //file.SaveAs(filePath);

                        pi.ImageSource = fileName;
                        product.ProductImages.Add(pi);
                        if (string.IsNullOrEmpty(product.ImageSource))
                            product.ImageSource = pi.ImageSource;
                    }

                    context.AddToProduct(product);
                    context.SaveChanges();

                    if (category.SpecialCategory)
                    {
                        return RedirectToAction("OurWorks", "Home", new { area = "" });
                    }

                    return RedirectToAction("Gallery", "Home", new { area = "", id = category.Name });
                }
            }
            catch (Exception ex)
            {
                return View(ViewBag.ErrorMessage = ex.Message);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ProductImage EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProductImage(ProductImage productImage)
 {
     base.AddObject("ProductImage", productImage);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new ProductImage object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="imageSource">Initial value of the ImageSource property.</param>
 /// <param name="productId">Initial value of the ProductId property.</param>
 public static ProductImage CreateProductImage(global::System.Int32 id, global::System.String imageSource, global::System.Int32 productId)
 {
     ProductImage productImage = new ProductImage();
     productImage.Id = id;
     productImage.ImageSource = imageSource;
     productImage.ProductId = productId;
     return productImage;
 }