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)); }
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)); }
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("Id,Name,LogoUrl,Description")] Brand brand) { if (ModelState.IsValid) { _context.Add(brand); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(brand)); }
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)); }
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)); }
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)); }
public IActionResult Create([Bind("MaKh,TaiKhoan,MatKhau,HoTen,GioiTinh,NgaySinh,DiaChi,DienThoai,Email,Hinh")] KhachHang khachHang, IFormFile fHinh) { if (ModelState.IsValid) { KhachHang kh = _context.KhachHang.SingleOrDefault(p => p.Email == khachHang.Email); KhachHang khh = _context.KhachHang.SingleOrDefault(p => p.TaiKhoan == khachHang.TaiKhoan); if (khh != null) { TempData["FailUser"] = "******"; if (kh != null) { TempData["FailEmail"] = "Email này đã được đăng kí!"; } return(View("Create")); } else { if (kh != null) { TempData["FailEmail"] = "Email này đã được đăng kí!"; return(View("Create")); } } if (fHinh != null) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "UserAvatar", fHinh.FileName); using (var file = new FileStream(path, FileMode.Create)) { fHinh.CopyTo(file); } khachHang.Hinh = fHinh.FileName; } khachHang.MatKhau = Encryptor.MD5Hash(khachHang.MatKhau); khachHang.TrangThaiHd = false; khachHang.LoaiKH = false; _context.Add(khachHang); _context.SaveChanges(); MailMessage mm = new MailMessage("*****@*****.**", khachHang.Email); mm.Subject = "Kích hoạt tài khoản Eshop"; mm.Body = string.Format("Xin chào: <h1>{0}</h1> <br/> <h3>Click vào <a href='https://*****:*****@gmail.com", "eshop147258369"); smtp.Send(mm); HttpContext.Session.Set("kh", khachHang); return(RedirectToAction("Index", "Login")); } return(View(khachHang)); }
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)); }
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 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)); }
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)); }
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)); }