コード例 #1
0
        public ActionResult Success(FormCollection frc)
        {
            DonHang donhang = new DonHang
            {
                Email           = frc["khEmail"],
                MaTT            = 1,
                DiaChiNguoiNhan = frc["khDiachi"],
                SDT             = frc["khSodt"],
                TongTien        = Int32.Parse(frc["TTien"]),
            };

            db.DonHangs.Add(donhang);
            db.SaveChanges();

            foreach (var billdetail in ShoppingCart)
            {
                ChiTietDonHang ctdh = new ChiTietDonHang()
                {
                    MaDH    = donhang.MaDH,
                    MaSP    = billdetail.SanPham.MaSP,
                    SoLuong = billdetail.SoLuong,
                };
                db.ChiTietDonHangs.Add(ctdh);
                db.SaveChanges();
            }
            ShoppingCart.Clear();
            return(View("Success"));
        }
コード例 #2
0
        public ActionResult Create(string roleId, string userId)
        {
            var role = db.AspNetRoles.Find(roleId);
            var user = db.AspNetUsers.Find(userId);

            role.AspNetUsers.Add(user);
            db.Entry(role).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index", "AspNetRoles"));
        }
コード例 #3
0
 public ActionResult Create(SanPham model)
 {
     ValidateProduct(model);
     if (ModelState.IsValid)
     {
         db.SanPhams.Add(model);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
コード例 #4
0
        public ActionResult Create(AspNetRole aspNetRole)
        {
            if (ModelState.IsValid)
            {
                aspNetRole.Id = Guid.NewGuid().ToString();
                db.AspNetRoles.Add(aspNetRole);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(aspNetRole));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "MaDH,Email,MaTT,DiaChiNguoiNhan,SDT")] DonHang donHang)
        {
            if (ModelState.IsValid)
            {
                donHang.idKH = User.Identity.GetUserId();
                db.DonHangs.Add(donHang);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MaTT = new SelectList(db.TrangThaiDonHangs, "MaTT", "TrangThai", donHang.MaTT);
            return(View(donHang));
        }
コード例 #6
0
        public ActionResult Create([Bind(Include = "MaCTDH,MaDH,MaSP,SoLuong")] ChiTietDonHang chiTietDonHang)
        {
            if (ModelState.IsValid)
            {
                db.ChiTietDonHangs.Add(chiTietDonHang);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MaDH = new SelectList(db.DonHangs, "MaDH", "Email", chiTietDonHang.MaDH);
            ViewBag.MaSP = new SelectList(db.SanPhams, "MaSP", "MaLoaiSP", chiTietDonHang.MaSP);
            return(View(chiTietDonHang));
        }
コード例 #7
0
 public ActionResult Profile(KhachHang user)
 {
     db.Entry(user).State = EntityState.Modified;
     db.SaveChanges();
     return(View(user));
 }