Esempio n. 1
0
        public bool DeleteKM(int idTK, int idKM)
        {
            if (db.KhuyenMais.Any(i => i.Flag == true && i.MaKhuyenMai == idKM) == false || idKM == 7)
            {
                return(false);
            }
            else
            {
                var list = db.SanPhams.Where(i => i.Flag == true && i.KhuyenMaiId == idKM && i.KhuyenMaiId != 7).ToList();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        var dc = db.SanPhams.Find(item.MaSP);
                        dc.KhuyenMaiId = 7;
                        dc.KhuyenMai   = db.KhuyenMais.Find(7);
                        db.SaveChanges();
                    }
                }

                Log log = new Log();
                log.Ngay      = DateTime.Now;
                log.HanhDong  = "XKhuyenMai";
                log.KHId      = idTK;
                log.KhachHang = db.KhachHangs.Find(idTK);

                var km = db.KhuyenMais.Find(idKM);
                log.ChiTiet = "Đã XÓA chương trình khuyến mãi tên " + km.TenKM;
                db.Logs.Add(log);
                km.Flag = false;
                db.SaveChanges();
                return(true);
            }
        }
Esempio n. 2
0
 public int UpdateTaiKhoan(int id, string email, string password, string newpassword, string repassword, string ho, string ten, DateTime ngaysinh, int gioitinh)
 {
     if (db.KhachHangs.Any(i => i.Username == email && i.Password == password) == false)
     {
         return(1);
     }
     else
     {
         if (String.IsNullOrEmpty(newpassword) != true || String.IsNullOrEmpty(repassword) != true)
         {
             if (newpassword == repassword)
             {
                 var tk = db.KhachHangs.Find(id);
                 tk.Password = newpassword;
                 tk.Ho       = ho;
                 tk.Ten      = ten;
                 tk.NgaySinh = ngaysinh;
                 if (gioitinh == 0)
                 {
                     tk.GioiTinh = true;
                 }
                 else
                 {
                     tk.GioiTinh = false;
                 }
                 db.SaveChanges();
                 return(3);
             }
             else
             {
                 return(2);
             }
         }
         else
         {
             var tk = db.KhachHangs.Find(id);
             tk.Ho       = ho;
             tk.Ten      = ten;
             tk.NgaySinh = ngaysinh;
             if (gioitinh == 0)
             {
                 tk.GioiTinh = true;
             }
             else
             {
                 tk.GioiTinh = false;
             }
             db.SaveChanges();
             return(4);
         }
     }
 }
Esempio n. 3
0
 public void BoTatCa(List <SanPham> list)
 {
     if (list != null)
     {
         foreach (var item in list)
         {
             var mh = db.SanPhams.Find(item.MaSP);
             mh.KhuyenMaiId = 7;
             mh.KhuyenMai   = db.KhuyenMais.Find(7);
             db.SaveChanges();
         }
     }
 }
Esempio n. 4
0
        public void TaoDanhGia(int idKH, int idMH, string mota)
        {
            DanhGia dg = new DanhGia();

            dg.BinhLuan  = mota;
            dg.Flag      = true;
            dg.Ngay      = DateTime.Now;
            dg.KHId      = idKH;
            dg.SanPhamId = idMH;
            db.DanhGias.Add(dg);
            db.SaveChanges();
        }
        public ActionResult GetDataPaypal()
        {
            var db     = new SanPhamContext();
            var hd     = Session["HD"] as HoaDon;
            var tempHD = db.HoaDons.Find(hd.MaHD);

            tempHD.TinhTrangHoaDon  = "Đã Thanh Toán";
            tempHD.TinhTrangDonHang = "Đang Giao Hàng";
            tempHD.NgayTao          = DateTime.Now;
            foreach (var item in db.ChiTietHoaDons.Where(i => i.HDId == hd.MaHD).ToList())
            {
                var mh = db.SanPhams.Find(item.SanPhamId);
                mh.SoLuong = mh.SoLuong - item.SoLuong;
                db.SaveChanges();
            }
            db.SaveChanges();
            Session["HD"]       = null;
            Session["ListCTHD"] = null;
            ViewBag.Err         = "Thanh toán thành công";
            return(View("../Home/Index"));
        }
Esempio n. 6
0
        public bool DeleteNSX(int id, int idTK)
        {
            if (db.SanPhams.Where(i => i.NSXId == id && i.Flag == true).Count() > 0)
            {
                return(false);
            }
            else
            {
                Log log = new Log();
                log.Ngay      = DateTime.Now;
                log.HanhDong  = "XNSX";
                log.KHId      = idTK;
                log.KhachHang = db.KhachHangs.Find(idTK);

                NSX nsx = db.NSXs.Find(id);
                log.ChiTiet = "Đã XÓA NSX tên " + nsx.TenNSX;
                nsx.flag    = false;
                db.Logs.Add(log);
                db.SaveChanges();
                return(true);
            }
        }
Esempio n. 7
0
        public bool DeleteLoai(int id, int idTK)
        {
            if (db.SanPhams.Where(i => i.LoaiId == id && i.Flag == true).Count() > 0)
            {
                return(false);
            }
            else
            {
                Log log = new Log();
                log.Ngay      = DateTime.Now;
                log.HanhDong  = "XLoai";
                log.KHId      = idTK;
                log.KhachHang = db.KhachHangs.Find(idTK);

                Loai nsx = db.Loais.Find(id);
                log.ChiTiet = "Đã XÓA loại mô hình: " + nsx.TenLoai;
                db.Logs.Add(log);
                nsx.Flag = false;
                db.SaveChanges();
                return(true);
            }
        }
