public ActionResult Create()
        {
            ProductCategoryManufacturerModel test = new ProductCategoryManufacturerModel();

            test.Categories   = ServiceFactory.GetCategoryService().GetAll();
            test.Manufactures = ServiceFactory.GetManufacturerService().GetAll();
            //test.CategoryId = 2;
            return(View(test));
        }
        public ActionResult Edit(int id)
        {
            Product p = ServiceFactory.GetProductService().Get(id);
            ProductCategoryManufacturerModel test = new ProductCategoryManufacturerModel();

            test.Categories     = ServiceFactory.GetCategoryService().GetAll();
            test.Manufactures   = ServiceFactory.GetManufacturerService().GetAll();
            test.Product        = p;
            test.ManufacturerId = p.ManufacturerId;
            test.CategoryId     = p.CategoryId;
            return(View(test));
        }
        public ActionResult Edit(ProductCategoryManufacturerModel p, HttpPostedFileBase ImagePath)
        {
            if (ModelState.IsValid)
            {
                //Product pToUpdate = ServiceFactory.GetProductService().Get(p.Product.ProductId);
                try
                {
                    string fullPath = Request.MapPath(p.Product.ProductImagePath);
                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }

                    string pic_name = p.Product.ProductName + Path.GetExtension(ImagePath.FileName);
                    string path     = System.IO.Path.Combine(Server.MapPath("~/Images"), pic_name);

                    ImagePath.SaveAs(path);

                    // tyre.Url = filename;
                    //p.ImagePath = DateTime.Now.ToLongDateString() + p.productId;

                    p.Product.ProductImagePath = "~/Images/" + pic_name;
                    // pToUpdate.ProductImagePath = p.Product.ProductImagePath;
                }
                catch (Exception ex)
                {
                }



                ///context.SaveChanges();

                // p.Product.ProductId = 17;
                p.Product.CategoryId     = p.CategoryId;
                p.Product.ManufacturerId = p.ManufacturerId;

                ServiceFactory.GetProductService().Update(p.Product);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(p));
            }
        }
        public ActionResult Create(ProductCategoryManufacturerModel p, HttpPostedFileBase ImagePath)
        {
            if (ModelState.IsValid)
            {
                string pic_name = p.Product.ProductName + Path.GetExtension(ImagePath.FileName);
                string path     = System.IO.Path.Combine(Server.MapPath("~/Images"), pic_name);

                ImagePath.SaveAs(path);

                // tyre.Url = filename;
                //p.ImagePath = DateTime.Now.ToLongDateString() + p.productId;
                p.Product.ProductImagePath = "~/Images/" + pic_name;
                p.Product.CategoryId       = p.CategoryId;
                p.Product.ManufacturerId   = p.ManufacturerId;
                int r = ServiceFactory.GetProductService().Insert(p.Product);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(p));
            }
        }