public bool DangKi(user ur, khachhang kh)
        {
            var check = context.users.Count(x => x.email == ur.email);

            if (check == 0)
            {
                //ur.password = Encrypt.MD5Hash(ur.password);
                //context.users.Add(ur);
                //context.SaveChanges();
                //user u = context.users.FirstOrDefault(s => s.id == ur.id);
                //kh.user = u;
                //context.khachhangs.Add(kh);
                //context.SaveChanges();
                ur.password = Encrypt.MD5Hash(ur.password);
                context.users.Add(ur);
                context.SaveChanges();
                kh.matk = context.users.Where(u => u.email == ur.email).Select(u => u.id).First();
                context.khachhangs.Add(kh);
                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        public int postSanpham(sanpham sp)
        {
            List <sanpham> kiemtratontai = db.sanphams.Where(x => x.tensp == sp.tensp).ToList();
            DateTime       date          = DateTime.Now.Date;

            date.ToString("yyyy-MM-dd");
            if (kiemtratontai.Count > 0)
            {
                return(0);
            }
            else
            {
                sp.ngaynhap = date;
                if (sp.mota == null)
                {
                    sp.mota = "";
                }
                if (sp.hinhanh == null)
                {
                    sp.hinhanh = "";
                }
                sp.moi = 1;
                db.sanphams.Add(sp);
                return(db.SaveChanges());
            }
        }
 public void ThayDoiInfo(infoClientModel info, int makh)
 {
     using (var ctx = new CoffeeHouseDbContext())
     {
         khachhang kh = ctx.khachhangs.FirstOrDefault(x => x.makh == makh);
         if (kh != null)
         {
             kh.sodt   = info.sodt;
             kh.diachi = info.diachi;
             ctx.SaveChanges();
         }
         user u = ctx.users.FirstOrDefault(x => x.id == kh.matk);
         if (u != null)
         {
             u.tentk = info.tenTk;
             ctx.SaveChanges();
         }
     }
     //    khachhang kh = context.khachhangs.FirstOrDefault(x => x.makh == makh);
     //if (kh != null)
     //{
     //    kh.sodt = info.sodt;
     //    kh.diachi = info.diachi;
     //    context.SaveChanges();
     //}
     //user u = context.users.FirstOrDefault(x => x.id == kh.matk);
     //if (u != null)
     //{
     //    u.tentk = info.tenTk;
     //    context.SaveChanges();
     //}
 }
Exemple #4
0
        public int postLoaisanpham(loaisanpham lsp)
        {
            DateTime           date          = DateTime.Now.Date;
            List <loaisanpham> kiemtratontai = db.loaisanphams.Where(x => x.tenloaisp == lsp.tenloaisp).ToList();

            if (kiemtratontai.Count > 0)
            {
                return(0);
            }
            else
            {
                db.loaisanphams.Add(lsp);
                return(db.SaveChanges());
            }
        }
 //private CoffeeHouseDbContext context = new CoffeeHouseDbContext();
 public bool DangKi(user ur, khachhang kh)
 {
     using (var ctx = new CoffeeHouseDbContext())
     {
         var check = ctx.users.Count(x => x.email == ur.email);
         if (check == 0)
         {
             //ur.password = Encrypt.MD5Hash(ur.password);
             //context.users.Add(ur);
             //context.SaveChanges();
             //user u = context.users.FirstOrDefault(s => s.id == ur.id);
             //kh.user = u;
             //context.khachhangs.Add(kh);
             //context.SaveChanges();
             ur.password = Encrypt.MD5Hash(ur.password);
             ctx.users.Add(ur);
             ctx.SaveChanges();
             kh.matk = ctx.users.Where(u => u.email == ur.email).Select(u => u.id).First();
             ctx.khachhangs.Add(kh);
             ctx.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     //    var check = context.users.Count(x => x.email == ur.email);
     //if (check == 0)
     //{
     //    //ur.password = Encrypt.MD5Hash(ur.password);
     //    //context.users.Add(ur);
     //    //context.SaveChanges();
     //    //user u = context.users.FirstOrDefault(s => s.id == ur.id);
     //    //kh.user = u;
     //    //context.khachhangs.Add(kh);
     //    //context.SaveChanges();
     //    ur.password = Encrypt.MD5Hash(ur.password);
     //    context.users.Add(ur);
     //    context.SaveChanges();
     //    kh.matk = context.users.Where(u => u.email == ur.email).Select(u => u.id).First();
     //    context.khachhangs.Add(kh);
     //    context.SaveChanges();
     //    return true;
     //}
     //else
     //    return false;
 }
 public bool getDangkinhantin(string mail)
 {
     using (var db = new CoffeeHouseDbContext())
     {
         dknt dk = new dknt();
         dk.email  = mail;
         dk.ngaydk = DateTime.Today;
         db.dknts.Add(dk);
         db.SaveChanges();
         //try
         //{
         //    db.dknts.Add(dk);
         //    db.SaveChanges();
         //}
         //catch (DbEntityValidationException dbEx)
         //{
         //    foreach (var validationErrors in dbEx.EntityValidationErrors)
         //    {
         //        foreach (var validationError in validationErrors.ValidationErrors)
         //        {
         //            System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
         //        }
         //    }
         //}
         return(true);
     }
 }
        public int setMakhoiphuc(int user_id, string makhoiphuc)
        {
            var ketqua = db.reminders.Count(x => x.user_id == user_id);

            if (ketqua > 0)
            {
                return(0);
            }
            reminder reminder = new reminder();

            reminder.user_id      = user_id;
            reminder.code         = makhoiphuc;
            reminder.completed_at = null;
            db.reminders.Add(reminder);
            return(db.SaveChanges());
        }
Exemple #8
0
        public int getXoaphanhoi(int maph)
        {
            var phanhoi = db.phanhois.Where(x => x.maph == maph).FirstOrDefault();

            db.phanhois.Attach(phanhoi);
            db.phanhois.Remove(phanhoi);
            return(db.SaveChanges());
        }
        public void ThayDoiInfo(infoClientModel info, int makh)
        {
            khachhang kh = context.khachhangs.FirstOrDefault(x => x.makh == makh);

            if (kh != null)
            {
                kh.sodt   = info.sodt;
                kh.diachi = info.diachi;
                context.SaveChanges();
            }
            user u = context.users.FirstOrDefault(x => x.id == kh.matk);

            if (u != null)
            {
                u.tentk = info.tenTk;
                context.SaveChanges();
            }
        }
 public int postDoimatkhau(string email, string matkhau)
 {
     using (var db = new CoffeeHouseDbContext())
     {
         user us = db.users.Where(x => x.email == email).FirstOrDefault();
         us.password = matkhau;
         db.users.AddOrUpdate(us);
         return(db.SaveChanges());
     }
 }
Exemple #11
0
 //private CoffeeHouseDbContext context = new CoffeeHouseDbContext();
 public bool DoiMatKhau(ChangePassModel model)
 {
     using (var ctx = new CoffeeHouseDbContext())
     {
         string matkhau = Encrypt.MD5Hash(model.reNewPass);
         var    query   = (from u in ctx.users
                           join kh in ctx.khachhangs
                           on u.id equals kh.matk
                           where u.email == model.email && u.password == matkhau
                           select new
         {
             idUser = u.id,
             idKH = kh.makh,
             tenKH = kh.hoten,
             email = kh.email
         }).FirstOrDefault();
         if (query is null)
         {
             user u = ctx.users.FirstOrDefault(x => x.email == model.email);
             u.password = matkhau;
             ctx.users.AddOrUpdate(u);
             ctx.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     //    string matkhau = Encrypt.MD5Hash(model.reNewPass);
     //var query = (from u in context.users
     //             join kh in context.khachhangs
     //             on u.id equals kh.matk
     //             where u.email == model.email && u.password == matkhau
     //             select new
     //             {
     //                 idUser = u.id,
     //                 idKH = kh.makh,
     //                 tenKH = kh.hoten,
     //                 email = kh.email
     //             }).FirstOrDefault();
     //if (query != null)
     //{
     //        user u = context.users.FirstOrDefault(x => x.email == model.email);
     //        u.password = matkhau;
     //        context.users.AddOrUpdate(u);
     //        context.SaveChanges();
     //        return true;
     //}
     //else
     //{
     //    return false;
     //}
 }
Exemple #12
0
        public bool Thanhtoandonhang(int madh)
        {
            DateTime date = DateTime.Now.Date;

            date.ToString("yyyy-MM-dd");
            var ctdh = db.ctdhs.Where(x => x.madh == madh);
            int mahd;

            Model.EF.donhang dh;
            using (var context = new CoffeeHouseDbContext())
            {
                dh = context.donhangs.Where(x => x.madh == madh).FirstOrDefault();
                hoadon hd = new hoadon();
                hd.makh          = (long)dh.makh;
                hd.ngaythanhtoan = date;
                hd.tongtien      = dh.tongtien;
                hd.httt          = dh.httt;
                context.hoadons.Add(hd);
                context.SaveChanges();
                mahd = (int)hd.mahd;
            }

            foreach (var ct in ctdh)
            {
                cthd cthd = new cthd();
                cthd.mahd    = mahd;
                cthd.masp    = ct.masp;
                cthd.soluong = ct.soluong;
                cthd.gia     = ct.gia;
                db.cthds.Add(cthd);
            }
            dh.tttt = 1;
            db.donhangs.AddOrUpdate(dh);
            db.SaveChanges();
            return(true);
        }
Exemple #13
0
        public void ThanhToan(List <cartModel> li, int makh, CheckOutInfoModel info)
        {
            try
            {
                khachhang kh = context.khachhangs.FirstOrDefault(x => x.makh == makh);
                kh.diachi   = info.diaChi;
                kh.email    = info.gmail;
                kh.ghichu   = null;
                kh.gioitinh = info.gioitinh;
                kh.hoten    = info.tenKH;
                kh.sodt     = info.sdt;
                kh.matk     = null;
                context.khachhangs.Add(kh);
                context.SaveChanges();

                donhang dh = new donhang();
                dh.makh     = makh;
                dh.ngaydat  = DateTime.Today;
                dh.tongtien = cartModel.tongTien;
                dh.ghichu   = info.ghichu;
                dh.httt     = info.httt;
                dh.tttt     = 0;
                context.donhangs.Add(dh);
                context.SaveChanges();
                donhang temp = context.donhangs.Find(dh.madh);
                foreach (var sp in li)
                {
                    ctdh ct = new ctdh();
                    ct.madh    = temp.madh;
                    ct.masp    = sp.maSP;
                    ct.soluong = sp.soLuong;
                    ct.gia     = sp.donGia;
                    context.ctdhs.Add(ct);
                }
                context.SaveChanges();
                cartModel.tongSoHang = 0;
                cartModel.tongTien   = 0;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
 public int postPhanHoi(phanhoi ph)
 {
     context.phanhois.Add(ph);
     return(context.SaveChanges());
 }
        //private CoffeeHouseDbContext context = new CoffeeHouseDbContext();
        public int ThanhToan(List <cartModel> li, int makh, CheckOutInfoModel info)
        {
            using (var ctx = new CoffeeHouseDbContext())
            {
                int     madh;
                donhang dh = new donhang();
                //dh.khachhang = kh;
                dh.makh     = makh;
                dh.ngaydat  = DateTime.Today;
                dh.tongtien = cartModel.tongTien;
                dh.ghichu   = info.ghichu;
                dh.httt     = info.httt;
                dh.tttt     = 0;
                ctx.donhangs.Add(dh);
                ctx.SaveChanges();
                //ma = dh.madh;
                //donhang temp = context.donhangs.Find(dh.madh);
                madh = (int)dh.madh;
                foreach (var sp in li)
                {
                    ctdh ct = new ctdh();
                    //ct.madh = ma;
                    /*ct.donhang = dh;*/
                    //ct.madh = temp.madh;
                    ct.madh    = madh;
                    ct.masp    = sp.maSP;
                    ct.soluong = sp.soLuong;
                    ct.gia     = sp.donGia;
                    ctx.ctdhs.Add(ct);
                    //context.SaveChanges();
                }

                //try
                //{
                //    context.SaveChanges();
                //}
                //catch (Exception exc)
                //{
                //    string message = exc.GetType().FullName + ": " + exc.Message;
                //}
                cartModel.tongSoHang = 0;
                cartModel.tongTien   = 0;
                return(ctx.SaveChanges());
            }
            //long ma;
            //khachhang kh = context.khachhangs.FirstOrDefault(x => x.makh == makh);
            //kh.diachi = info.diaChi;
            //kh.email = info.gmail;
            //kh.ghichu = info.ghichu;
            //kh.gioitinh = info.gioitinh;
            //kh.hoten = info.tenKH;
            //kh.sodt = info.sdt;
            //kh.matk = null;
            //context.khachhangs.Add(kh);
            //context.SaveChanges();
            //    int madh;
            //    donhang dh = new donhang();
            //    //dh.khachhang = kh;
            //    dh.makh = makh;
            //    dh.ngaydat = DateTime.Today;
            //    dh.tongtien = cartModel.tongTien;
            //    dh.ghichu = info.ghichu;
            //    dh.httt = info.httt;
            //    dh.tttt = 0;
            //    context.donhangs.Add(dh);
            //    context.SaveChanges();
            //    //ma = dh.madh;
            //    //donhang temp = context.donhangs.Find(dh.madh);
            //    madh = (int) dh.madh;
            //    foreach (var sp in li)
            //    {
            //        ctdh ct = new ctdh();
            //        //ct.madh = ma;
            //        /*ct.donhang = dh;*/
            //        //ct.madh = temp.madh;
            //        ct.madh = madh;
            //        ct.masp = sp.maSP;
            //        ct.soluong = sp.soLuong;
            //        ct.gia = sp.donGia;
            //        context.ctdhs.Add(ct);
            //        //context.SaveChanges();
            //    }

            //    //try
            //    //{
            //    //    context.SaveChanges();
            //    //}
            //    //catch (Exception exc)
            //    //{
            //    //    string message = exc.GetType().FullName + ": " + exc.Message;
            //    //}
            //    cartModel.tongSoHang = 0;
            //    cartModel.tongTien = 0;
            //return context.SaveChanges();
        }
Exemple #16
0
 public long Insert(user entity)
 {
     db.users.Add(entity);
     db.SaveChanges();
     return(entity.id);
 }
 public void setTrangthaidangnhap(user taikhoan, int ttdn)
 {
     taikhoan.ttdn = ttdn;
     db.users.AddOrUpdate(taikhoan);
     db.SaveChanges();
 }