public ActionResult Checkout(string name, string address, string phonenum, string email)
        {
            int id = 1;

            try
            {
                var dt = db.DonDatHang.Select(s => new { s.MaDDH }).OrderByDescending(s => s.MaDDH).FirstOrDefault();
                id = dt.MaDDH + 1;
            }
            catch (Exception)
            {
            }
            DonDatHang thongtin = new DonDatHang();

            thongtin.Name           = name;
            thongtin.PhoneNum       = phonenum;
            thongtin.Email          = email;
            thongtin.DiaChiGiaoHang = address;
            thongtin.NgayDat        = DateTime.Now;
            thongtin.TrangThai      = "Đã xác nhận";
            float tongtien = 0;

            thongtin.ThanhToan = false;
            if (Session["GioHang"] != null)
            {
                var gh = (List <GioHang>)Session["GioHang"];
                foreach (GioHang a in gh)
                {
                    tongtien += a.SL * a.DonGia;
                }
            }
            thongtin.MaDDH    = id;
            thongtin.TongTien = tongtien;
            db.DonDatHang.Add(thongtin);
            db.SaveChanges();
            if (Session["GioHang"] != null)
            {
                var gh = (List <GioHang>)Session["GioHang"];
                foreach (GioHang a in gh)
                {
                    CT_DonDatHang ct = new CT_DonDatHang();
                    ct.MaSP     = a.ID;
                    ct.MaDDH    = id;
                    ct.DonGia   = a.DonGia;
                    ct.SoLuong  = a.SL;
                    ct.TongTien = a.SL * a.DonGia;
                    foreach (var i in db.Sanpham)
                    {
                        if (i.MaSP == ct.MaSP)
                        {
                            i.SoLuong = i.SoLuong - a.SL;
                        }
                    }
                    db.CT_DonDatHang.Add(ct);
                    db.SaveChanges();
                }
            }
            return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public void LuuDH(int?id, string TrangThai)
        {
            var dh = db.DonDatHang.Find(id);

            dh.TrangThai = TrangThai;
            if (dh.TrangThai == "Đã thanh toán")
            {
                dh.ThanhToan = true;
            }
            if (dh.TrangThai == "Chưa thanh toán")
            {
                dh.ThanhToan = false;
            }
            db.SaveChanges();
        }
Exemplo n.º 3
0
 public int Insert(ClientAccount entity)
 {
     db.ClientAccount.Add(entity);
     db.SaveChanges();
     return(entity.IDAcount);
 }
 public int Insert(Sanpham entity)
 {
     db.Sanpham.Add(entity);
     db.SaveChanges();
     return(entity.MaSP);
 }
Exemplo n.º 5
0
 public int Insert(User entity)
 {
     db.User.Add(entity);
     db.SaveChanges();
     return(entity.MaUser);
 }