Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("MaYt,MaSp,MaKh,NgayChon,MoTa")] YeuThich yeuThich)
        {
            if (ModelState.IsValid)
            {
                _context.Add(yeuThich);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MaKh"] = new SelectList(_context.KhachHang, "MaKh", "MaKh", yeuThich.MaKh);
            ViewData["MaSp"] = new SelectList(_context.SanPham, "MaSp", "MaSp", yeuThich.MaSp);
            return(View(yeuThich));
        }
Exemplo n.º 2
0
 public IActionResult Forget(RestoreAccount model)
 {
     if (ModelState.IsValid)
     {
         KhachHang kh = db.KhachHang.SingleOrDefault(p => p.Email == model.UserEmail);
         if (kh == null)
         {
             ModelState.AddModelError("Lỗi", "Người dùng không tồn tại");
             return(View("Index"));
         }
         else
         {
             string mk = CreatePassword(12);
             kh.MatKhau = pH.HashPassword(mk);
             db.Update(kh);
             db.SaveChangesAsync();
             MailMessage mm = new MailMessage("*****@*****.**", model.UserEmail);
             mm.Subject    = "Mật khẩu tài khoản Eshop";
             mm.Body       = string.Format("Xin chào: <h1>{0}</h1> <br/> Mật khẩu mới của bạn là <h1>{1}</h1>", kh.HoTen, mk);
             mm.IsBodyHtml = true;
             SmtpClient smtp = new SmtpClient();
             smtp.Host        = "smtp.gmail.com";
             smtp.Port        = 587;
             smtp.EnableSsl   = true;
             smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "EShop@21298");
             smtp.Send(mm);
             TempData["Success"] = "Xin hãy kiểm tra Email của bạn!";
             return(View("Index"));
         }
     }
     return(View("Index"));
 }
Exemplo n.º 3
0
        public async Task <IActionResult> DangKy(RegisterModel model)
        {
            var temp = 0;

            if (ModelState.IsValid)
            {
                if (!Regex.IsMatch(model.Email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase))
                {
                    throw new UserDefException("Email không hợp lệ!");
                }
                else
                {
                    var user = new KhachHang();
                    user.MaKh    = model.UserName;
                    user.MatKhau = passwordHasher.HashPassword(model.PassWord);
                    //  user.MatKhau = model.PassWord;
                    user.HoTen       = model.Name;
                    user.GioiTinh    = model.GioiTinh;
                    user.NgaySinh    = model.NgaySinh;
                    user.DiaChi      = model.Diachi;
                    user.PhoneNumber = model.Phonenumer;
                    db.Add(user);
                    await db.SaveChangesAsync();

                    temp = 1;
                }
                if (temp > 0)
                {
                    ViewBag.Success = "Đăng ký thành công!!";
                    temp            = 0;
                }
            }
            // return View(model);
            return(View("DangKy"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("MaLoai,TenLoai,TenLoaiAlias,MoTa")] Loai loai)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(loai);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(loai));
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("MaNv,HoTen,Email,MatKhau")] NhanVien nhanVien)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(nhanVien);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(nhanVien));
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("MaKh,MatKhau,HoTen,GioiTinh,NgaySinh,DiaChi,DienThoai,Email,HieuLuc,VaiTro,RandomKey")] KhachHang khachHang)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(khachHang);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(khachHang));
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("MaKho,MaSp,SoLuong")] KhoHang khoHang)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(khoHang);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["MaSp"] = new SelectList(_context.SanPham, "MaSp", "MaSp", khoHang.MaSp);
                return(View(khoHang));
            }
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("MaHieu,TenHieu,MaSp,Hinh")] ThuongHieu thuongHieu)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(thuongHieu);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["MaHieu"] = new SelectList(_context.ThuongHieu, "MaHieu", "MaHieu", thuongHieu.MaHieu);
                return(View(thuongHieu));
            }
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("MaBl,MaSp,MaKh,NgayBl,HoTen,Email,NoiDung")] BinhLuan binhLuan)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(binhLuan);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["MaKh"] = new SelectList(_context.KhachHang, "MaKh", "MaKh", binhLuan.MaKh);
                ViewData["MaSp"] = new SelectList(_context.SanPham, "MaSp", "MaSp", binhLuan.MaSp);
                return(View(binhLuan));
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("MaSp,TenSp,TenAlias,MaLoai,MoTa,DonGia,Hinh,GiaCu,MaNcc")] SanPham sanPham)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(sanPham);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["MaLoai"] = new SelectList(_context.Loai, "MaLoai", "MaLoai", sanPham.MaLoai);
                ViewData["MaNcc"]  = new SelectList(_context.NhaCungCap, "MaNcc", "MaNcc", sanPham.MaNcc);
                return(View(sanPham));
            }
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("MaCt,MaHd,MaSp,DonGia,SoLuong,GiamGia")] ChiTietHd chiTietHd)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(chiTietHd);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["MaHd"] = new SelectList(_context.HoaDon, "MaHd", "DiaChi", chiTietHd.MaHd);
                ViewData["MaSp"] = new SelectList(_context.SanPham, "MaSp", "MaSp", chiTietHd.MaSp);
                return(View(chiTietHd));
            }
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("MaHd,MaKh,NgayDat,NgayGiao,MaNv,HoTen,DiaChi,CachThanhToan,CachVanChuyen,PhiVanChuyen,MaTrangThai,GhiChu,DienThoai,TenNgNhan,DtngNhan,DiaChiNgNhan")] HoaDon hoaDon)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(hoaDon);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["MaKh"]        = new SelectList(_context.KhachHang, "MaKh", "MaKh", hoaDon.MaKh);
                ViewData["MaNv"]        = new SelectList(_context.NhanVien, "MaNv", "MaNv", hoaDon.MaNv);
                ViewData["MaTrangThai"] = new SelectList(_context.TrangThai, "MaTrangThai", "MaTrangThai", hoaDon.MaTrangThai);
                return(View(hoaDon));
            }
        }