public async Task <IActionResult> Create([Bind("ID,TenNCC,DiaChi,TrangThai")] NhaCungCapModel nhaCungCapModel) { if (ModelState.IsValid) { _context.Add(nhaCungCapModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(nhaCungCapModel)); }
public async Task <IActionResult> Create([Bind("ID_DanhMuc,TenDanhMuc,TrangThai")] DanhMucModel danhMucModel) { if (ModelState.IsValid) { _context.Add(danhMucModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(danhMucModel)); }
public async Task <IActionResult> Create([Bind("ID,HoaDon_ID,TenSP,SoLuong,Gia,KhuyenMai,ThanhTien")] ChiTietHoaDonModel chiTietHoaDonModel) { if (ModelState.IsValid) { _context.Add(chiTietHoaDonModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["HoaDon_ID"] = new SelectList(_context.HoaDonModel, "ID", "ID", chiTietHoaDonModel.HoaDon_ID); return(View(chiTietHoaDonModel)); }
public async Task <IActionResult> Create([Bind("id,User_ID,SanPham_ID,NoiDung,NgayDang,TrangThai")] BinhLuanModel binhLuanModel) { if (ModelState.IsValid) { _context.Add(binhLuanModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["User_ID"] = new SelectList(_context.UserModel, "ID", "ID", binhLuanModel.User_ID); return(View(binhLuanModel)); }
public async Task <IActionResult> Create([Bind("ID,TenLoai,NhaCungCap,TrangThai")] LoaiSanPhamModel loaiSanPhamModel) { if (ModelState.IsValid) { _context.Add(loaiSanPhamModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["NhaCungCap"] = new SelectList(_context.Set <NhaCungCapModel>(), "ID", "ID", loaiSanPhamModel.NhaCungCap); return(View(loaiSanPhamModel)); }
public async Task <IActionResult> Create([Bind("ID,UserName,Password,HoTen,DiaChi,Email,Sdt,Loai,TrangThai")] UserModel userModel) { if (ModelState.IsValid) { userModel.Password = CreateMd5(userModel.Password); _context.Add(userModel); await _context.SaveChangesAsync(); var url = Url.RouteUrl("", new { Controller = "Pages", action = "Index", area = "" }); return(Redirect(url)); } return(View(userModel)); }
public async Task <IActionResult> Create([Bind("ID,User_ID,HoTen,Sdt,ThanhTien,TrangThai")] HoaDonModel hoaDonModel, [Bind("ID,HoaDon_ID,TenSP,SoLuong,Gia,KhuyenMai,ThanhTien,TrangThai")] ChiTietHoaDonModel chitiethoaDonModel) { var HoaDon = from m in _context.HoaDonModel select m; int size = HoaDon.Count(); if (ModelState.IsValid) { _context.Add(hoaDonModel); size++; await _context.SaveChangesAsync(); chitiethoaDonModel.HoaDon_ID = size; _context.Add(chitiethoaDonModel); await _context.SaveChangesAsync(); HttpContext.Session.Remove("cart"); var url = Url.RouteUrl(new { area = "", controller = "Pages", action = "Index" }); return(Redirect(url)); } ViewData["User_ID"] = new SelectList(_context.Set <UserModel>(), "ID", "ID", hoaDonModel.User_ID); return(View(hoaDonModel)); }
public async Task <IActionResult> Create([Bind("ID,TenSP,MaLoai,DanhMuc,Gia,GiaMoi,Image,Image_List,Size,SoLuong,NgayLap,TrangThai")] SanPhamModel sanPhamModel, IFormFile ful, IFormFile ful1) { if (ModelState.IsValid) { _context.Add(sanPhamModel); await _context.SaveChangesAsync(); //dat lai ten file hinh theo ID string s = sanPhamModel.ID + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; //Di chuyen file hinh den folder khac var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/images/", s); using (var stream = new FileStream(path, FileMode.Create)) { await ful.CopyToAsync(stream); } //dat lai ten file hinh theo ID string s1 = sanPhamModel.ID + "2nd" + "." + ful1.FileName.Split(".")[ful1.FileName.Split(".").Length - 1]; //Di chuyen file hinh den folder khac var path1 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/images/", s1); using (var stream1 = new FileStream(path1, FileMode.Create)) { await ful1.CopyToAsync(stream1); } //Gan lai ten file hinh moi cho cot TenHinh sanPhamModel.Image = s; sanPhamModel.Image_List = s1; _context.Update(sanPhamModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(sanPhamModel)); }