public async Task <IActionResult> Edit(int id, [Bind("ID,sanPhamID,maBaoHanh,ngayBan")] SanPhamBan SanPhamBan) { if (id != SanPhamBan.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(SanPhamBan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SanPhamBanExists(SanPhamBan.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(SanPhamBan)); }
public async Task <IActionResult> Create([Bind("ID,sanPhamID,khachHangID,maBaoHanh")] SanPhamBan SanPhamBan) { var dssp = from spb in _context.SanPhamBan select spb; ViewBag.dsLoaiSanPham = dssp.ToList(); if (ModelState.IsValid) { _context.Add(SanPhamBan); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(SanPhamBan)); }
public async Task <IActionResult> BanHang([Bind("ID,sanPhamID,khachHangID,maBaoHanh")] SanPhamBan SanPhamBan, string TenSP) { if (ModelState.IsValid) { var ngayTao = DateTime.Now; SanPhamBan.ngayBan = ngayTao; _context.Add(SanPhamBan); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } var khachhang = (from kh in _context.KhachHang where kh.ID == SanPhamBan.khachHangID select kh).FirstOrDefault(); if (khachhang != null) { ViewBag.tenKH = khachhang.HoTenKhachHang; ViewBag.soDT = khachhang.SoDienThoai; ViewBag.diaChi = khachhang.DiaChi; } ViewBag.tenSP = TenSP; ViewBag.sanPhamID = SanPhamBan.sanPhamID; var dsLoaiSanPham = from lsp in _context.LoaiSanPham select lsp; var loaiSanPhamDauTien = await(from lsp in dsLoaiSanPham select lsp).FirstOrDefaultAsync(); var dsSanPhamTheoLoai = from sp in _context.SanPham where sp.LoaiSanPham == loaiSanPhamDauTien.ID select sp; ViewBag.dsLoaiSanPham = await dsLoaiSanPham.ToListAsync(); ViewBag.dsSanPhamTheoLoai = await dsSanPhamTheoLoai.ToListAsync(); return(View(SanPhamBan)); }