public ActionResult DeleteConfirmed(int id)
        {
            Produtc produtc = db.Produtcs.Find(id);

            db.Produtcs.Remove(produtc);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: Produtcs/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Produtc produtc = db.Produtcs.Find(id);

            if (produtc == null)
            {
                return(HttpNotFound());
            }
            return(View(produtc));
        }
        // GET: Produtcs/Create
        public ActionResult Create()
        {
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(user.CompanyId), "CategoryId", "Description");
            ViewBag.TaxId      = new SelectList(CombosHelper.GetTaxes(user.CompanyId), "TaxId", "Description");
            var products = new Produtc
            {
                CompanyId = user.CompanyId
            };

            return(View(products));
        }
        // GET: Produtcs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Produtc produtc = db.Produtcs.Find(id);

            if (produtc == null)
            {
                return(HttpNotFound());
            }



            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(produtc.CompanyId), "CategoryId", "Description", produtc.ProductId);
            ViewBag.TaxId      = new SelectList(CombosHelper.GetTaxes(produtc.CompanyId), "TaxId", "Description", produtc.ProductId);
            return(View(produtc));
        }
        public ActionResult Create(Produtc produtc)
        {
            if (ModelState.IsValid)
            {
                db.Produtcs.Add(produtc);
                db.SaveChanges();

                if (produtc.ImageFile != null)
                {
                    var pic    = string.Empty;
                    var folder = "~/Content/Products";
                    var file   = string.Format("{0}.jpg", produtc.ProductId);

                    var response = FilesHelper.UploadPhoto(produtc.ImageFile, folder, file);

                    if (response)
                    {
                        pic                     = string.Format("{0}/{1}", folder, file);
                        produtc.Image           = pic;
                        db.Entry(produtc).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index"));
            }

            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }


            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(user.CompanyId), "CategoryId", "Description", produtc.CategoryId);
            ViewBag.TaxId      = new SelectList(CombosHelper.GetTaxes(user.CompanyId), "TaxId", "Description", produtc.TaxId);



            return(View(produtc));
        }