Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("MaYt,MaSp,MaKh,NgayChon,MoTa")] YeuThich yeuThich)
        {
            if (id != yeuThich.MaYt)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(yeuThich);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!YeuThichExists(yeuThich.MaYt))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                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));
        }
Ejemplo 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"));
 }
Ejemplo n.º 3
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"));
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("MaHd,MaKh,NgayDat,NgayGiao,MaNv,HoTen,CachThanhToan,CachVanChuyen,PhiVanChuyen,MaTrangThai,GhiChu,DienThoai,TenNgNhan,DtngNhan,DiaChiNgNhan")] HoaDon hoaDon)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (id != hoaDon.MaHd)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(hoaDon);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!HoaDonExists(hoaDon.MaHd))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    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));
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("MaBl,MaSp,MaKh,NgayBl,HoTen,Email,NoiDung")] BinhLuan binhLuan)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (id != binhLuan.MaBl)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(binhLuan);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!BinhLuanExists(binhLuan.MaBl))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    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));
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [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 (id != sanPham.MaSp)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(sanPham);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!SanPhamExists(sanPham.MaSp))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    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));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, [Bind("MaCt,MaHd,MaSp,DonGia,SoLuong,GiamGia")] ChiTietHd chiTietHd)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (id != chiTietHd.MaCt)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(chiTietHd);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ChiTietHdExists(chiTietHd.MaCt))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    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));
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Edit(string id, [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 (id != khachHang.MaKh)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        PasswordHasher passwordHasher = new PasswordHasher();
                        khachHang.MatKhau = passwordHasher.HashPassword(khachHang.MatKhau);
                        _context.Update(khachHang);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!KhachHangExists(khachHang.MaKh))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(khachHang));
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Edit(int id, [Bind("MaKho,MaSp,SoLuong")] KhoHang khoHang)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (id != khoHang.MaKho)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(khoHang);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!KhoHangExists(khoHang.MaKho))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["MaSp"] = new SelectList(_context.SanPham, "MaSp", "MaSp", khoHang.MaSp);
                return(View(khoHang));
            }
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Edit(int id, [Bind("MaHieu,TenHieu,MaSp,Hinh")] ThuongHieu thuongHieu)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (id != thuongHieu.MaHieu)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(thuongHieu);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ThuongHieuExists(thuongHieu.MaHieu))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["MaHieu"] = new SelectList(_context.ThuongHieu, "MaHieu", "MaHieu", thuongHieu.MaHieu);
                return(View(thuongHieu));
            }
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Edit(int id, [Bind("MaLoai,TenLoai,TenLoaiAlias,MoTa")] Loai loai)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (id != loai.MaLoai)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(loai);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!LoaiExists(loai.MaLoai))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(loai));
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Edit(string id, [Bind("MaNv,HoTen,Email,MatKhau")] NhanVien nhanVien)
        {
            if (HttpContext.Session.Get <NhanVien>("MaNv") == null)
            {
                return(Redirect("/Admin/Login"));
            }
            else
            {
                if (id != nhanVien.MaNv)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(nhanVien);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!NhanVienExists(nhanVien.MaNv))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(nhanVien));
            }
        }