Exemple #1
0
        public ActionResult Create(int categoryId, FormCollection form, HttpPostedFileBase fileUpload)
        {
            using (var context = new SiteContext())
            {
                var category = context.Category.First(c => c.Id == categoryId);
                var product = new Product{SortOrder = 0};
                TryUpdateModel(product, new[] { "Name","Date", "Title",/* "SortOrder",*/ "SeoDescription", "SeoKeywords" });
                product.Description = HttpUtility.HtmlDecode(form["Description"]);
                product.Category = category;

                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);
                    product.ImageSource = fileName;
                }

                context.AddToProduct(product);
                context.SaveChanges();
                return RedirectToAction("Index", "Home", new { area = "", category = category.Name, product = product.Name });
            }
        }
Exemple #2
0
 /// <summary>
 /// Create a new Product object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="imageSource">Initial value of the ImageSource property.</param>
 /// <param name="categoryId">Initial value of the CategoryId property.</param>
 /// <param name="sortOrder">Initial value of the SortOrder property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 public static Product CreateProduct(global::System.Int32 id, global::System.String name, global::System.String title, global::System.String imageSource, global::System.Int32 categoryId, global::System.Int32 sortOrder, global::System.DateTime date)
 {
     Product product = new Product();
     product.Id = id;
     product.Name = name;
     product.Title = title;
     product.ImageSource = imageSource;
     product.CategoryId = categoryId;
     product.SortOrder = sortOrder;
     product.Date = date;
     return product;
 }
Exemple #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Product EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProduct(Product product)
 {
     base.AddObject("Product", product);
 }