Пример #1
0
        public async Task <IActionResult> RegisterUser(string phone)
        {
            UserModel userModel = new UserModel
            {
                Email       = "*****@*****.**",
                CountryCode = "+84",
                PhoneNumber = phone
            };

            var authyId = await _authy.RegisterUserAsync(userModel).ConfigureAwait(false);

            if (string.IsNullOrEmpty(authyId))
            {
                return(Json(new { success = false }));
            }
            else
            {
                //update authyId in database
                KhachHang khachHang = _context.KhachHang.SingleOrDefault(kh => kh.PhoneNumber == phone);

                if (khachHang != null)
                {
                    khachHang.AuthyId = authyId;
                    _context.SaveChanges();
                }

                return(Json(new { success = true, authyId = authyId }));
            }
        }
Пример #2
0
        public IActionResult DoiMK()
        {
            KhachHang kh = HttpContext.Session.Get <KhachHang>("TaiKhoan");
            // Use hash
            PasswordHasher passwordHasher = new PasswordHasher();

            string passold = HttpContext.Request.Form["nhapmkcu"].ToString();
            string pass1   = HttpContext.Request.Form["nhapmk"].ToString();
            string pass2   = HttpContext.Request.Form["nhaplaimk"].ToString();

            //bool isPass = Regex.IsMatch(pass2, @"^((?!.*[\s])(?=.*[A-Z])(?=.*\d).{8,15})", RegexOptions.IgnoreCase);

            try
            {
                if (pass1 != pass2 ||
                    passwordHasher.VerifyHashedPassword(kh.MatKhau, passold) == PasswordVerificationResult.Failed)
                {
                    throw new UserDefException("Mật khẩu không khớp!");
                }
                else if (passwordHasher.VerifyHashedPassword(kh.MatKhau, passold) == PasswordVerificationResult.ErrorNull)
                {
                    throw new UserDefException("Mật khẩu không hợp lệ!");
                }
                else
                {
                    var query = from info in db.KhachHang
                                where info.MaKh == kh.MaKh
                                select info;

                    foreach (KhachHang ds in query)
                    {
                        if (passwordHasher.HashPassword(pass2) == "IVP")
                        {
                            throw new UserDefException("Mật khẩu không hợp lệ!");
                        }
                        else
                        {
                            ds.MatKhau     = passwordHasher.HashPassword(pass2);
                            kh.MatKhau     = ds.MatKhau;
                            ViewBag.Result = "Đã đổi mật khẩu thành công!";
                            HttpContext.Session.Set("TaiKhoan", kh);
                        }
                    }
                    db.SaveChanges();
                    return(View("Index"));
                }
            }
            catch (UserDefException e)
            {
                ViewBag.Result = e.Message;
            }
            catch (Exception e)
            {
                ViewBag.Result = e.Message;
            }
            return(View("Index"));
        }
Пример #3
0
        public IActionResult DatHang(string makh, string hotenkh, string diachikh, string sdt, string tennhan, string sdtnhan, string diachinhan, string ghichunhan)
        {
            HoaDon hd = new HoaDon
            {
                MaKh         = makh,
                HoTen        = hotenkh,
                DiaChi       = diachikh,
                DienThoai    = sdt,
                TenNgNhan    = tennhan,
                DtngNhan     = sdtnhan,
                DiaChiNgNhan = diachinhan,
                GhiChu       = ghichunhan,
                NgayDat      = DateTime.Now,
                MaTrangThai  = 0,
                PhiVanChuyen = 0
            };

            db.HoaDon.Add(hd);

            foreach (var item in Carts)
            {
                SanPham hh = db.SanPham.SingleOrDefault(p => p.MaSp == item.MaHh);
                //Lưu chi tiết hóa đơn
                ChiTietHd cthd = new ChiTietHd
                {
                    MaHd    = hd.MaHd,
                    MaSp    = item.MaHh,
                    DonGia  = hh.DonGia,
                    SoLuong = item.SoLuong,
                };
                db.ChiTietHd.Add(cthd);
                db.SaveChanges();

                //Kiểm tra hàng tồn kho
                KhoHang kho = db.KhoHang.SingleOrDefault(p => p.MaSp == cthd.MaSp);
                if (kho.SoLuong >= cthd.SoLuong)
                {
                    kho.SoLuong = kho.SoLuong - cthd.SoLuong;
                    db.SaveChanges();
                }
                else
                {
                    SanPham sp = db.SanPham.SingleOrDefault(p => p.MaSp == cthd.MaSp);

                    db.ChiTietHd.Remove(cthd);
                    db.HoaDon.Remove(hd);
                    db.SaveChanges();
                    return(RedirectToAction("ThanhToan1"));
                }
            }

            HttpContext.Session.Remove("GioHang");
            HttpContext.Session.Remove("ThongTin");
            return(RedirectToAction("ThanhToan1"));
        }
