Esempio n. 1
0
        public ActionResult Create([Bind(Include = "ID,Name,MoTa")] DanhMuc danhMuc)
        {
            if (ModelState.IsValid)
            {
                db.DanhMucs.Add(danhMuc);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(danhMuc));
        }
        public ActionResult Create([Bind(Include = "MaKhuyenMai,PhanTram")] KM kM)
        {
            if (ModelState.IsValid)
            {
                db.KmS.Add(kM);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(kM));
        }
Esempio n. 3
0
        public ActionResult Create(SanPham sanPham)
        {
            if (ModelState.IsValid)
            {
                //db.SanPhams.Add(sanPham);
                //db.SaveChanges();
                //return RedirectToAction("Index");

                foreach (var item in sanPham.PictureUpload)
                {
                    string path = Path.Combine(Server.MapPath("~/Content/Images/"), Path.GetFileName(item.FileName));
                    item.SaveAs(path);

                    string pathInDb = "/Content/Images/" + Path.GetFileName(item.FileName);

                    HinhAnhSP img = new HinhAnhSP();
                    img.SanPhamID   = sanPham.ID;
                    img.SanPhamObj  = sanPham;
                    img.PicturePath = pathInDb;
                    db.HinhAnhSPs.Add(img);
                }

                db.SanPhams.Add(sanPham);
                db.SaveChanges();
                return(RedirectToAction("IndexPage"));
            }

            ViewBag.DanhMucID   = new SelectList(db.DanhMucs, "ID", "Name", sanPham.DanhMucID);
            ViewBag.MaKhuyenMai = new SelectList(db.KmS, "MaKhuyenMai", "MaKhuyenMai", sanPham.MaKhuyenMai);
            return(View(sanPham));
        }