Beispiel #1
0
        public ActionResult Create(Product model, HttpPostedFileBase fileUpload)
        {

            using (var context = new ShopContainer())
            {
                var category = context.Category.First(c => c.Id == model.CategoryId);



                var product = new Product
                                  {
                                      Name = SiteHelper.UpdatePageWebName(model.Name),
                                      Description = model.Description,
                                      SortOrder = model.SortOrder,
                                      Brand = model.Brand,
                                      Composition = model.Composition,
                                      Size = model.Size,
                                      Price = model.Price,
                                      SeoDescription = model.SeoDescription,
                                      SeoKeywords = model.SeoKeywords,
                                      Title = model.Title
                                  };


                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, 1200);
                    //fileUpload.SaveAs(filePath);
                    product.ImageSource = fileName;
                    product.Preview = fileName;
                }

                product.Category = category;
                context.AddToProduct(product);
                context.SaveChanges();



                return RedirectToAction("Category", "Home", new { area = "", id = category.Name });
            }

        }
Beispiel #2
0
        public ActionResult Create(int categoryId, int brandId, FormCollection form)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    var category = context.Category.First(c => c.Id == categoryId);
                    var brand = context.Brand.First(b => b.Id == brandId);
                    var product = new Product
                                      {
                                          Category = category,
                                          Brand = brand
                                      };
                    TryUpdateModel(product,
                        new[]
                        {
                            "Title",
                            "SortOrder",
                            "Price", 
                            "OldPrice",
                            "IsNew",
                            "IsSpecialOffer",
                            "Published",
                            "SeoDescription",
                            "SeoKeywords",
                            "Articul"
                        });

                    string[] x = form["Name"].Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var s in x)
                    {
                        product.Name += s[0].ToString().ToUpper() + s.Substring(1);
                    }

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

                    context.AddToProduct(product);
                    context.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch
            {
                return View();
            }
        }