Exemple #1
0
        public ShopModel(ShopContainer context, string categoryId, int? productId)
            : base(context, null)
        {

            Category = context.Category.Include("Products").First(c => c.Name == categoryId);

            foreach (var item in CatalogueMenu.Where(item => item.ContentName == Category.Name))
            {
                if (productId != null)
                {
                    item.Selected = true;
                }
                else
                {
                    item.Current = true;
                }
            }

            if (!string.IsNullOrEmpty(Category.SeoDescription))
                SeoDescription = Category.SeoDescription;
            if (!string.IsNullOrEmpty(Category.SeoKeywords))
                SeoKeywords = Category.SeoKeywords;


            if (productId.HasValue)
            {
                Product = context.Product.First(p => p.Id == productId);
            }

        }
Exemple #2
0
 public void AddToCart(Product product, int quantity)
 {
     //CartLine line = CartLines.FirstOrDefault(x => x.Product.Id == product.Id);
     CartLine line = CartLines.FirstOrDefault(x => x.Product.Id == product.Id);
     if (line == null)
     {
         CartLines.Add(new CartLine
         {
             Count = quantity,
             Product = product
         });
     }
     else
     {
         line.Count += quantity;
     }
 }
Exemple #3
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 });
            }

        }
Exemple #4
0
        public ActionResult Create(int id)
        {
            using (var context = new ShopContainer())
            {
                int maxSortOrder = context.Product.Where(p => p.CategoryId == id).Max(c => (int?)c.SortOrder) ?? 0;

                var category = context.Category.First(c => c.Id == id);

                ViewBag.CategoryName = category.Name;

                var product = new Product
                                  {
                                      SortOrder = maxSortOrder + 1,
                                      CategoryId = id
                                  };

                return View(product);
            }
        }
        public ActionResult Create(ProductCreate product, HttpPostedFileBase image)
        {
            if (this.ModelState.IsValid)
            {

                var p = new Product
                {
                    CategoryId = product.CategoryId,
                    Description = product.Description,
                    Price = product.Price,
                    Name = product.Name,
                    AddDate = DateTime.Now,
                    ImageMimeType = image.ContentType,
                };

                var temp = new byte[image.ContentLength];
                image.InputStream.Read(temp, 0, image.ContentLength);
                var webImageDetailImage = new WebImage(temp);
                var webImagethumImage = new WebImage(temp);

                byte[] detail = webImageDetailImage.Resize(400, 300, false, false).GetBytes();
                byte[] thumb = webImagethumImage.Resize(320, 150,false, false).GetBytes();

                p.ImageData = new byte[detail.Length];
                p.ThumbnailImage = new byte[thumb.Length];

                Array.Copy(detail, p.ImageData, detail.Length);
                Array.Copy(thumb, p.ThumbnailImage, thumb.Length);

                // image.InputStream.Read(p.ImageData, 0, image.ContentLength);
                _db.Products.Add(p);
                _db.SaveChanges();
                return RedirectToAction("Index");
            }

            var selectList = new SelectList(_db.Categories, "Id", "Name");
            ViewBag.Category = selectList;
            return View();
        }
Exemple #6
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);
 }
Exemple #7
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="isNew">Initial value of the IsNew property.</param>
 /// <param name="isSpecialOffer">Initial value of the IsSpecialOffer property.</param>
 /// <param name="published">Initial value of the Published property.</param>
 /// <param name="categoryId">Initial value of the CategoryId property.</param>
 /// <param name="brandId">Initial value of the BrandId property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="articul">Initial value of the Articul property.</param>
 public static Product CreateProduct(global::System.Int32 id, global::System.String name, global::System.Boolean isNew, global::System.Boolean isSpecialOffer, global::System.Boolean published, global::System.Int32 categoryId, global::System.Int32 brandId, global::System.String title, global::System.String articul)
 {
     Product product = new Product();
     product.Id = id;
     product.Name = name;
     product.IsNew = isNew;
     product.IsSpecialOffer = isSpecialOffer;
     product.Published = published;
     product.CategoryId = categoryId;
     product.BrandId = brandId;
     product.Title = title;
     product.Articul = articul;
     return product;
 }
Exemple #8
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="sortOrder">Initial value of the SortOrder property.</param>
 /// <param name="imageSource">Initial value of the ImageSource property.</param>
 /// <param name="preview">Initial value of the Preview property.</param>
 /// <param name="categoryId">Initial value of the CategoryId property.</param>
 public static Product CreateProduct(global::System.Int32 id, global::System.String name, global::System.String title, global::System.Int32 sortOrder, global::System.String imageSource, global::System.String preview, global::System.Int32 categoryId)
 {
     Product product = new Product();
     product.Id = id;
     product.Name = name;
     product.Title = title;
     product.SortOrder = sortOrder;
     product.ImageSource = imageSource;
     product.Preview = preview;
     product.CategoryId = categoryId;
     return product;
 }
Exemple #9
0
 public void RemoveLine(Product product)
 {
     CartLines.RemoveAll(x => x.Product.Id == product.Id);
 }
Exemple #10
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();
            }
        }