示例#1
0
        public ActionResult Create(int productId, FormCollection form, HttpPostedFileBase fileUpload)
        {
            using (var context = new SiteContext())
            {
                var product = context.Product.Include("Category").First(c => c.Id == productId);
                
                var pi = new ProductItem();
                TryUpdateModel(pi, new[] { "SortOrder" });
                pi.Description = HttpUtility.HtmlDecode(form["Description"]);
                pi.Product = product;

                if (fileUpload != null)
                {
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                    string filePath = Server.MapPath("~/Content/Images");
                    filePath = Path.Combine(filePath, fileName);
                    //GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload);
                    fileUpload.SaveAs(filePath);
                    pi.ImageSource = fileName;
                }

                context.AddToProductItem(pi);
                context.SaveChanges();
                return RedirectToAction("Index", "Home", new { area = "", category =product.Category.Name, product = product.Name });
            }
        }
示例#2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ProductItem EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProductItem(ProductItem productItem)
 {
     base.AddObject("ProductItem", productItem);
 }
示例#3
0
 /// <summary>
 /// Create a new ProductItem object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="productId">Initial value of the ProductId property.</param>
 /// <param name="sortOrder">Initial value of the SortOrder property.</param>
 public static ProductItem CreateProductItem(global::System.Int32 id, global::System.Int32 productId, global::System.Int32 sortOrder)
 {
     ProductItem productItem = new ProductItem();
     productItem.Id = id;
     productItem.ProductId = productId;
     productItem.SortOrder = sortOrder;
     return productItem;
 }