public void Create(ProductViewModel model)
 {
     Product product = new Product
     {
         ProductId = model.ProductId,
         ProductName = model.ProductName,
         SubcategoryId = model.SubcategoryId,
         Price = model.Price,
         Discount = model.Discount,
         Description = model.Description
     };
     using (var context = new WebShopMVCContext())
     {
         context.Products.Add(product);
         context.SaveChanges();
     }
 }
        public ProductViewModel GetNewProductViewModelWithSubcategory()
        {
            ProductViewModel model = new ProductViewModel();

            using (var context = new WebShopMVCContext())
            {
                model.Subcategories = context.Subcategories.Select(c => new PartViewSubcategoriesForProduct
                {
                    SubcategoryName = c.SubcategoryName,
                    SubcategoryId = c.SubcategoryId
                }).ToList();

            }
            return model;
        }
        public ProductViewModel GetModelById(int id)
        {
            ProductViewModel model;

            using (var context = new WebShopMVCContext())
            {
                var product = context.Products.Find(id);
                model = new ProductViewModel
                {
                    ProductId = product.ProductId,
                    ProductName = product.ProductName,
                    SubcategoryId = product.SubcategoryId,
                    Price = product.Price,
                    Discount = product.Discount,
                    Description = product.Description,
                    Subcategories = context.Subcategories.Select(c => new PartViewSubcategoriesForProduct
                    {
                        SubcategoryName = c.SubcategoryName,
                        SubcategoryId = c.SubcategoryId
                    }).ToList(),
                    Images = context.Images.Select(f => new PartImageViewModel
                    {
                        MainPicture = f.MainPicture,
                        FileName = f.FileName,
                        ImageId = f.ImageId,
                        ProductId = f.ProductId
                    }).Where(p=>p.ProductId==id).ToList()

                };
            }
            return model;
        }
 public void Update(ProductViewModel model)
 {
     using (var context = new WebShopMVCContext())
     {
         var product = context.Products.Find(model.ProductId);
         product.ProductName = model.ProductName;
         product.SubcategoryId = model.SubcategoryId;
         product.Price = model.Price;
         product.Discount = model.Discount;
         product.Description = model.Description;
         context.SaveChanges();
     }
 }