Esempio n. 8
0
        // GET: Home
        public ActionResult Index()
        {
            var db  = new SanPhamContext();
            Log log = new Log();

            log.KHId      = 3;
            log.KhachHang = db.KhachHangs.Find(3);
            log.Ngay      = DateTime.Now;
            log.HanhDong  = "TKhachHang";
            log.ChiTiet   = "ádasfas";
            db.Logs.Add(log);
            db.SaveChanges();
            return(View());
        }
Esempio n. 9
0
        // GET: ChiTietSanPham
        public ActionResult Index(int id, int?page)
        {
            SanPhamContext db = new SanPhamContext();
            SanPham        mh = db.SanPhams.Find(id);

            mh.LuotXem++;
            db.SaveChanges();
            DanhGiaDAO dao = new DanhGiaDAO();

            Session["CTMoHinh"] = mh;
            if (page != null)
            {
                ViewBag.Roll = "roll";
            }
            return(View(dao.GetList(mh.MaSP).ToPagedList(page ?? 1, 7)));
        }
Esempio n. 10
0
        // GET: Paypal
        public ActionResult Index(string ten, string diachi, string SDT)
        {
            var       db     = new SanPhamContext();
            HoaDonDAO dao    = new HoaDonDAO();
            var       hd     = Session["HD"] as HoaDon;
            var       list   = new List <Product>();
            var       tempHD = db.HoaDons.Find(hd.MaHD);

            tempHD.DiaChi       = diachi;
            tempHD.SDT          = SDT;
            tempHD.TenNguoiNhan = ten;
            double tong = 0;

            double phanTram = 0;

            foreach (var item in db.TichLuys.OrderByDescending(i => i.Diem).ToList())
            {
                if (db.KhachHangs.Find(hd.KHId).DiemTichLuy >= item.Diem)
                {
                    phanTram = item.PhanTram;
                    break;
                }
            }

            var ls = dao.GetListCTHD(hd.MaHD);

            foreach (var item in ls)
            {
                tong = tong + item.ThanhTien;
                Product temp = new Product();
                temp.item_number = item.SanPhamId;
                temp.item_name   = item.SanPhams.TenSP;
                temp.quantity    = item.SoLuong;
                double thanhTien = item.ThanhTien - (item.ThanhTien * ((phanTram * 1.0) / 100));
                temp.amount = Math.Round(((thanhTien) * 1.0) / (22000 * 1.0), MidpointRounding.ToEven);
                list.Add(temp);
            }
            tempHD.TongTien = Math.Round((tong - (tong * ((7 * 1.0) / 100))), MidpointRounding.ToEven);
            db.SaveChanges();
            return(View(list));
        }
Esempio n. 11
0
        public void UpdateKH(int idTK, int id, string ho, string ten, DateTime ngaysinh, string gioitinh)
        {
            bool gioiTinh;

            if (gioitinh == "1")
            {
                gioiTinh = false;
            }
            else
            {
                gioiTinh = true;
            }
            string chiTiet = "Đã SỬA";

            Log log = new Log();

            log.Ngay      = DateTime.Now;
            log.HanhDong  = "SAdmin";
            log.KHId      = idTK;
            log.KhachHang = db.KhachHangs.Find(idTK);

            var kh = db.KhachHangs.Find(id);

            if (kh.Ho != ho)
            {
                chiTiet = chiTiet + " 'HỌ' từ " + kh.Ho + " sang " + ho + "; ";
                kh.Ho   = ho;
            }
            if (kh.Ten != ten)
            {
                chiTiet = chiTiet + " 'TÊN' từ " + kh.Ten + " sang " + ten + "; ";
                kh.Ten  = ten;
            }
            if (kh.NgaySinh != ngaysinh)
            {
                chiTiet     = chiTiet + " 'NGÀY SINH' từ " + kh.NgaySinh.ToShortDateString() + " sang " + ngaysinh.ToShortDateString() + "; ";
                kh.NgaySinh = ngaysinh;
            }
            if (kh.GioiTinh != gioiTinh)
            {
                string old  = "";
                string news = "";
                if (gioitinh == "1")
                {
                    news = "Nữ";
                }
                else
                {
                    news = "Nam";
                }
                if (kh.GioiTinh == true)
                {
                    old = "Nam";
                }
                else
                {
                    old = "Nữ";
                }
                chiTiet = chiTiet + " 'GIỚI TÍNH' từ " + old + " sang " + news + "; ";
                if (gioitinh == "1")
                {
                    kh.GioiTinh = false;
                }
                else
                {
                    kh.GioiTinh = true;
                }
            }
            if (chiTiet != "Đã SỬA")
            {
                log.ChiTiet = chiTiet;
                db.Logs.Add(log);
            }



            db.SaveChanges();
        }
Esempio n. 12
0
        public bool HuyDonHang(int idHD, int idTK)
        {
            var hd = db.HoaDons.Find(idHD);

            if (hd.TinhTrangDonHang == "Giao Thành Công")
            {
                return(false);
            }
            foreach (var item in GetListCTHD(idHD))
            {
                var mh = db.SanPhams.Find(item.SanPhamId);
                mh.SoLuong = mh.SoLuong + item.SoLuong;
                db.ChiTietHoaDons.Remove(db.ChiTietHoaDons.Find(item.MaCTHD));
                db.SaveChanges();
            }
            Log log = new Log();

            log.Ngay      = DateTime.Now;
            log.KHId      = idTK;
            log.KhachHang = db.KhachHangs.Find(idTK);
            log.HanhDong  = "HHoaDon";
            log.ChiTiet   = "Đã HỦY hóa đơn với Mã: " + idHD;
            db.Logs.Add(log);
            db.HoaDons.Remove(hd);
            db.SaveChanges();
            return(true);
        }