Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("LoaiId,TenLoai,MoTa")] Loai loai)
        {
            if (ModelState.IsValid)
            {
                _context.Add(loai);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(loai));
        }
        public async Task <IActionResult> Create([Bind("NhaCungCapId,TenNhaCungCap,MoTa")] NhaCungCap nhaCungCap)
        {
            if (ModelState.IsValid)
            {
                _context.Add(nhaCungCap);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(nhaCungCap));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("HoaDonId,NgayLapHoaDon,TinhTrang,TenKhachHang,DiaChi,Sdt,Email")] HoaDon hoaDon)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hoaDon);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hoaDon));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("ThongTinTaiKhoanId,HoVaTen,NgaySinh,Sdt,DiaChi,TaiKhoanId")] ThongTinTaiKhoan thongTinTaiKhoan)
        {
            if (ModelState.IsValid)
            {
                _context.Add(thongTinTaiKhoan);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TaiKhoanId"] = new SelectList(_context.TaiKhoan, "TaiKhoanId", "UserName", thongTinTaiKhoan.TaiKhoanId);
            return(View(thongTinTaiKhoan));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("KhoHangId,SoLuong,HangHoaId")] KhoHang khoHang)
        {
            if (ModelState.IsValid)
            {
                _context.Add(khoHang);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HangHoaId"] = new SelectList(_context.HangHoa, "HangHoaId", "Hinh", khoHang.HangHoaId);
            return(View(khoHang));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("TopSellingId,HangHoaId,SoLan,DanhGia")] TopSelling topSelling)
        {
            if (ModelState.IsValid)
            {
                _context.Add(topSelling);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HangHoaId"] = new SelectList(_context.HangHoa, "HangHoaId", "Hinh", topSelling.HangHoaId);
            return(View(topSelling));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("HangHoaId,TenHangHoa,NhaCungCapId,LoaiId,Gia,Hinh,MoTa")] HangHoa hangHoa)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hangHoa);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LoaiId"]       = new SelectList(_context.Loai, "LoaiId", "TenLoai", hangHoa.LoaiId);
            ViewData["NhaCungCapId"] = new SelectList(_context.NhaCungCap, "NhaCungCapId", "TenNhaCungCap", hangHoa.NhaCungCapId);
            return(View(hangHoa));
        }
Esempio n. 8
0
        public async Task <IActionResult> Register([Bind("UserName,Email,Password")] TaiKhoan register, string repassword)
        {
            var check = _context.TaiKhoan.Where(p => p.UserName == register.UserName).FirstOrDefault();

            if (check != null)
            {
                ViewData["RegisterError"] = "Tài Khoản Đã Tồn Tại"; return(View("Register"));
            }
            register.LoaiTaiKhoan = false;
            register.NgayDk       = DateTime.Now;

            if (ModelState.IsValid)
            {
                if (repassword == register.Password)
                {
                    register.Password = Encryptor.MD5Hash(register.Password);
                    _context.Add(register);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ViewData["RegisterError"] = "Mật Khẩu không Khớp";
                    return(View("Register"));
                }
            }
            return(View("Index"));
        }
Esempio n. 9
0
        public async Task <IActionResult> Register([Bind("UserName,Email,Password")] TaiKhoan register, string repassword)
        {
            if (UserIsExisting(register.UserName))
            {
                ViewData["RegisterError"] = "Tài Khoản Đã Tồn Tại";
                return(View("Register"));
            }
            else
            {
                register.LoaiTaiKhoan = true;
                register.NgayDk       = DateTime.Now;

                if (ModelState.IsValid)
                {
                    if (repassword == register.Password)
                    {
                        register.Password = Encryptor.MD5Hash(register.Password);
                        _context.Add(register);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        ViewData["RegisterError"] = "Thông tin mật khẩu không chính xác";
                        return(View("Register"));
                    }
                }

                return(View("Index"));
            }
        }
Esempio n. 10
0
        public async Task <IActionResult> Create([Bind("TaiKhoanId,UserName,Password,Email,LoaiTaiKhoan")] TaiKhoan taiKhoan)
        {
            if (ModelState.IsValid)
            {
                var check = _context.TaiKhoan.Where(p => p.UserName == taiKhoan.UserName).FirstOrDefault();
                if (check != null)
                {
                    ViewBag.Error = "Tài Khoản Đã Tồn Tại"; return(View("Create"));
                }
                taiKhoan.Password = Encryptor.MD5Hash(taiKhoan.Password);
                taiKhoan.NgayDk   = DateTime.Now;
                _context.Add(taiKhoan);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(taiKhoan));
        }
Esempio n. 11
0
        public async Task <IActionResult> Create([Bind("HangHoaId,TenHangHoa,NhaCungCapId,LoaiId,Gia,MoTa")] HangHoa hangHoa, IFormFile Hinh)
        {
            if (ModelState.IsValid)
            {
                if (Hinh != null)
                {
                    string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "img", Hinh.FileName);
                    using (var file = new FileStream(path, FileMode.Create))
                    {
                        Hinh.CopyTo(file);
                    }
                    hangHoa.Hinh = Hinh.FileName;
                }
                _context.Add(hangHoa);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LoaiId"]       = new SelectList(_context.Loai, "LoaiId", "TenLoai", hangHoa.LoaiId);
            ViewData["NhaCungCapId"] = new SelectList(_context.NhaCungCap, "NhaCungCapId", "TenNhaCungCap", hangHoa.NhaCungCapId);
            return(View(hangHoa));
        }