Exemple #1
0
        public ActionResult Create_Edit()
        {
            if (Request.Files.Count != 0)
            {
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file       = Request.Files[i];
                    var fileName   = Path.GetFileName(file.FileName);
                    var id         = int.Parse(Request.Form["id_pro"]);
                    var name       = Request.Form["name"];
                    var image_name = Request.Form["Img"];
                    var id_cate    = int.Parse(Request.Form["Category"]);
                    var id_brand   = int.Parse(Request.Form["Brand"]);
                    var price      = float.Parse(Request.Form["Price"]);
                    var decription = Request.Form["Decription"];
                    var discount   = float.Parse(Request.Form["Discount"]);
                    var active     = Request.Form["Status"].Equals("1") ? true : false;
                    Models.IRepository <Models.ModelView.ProductView> repository = Models.Dao.ProductDao.Instance;
                    Models.ModelView.ProductView pv = new Models.ModelView.ProductView();
                    pv.id           = id;
                    pv.name_product = name;
                    pv.name_image   = fileName;
                    pv.id_brand     = id_brand;
                    pv.id_category  = id_cate;
                    pv.price        = price;
                    pv.discount     = discount;
                    pv.status       = active;
                    pv.description  = decription;
                    repository.Update(pv);
                    var path = Path.Combine(Server.MapPath("~/Areas/Admin/Upload/"), fileName);
                    file.SaveAs(path);
                }
            }

            return(RedirectToAction("Product"));
        }
Exemple #2
0
        public ActionResult CreateProduct(HttpPostedFileBase Img)
        {
            var name  = Request.Form["Name"];
            var price = 0.0;

            if (Request.Form["Price"] != "")
            {
                price = float.Parse(Request.Form["Price"]);
            }

            var active = false;

            if (Request.Form["Status"] != null)
            {
                if (int.Parse(Request.Form["Status"]) == 1)
                {
                    active = true;
                }
                else
                {
                    active = false;
                }
            }
            var image_name = "";

            if (Img != null)
            {
                image_name = Img.FileName;
            }


            var id_cate = 0;

            if (Request.Form["Category"] != null)
            {
                id_cate = int.Parse(Request.Form["Category"]);
            }

            var id_brand = 0.0;

            if (Request.Form["Brand"] != null)
            {
                id_brand = int.Parse(Request.Form["Brand"]);
            }
            var description = "";

            if (Session["description"] != null)
            {
                description            = Session["description"].ToString();
                Session["description"] = null;
            }
            if (name != "" && price != 0 && image_name != "" && id_cate != 0 && id_brand != 0 && description != "")
            {
                Models.ModelView.ProductView pro = new Models.ModelView.ProductView();
                pro.name_product = name;
                pro.name_image   = image_name;
                pro.id_brand     = (int)id_brand;
                pro.id_category  = id_cate;
                pro.price        = (float)price;
                pro.discount     = 0;
                pro.status       = active;
                pro.description  = description;
                pro.created      = DateTime.Parse(DateTime.Now.ToString("d"));
                Models.IRepository <Models.ModelView.ProductView> Product = Models.Dao.ProductDao.Instance;
                Product.Create(pro);
                string pathUpload = Server.MapPath("~/Areas/Admin/Upload/") + image_name;
                Img.SaveAs(pathUpload);

                return(RedirectToAction("Product"));
            }
            else
            {
                return(RedirectToAction("Product"));
            }
        }