Пример #4
0
        public IActionResult themYT(int masp, string makh)
        {
            ViewBag.chon = "1";
            YeuThich yt = new YeuThich
            {
                MaKh     = makh,
                MaSp     = masp,
                NgayChon = DateTime.Now,
            };

            _context.YeuThich.Add(yt);
            _context.SaveChanges();
            return(RedirectToAction("ChiTiet", "SanPham", new { @id = masp }));
        }
Пример #5
0
 public IActionResult DoiMK(LoginViewModel model, string nhapmk, string nhaplaimk)
 {
     if (ModelState.IsValid)
     {
         KhachHang kh = db.KhachHang.SingleOrDefault(p => p.MaKh == model.MaKh);
         if (nhapmk != nhaplaimk)
         {
             ModelState.AddModelError("Loi", "Mật khẩu xác nhận không khớp.");
             return(View("Index"));
         }
         else
         {
             kh.MatKhau = nhaplaimk;
             db.Update(kh);
             db.SaveChanges();
             HttpContext.Session.Remove("TaiKhoan");
             return(RedirectToAction("Index", "DangNhap"));
         }
     }
     return(View("Index"));
 }
Пример #6
0
        public IActionResult CheckoutSuccess()
        {
            double tong = 0;
            //Tạo đơn hàng trong database với trạng thái thanh toán là "Paypal" và thành công
            //Xóa session

            List <CartItem> giohang = Carts;

            foreach (var item in giohang)
            {
                tong = tong + item.ThanhTien;
            }
            HttpContext.Session.Set("GioHang", giohang);
            KhachHang kh = HttpContext.Session.Get <KhachHang>("TaiKhoan");
            HoaDon    hd = new HoaDon
            {
                MaKh          = kh.MaKh,
                HoTen         = kh.HoTen,
                DiaChi        = "TPHCM",
                MaOnline      = "IM" + Math.Round(tong * 3, 5).ToString(),
                DienThoai     = kh.DienThoai,
                TenNgNhan     = kh.HoTen,
                DtngNhan      = kh.DienThoai,
                DiaChiNgNhan  = kh.DiaChi,
                NgayDat       = DateTime.Now,
                CachThanhToan = "Online",
                MaTrangThai   = 1,
                PhiVanChuyen  = 0,
                TongTien      = tong
            };

            db.HoaDon.Add(hd);
            //  db.SaveChanges();
            foreach (var item in Carts)
            {
                SanPham hh = db.SanPham.SingleOrDefault(p => p.MaSp == item.MaHh);
                //Lưu chi tiết hóa đơn
                ChiTietHd cthd = new ChiTietHd
                {
                    MaHd    = hd.MaHd,
                    MaSp    = item.MaHh,
                    DonGia  = hh.DonGia,
                    SoLuong = item.SoLuong,
                };
                db.ChiTietHd.Add(cthd);
                db.SaveChanges();
            }
            //HttpContext.Session.Remove("GioHang");
            return(View());
        }
Пример #7
0
        public IActionResult BinhLuan(string makh, int masp, string hoten, string email, string noidung, string loais, string urls)
        {
            BinhLuan bl = new BinhLuan
            {
                MaSp    = masp,
                MaKh    = makh,
                NgayBl  = DateTime.Now,
                HoTen   = hoten,
                Email   = email,
                NoiDung = noidung,
            };

            db.BinhLuan.Add(bl);
            db.SaveChanges();
            return(RedirectToAction("ChiTiet", "SanPham", new { url = urls, loai = loais }));
        }
