Exemplo n.º 1
0
        public async Task <IActionResult> PutBrand(int id, Brand brand)
        {
            if (id != brand.Id)
            {
                return(BadRequest());
            }

            _context.Entry(brand).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BrandExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Edit(int id, [Bind("MaKh,TaiKhoan,MatKhau,HoTen,GioiTinh,NgaySinh,DiaChi,DienThoai,Email,Hinh,TrangThaiHd")] KhachHang khachHang)
        {
            if (id != khachHang.MaKh)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(khachHang);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!KhachHangExists(khachHang.MaKh))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(khachHang));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,LogoUrl,Description")] Brand brand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(brand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brand));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email,Phone,Address")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public async Task <IActionResult> Create([Bind("MaNcc,TenCongTy,Email,DienThoai,DiaChi,MoTa")] NhaCungCap nhaCungCap)
        {
            if (ModelState.IsValid)
            {
                _context.Add(nhaCungCap);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(nhaCungCap));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("MaKh,TaiKhoan,MatKhau,HoTen,GioiTinh,NgaySinh,DiaChi,DienThoai,Email,Hinh,TrangThaiHd")] KhachHang khachHang)
        {
            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("MaLoai,GioiTinh,TenLoai")] Loai loai)
        {
            if (ModelState.IsValid)
            {
                _context.Add(loai);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(loai));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> Create([Bind("LoaiTt,TenTt")] LoaiTinTuc loaiTinTuc)
        {
            if (ModelState.IsValid)
            {
                _context.Add(loaiTinTuc);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(loaiTinTuc));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("Id,Date,DeliveryAddress,ExpectedDeliveryDate,CustomerId,Status,IsPaid")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "FirstName", order.CustomerId);
            return(View(order));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Discount,Stock,Description,Category,BrandId,ImageUrl")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"]  = new SelectList(_context.Brand, "Id", "Name", product.BrandId);
            ViewData["Category"] = new SelectList(_context.Category, "Id", "Name", product.Category);
            return(View(product));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("MaNv,HoTen,Email,MatKhau,MaPq,TrangThaiHd")] NhanVien nhanVien)
        {
            if (ModelState.IsValid)
            {
                nhanVien.MatKhau = Encryptor.MD5Hash(nhanVien.MatKhau);
                _context.Add(nhanVien);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MaPq"] = new SelectList(_context.PhanQuyen, "MaPq", "MaPq", nhanVien.MaPq);
            return(View(nhanVien));
        }
 public IActionResult Forget(ForgetPassword model)
 {
     if (ModelState.IsValid)
     {
         KhachHang kh = db.KhachHang.SingleOrDefault(p => p.Email == model.UserEmail);
         if (kh == null)
         {
             ModelState.AddModelError("Lỗi", "Email không tồn tại trong dữ liệu");
             return(View("Index"));
         }
         else
         {
             string mk = CreatePassword(12);
             kh.MatKhau = Encryptor.MD5Hash(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("*****@*****.**", "eshop147258369");
             smtp.Send(mm);
             TempData["Success"] = "Xin hãy kiểm tra Email của bạn!";
             return(View("Index"));
         }
     }
     return(View("Index"));
 }
 public IActionResult Change(ChangePassword model)
 {
     if (ModelState.IsValid)
     {
         KhachHang kh = HttpContext.Session.Get <KhachHang>("user");
         if (model.MatKhauMoi != model.XacNhanMatKhauMoi)
         {
             ModelState.AddModelError("Lỗi", "Mật khẩu xác nhận không khớp");
             return(View("Index"));
         }
         else
         {
             kh.MatKhau = Encryptor.MD5Hash(model.MatKhauMoi);
             db.Update(kh);
             db.SaveChangesAsync();
             HttpContext.Session.Remove("user");
             if (HttpContext.Session.Get <string>("mess") != null)
             {
                 HttpContext.Session.Remove("mess");
             }
             return(RedirectToAction("Index", "Login"));
         }
     }
     return(View("Index"));
 }
Exemplo n.º 15
0
        public async Task <IActionResult> Create([Bind("MaQc,NoiDungQc,NgayTao,Hinh,NgayKetThucQc,LoaiQc")] BannerQc bannerQc, IFormFile fHinh)
        {
            if (ModelState.IsValid)
            {
                if (fHinh != null)
                {
                    string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "HangHoa", fHinh.FileName);
                    using (var file = new FileStream(path, FileMode.Create))
                    {
                        fHinh.CopyTo(file);
                    }
                    bannerQc.Hinh = fHinh.FileName;
                }
                _context.Add(bannerQc);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(bannerQc));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Create([Bind("MaTt,NoiDung,NgayTao,MaNv,LoaiTt,TrangThai,TieuDe")] TinTuc tinTuc, IFormFile fHinh)
        {
            if (ModelState.IsValid)
            {
                if (fHinh != null)
                {
                    string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "HangHoa", fHinh.FileName);
                    using (var file = new FileStream(path, FileMode.Create))
                    {
                        fHinh.CopyTo(file);
                    }
                    tinTuc.Hinh = fHinh.FileName;
                }
                _context.Add(tinTuc);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LoaiTt"] = new SelectList(_context.LoaiTinTuc, "LoaiTt", "LoaiTt", tinTuc.LoaiTt);
            ViewData["MaNv"]   = new SelectList(_context.NhanVien, "MaNv", "Email", tinTuc.MaNv);
            return(View(tinTuc));
        }
Exemplo n.º 17
0
        public async Task <IActionResult> Create([Bind("MaHh,TenHh,MaLoai,Hinh,DonGia,GiamGia,MoTa,MaNcc,SoLuongHang")] HangHoa hangHoa, IFormFile fHinh)
        {
            if (ModelState.IsValid)
            {
                if (fHinh != null)
                {
                    string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "HangHoa", fHinh.FileName);
                    using (var file = new FileStream(path, FileMode.Create))
                    {
                        fHinh.CopyTo(file);
                    }
                    hangHoa.Hinh = fHinh.FileName;
                }
                _context.Add(hangHoa);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MaLoai"] = new SelectList(_context.Loai, "MaLoai", "MaLoai", hangHoa.MaLoai);
            ViewData["MaNcc"]  = new SelectList(_context.NhaCungCap, "MaNcc", "MaNcc", hangHoa.MaNcc);
            return(View(hangHoa));
        }
Exemplo n.º 18
0
        public IActionResult Activate()
        {
            KhachHang k = HttpContext.Session.Get <KhachHang>("kh");

            if (k != null)
            {
                k.TrangThaiHd = true;
                db.Update(k);
                db.SaveChangesAsync();
                HttpContext.Session.Remove("kh");
                return(RedirectToAction("Index", "Login"));
            }
            else
            {
                ModelState.AddModelError("Lỗi", "Không tìm thấy tài khoản. Bạn cần thực hiện đăng kí tài khoản!");
                return(View("Index"));
            }
        }