Пример #1
0
        public ActionResult Edit(vw_Everything tb)
        {
            tblProduct tp = _db.tblProducts.Where(u => u.ProductId == tb.ProductId).FirstOrDefault();

            tp.Brand       = tb.Brand;
            tp.CategoryId  = Convert.ToInt32(tb.CategoryName);
            tp.Description = tb.Description;
            tp.Price       = tb.Price;
            tp.ProductName = tb.ProductName;
            tp.Color       = tb.Color;
            HttpPostedFileBase fup = Request.Files["Img"];

            if (fup != null)
            {
                if (fup.FileName != "")
                {
                    if (tp.CategoryId == 3)
                    {
                        System.IO.File.Delete(Server.MapPath("~/Images/Products/Tshirt/" + tb.Img));

                        tp.Img = fup.FileName;
                        fup.SaveAs(Server.MapPath("~/Images/Products/Tshirt/" + fup.FileName));
                    }
                    if (tp.CategoryId == 1)
                    {
                        System.IO.File.Delete(Server.MapPath("~/Images/Products/Mobile/" + tb.Img));

                        tp.Img = fup.FileName;
                        fup.SaveAs(Server.MapPath("~/Images/Products/Mobile/" + fup.FileName));
                    }
                    if (tp.CategoryId == 2)
                    {
                        System.IO.File.Delete(Server.MapPath("~/Images/Products/Pant/" + tb.Img));

                        tp.Img = fup.FileName;
                        fup.SaveAs(Server.MapPath("~/Images/Products/Pant/" + fup.FileName));
                    }
                    if (tp.CategoryId == 4)
                    {
                        System.IO.File.Delete(Server.MapPath("~/Images/Products/Kurtha/" + tb.Img));

                        tp.Img = fup.FileName;
                        fup.SaveAs(Server.MapPath("~/Images/Products/Kurtha/" + fup.FileName));
                    }
                }
                else
                {
                    tp.Img = tb.Img;
                }
            }
            if (_db.SaveChanges() > 0)
            {
                return(RedirectToAction("Index", "Product"));
            }

            return(View());
        }
Пример #2
0
        public ActionResult Create(vw_Everything tb)
        {
            tblProduct tp = new tblProduct();

            tp.Brand       = tb.Brand;
            tp.Color       = tb.Color;
            tp.CategoryId  = Convert.ToInt32(tb.CategoryName);
            tp.Description = tb.Description;
            tp.Price       = tb.Price;
            tp.ProductName = tb.ProductName;


            HttpPostedFileBase fup = Request.Files["Img"];

            if (tp.CategoryId == 1)
            {
                if (fup != null)
                {
                    tp.Img = fup.FileName;
                    fup.SaveAs(Server.MapPath("~/Images/Products/Mobile/" + fup.FileName));
                }
            }
            if (tp.CategoryId == 2)
            {
                if (fup != null)
                {
                    tp.Img = fup.FileName;
                    fup.SaveAs(Server.MapPath("~/Images/Products/Pant/" + fup.FileName));
                }
            }
            if (tp.CategoryId == 3)
            {
                if (fup != null)
                {
                    tp.Img = fup.FileName;
                    fup.SaveAs(Server.MapPath("~/Images/Products/Tshirt/" + fup.FileName));
                }
            }
            if (tp.CategoryId == 4)
            {
                if (fup != null)
                {
                    tp.Img = fup.FileName;
                    fup.SaveAs(Server.MapPath("~/Images/Products/Kurtha/" + fup.FileName));
                }
            }

            _db.tblProducts.Add(tp);
            if (_db.SaveChanges() > 0)
            {
                return(RedirectToAction("Index"));
            }


            return(View());
        }