Пример #8
0
        public IActionResult LienHe(string ten, string tieude, string sdt, string email, string noidung)
        {
            LienHe lh = new LienHe
            {
                HoTen     = ten,
                TieuDe    = tieude,
                DienThoai = sdt,
                Email     = email,
                NoiDung   = noidung,
                NgayGy    = DateTime.Now,
            };

            db.LienHe.Add(lh);
            db.SaveChanges();
            return(RedirectToAction("Contact"));
        }
Пример #9
0
 public static int Insert(SanPham entity)
 {
     db.SanPhams.Add(entity);
     db.SaveChanges();
     return(entity.MaSP);
 }
Пример #10
0
        public async Task <IActionResult> PaypalPayment(string makh, string hotenkh, string diachikh, string sdt, string tennhan, string sdtnhan, string diachinhan, string ghichunhan)
        {
            List <CartItem> danhsachhang = HttpContext.Session.Get <List <CartItem> >("GioHang");
            List <Item>     items        = new List <Item>();
            double          total        = 0;

            foreach (var x in danhsachhang)
            {
                var gia = Math.Round(x.GiaBan / 23000, 0);
                items.Add(new Item()
                {
                    Name     = x.TenHh,
                    Currency = "USD",
                    Price    = gia.ToString(),
                    Quantity = x.SoLuong.ToString(),
                    Sku      = "sku",
                    Tax      = "0"
                });
                total += gia * x.SoLuong;
            }
            HoaDon hd = new HoaDon
            {
                MaKh         = makh,
                HoTen        = hotenkh,
                DiaChi       = "TPHCM",
                DienThoai    = sdt,
                TenNgNhan    = tennhan,
                DtngNhan     = sdtnhan,
                DiaChiNgNhan = diachinhan,
                GhiChu       = ghichunhan,
                NgayDat      = DateTime.Now,
                MaTrangThai  = 0,
                PhiVanChuyen = 0
            };

            db.HoaDon.Add(hd);
            foreach (var item in Carts)
            {
                SanPham hh = db.SanPham.SingleOrDefault(p => p.MaSp == item.MaHh);
                //Lưu chi tiết hóa đơn
                ChiTietHd cthd = new ChiTietHd
                {
                    //MaHd = hd.MaHd,
                    MaSp    = item.MaHh,
                    DonGia  = hh.DonGia,
                    SoLuong = item.SoLuong,
                };
                db.ChiTietHd.Add(cthd);
                db.SaveChanges();
                KhoHang kho = db.KhoHang.SingleOrDefault(p => p.MaSp == cthd.MaSp);
                if (kho.SoLuong >= cthd.SoLuong)
                {
                    kho.SoLuong = kho.SoLuong - cthd.SoLuong;
                    db.SaveChanges();
                }
                else
                {
                    SanPham sp = db.SanPham.SingleOrDefault(p => p.MaSp == cthd.MaSp);

                    db.ChiTietHd.Remove(cthd);
                    db.HoaDon.Remove(hd);
                    db.SaveChanges();
                }
            }
            Payment payment           = _payPal.CreatePayment(total, @"https://*****:*****@"https://localhost:44345/GioHang/CheckoutFail", "sale", items);
            string  paypalRedirectUrl = await _payPal.ExecutePayment(payment);

            if (paypalRedirectUrl == "fail")

            {
                hd.MaTrangThai = 0;
                db.SaveChanges();
                TempData["status"] = "Thanh toán thất bại";
                return(RedirectToAction("Fail"));
            }
            else
            {
                hd.MaTrangThai = 1;
                db.SaveChanges();
                TempData["status"] = "Thanh toán đơn hàng thanh cong";
                return(Redirect(paypalRedirectUrl));
            }
        }
Пример #11
0
 public static int Insert(LoaiSP entity)
 {
     db.LoaiSPs.Add(entity);
     db.SaveChanges();
     return(entity.MaLoaiSP);
 }