public async Task <IActionResult> SuaSanPham(int id, [Bind("ID,IDLSP,MaSanPham,TenSanPham")] tb_WMS_SanPham tb_WMS_SanPham) { if (id != tb_WMS_SanPham.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tb_WMS_SanPham); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!tb_WMS_SanPhamExists(tb_WMS_SanPham.ID)) { return(NotFound()); } else { throw; } } TempData["success"] = "success"; return(RedirectToAction(nameof(SanPham))); } ViewData["IDLSP"] = new SelectList(_context.tb_WMS_LoaiSanPham, "ID", "ID", tb_WMS_SanPham.IDLSP); return(View(tb_WMS_SanPham)); }
public async Task <IActionResult> ThemSanPham([Bind("ID,IDLSP,MaSanPham,TenSanPham")] tb_WMS_SanPham tb_WMS_SanPham) { if (ModelState.IsValid) { var idend = (from u in _context.tb_WMS_SanPham orderby u.ID descending select u.ID).Take(1).FirstOrDefault(); tb_WMS_SanPham.ID = idend + 1; var MLSP = (from N in _context.tb_WMS_LoaiSanPham where N.ID == tb_WMS_SanPham.IDLSP select N.MaLoai).FirstOrDefault(); tb_WMS_SanPham.MaSanPham = MLSP + "_P" + (idend + 1); _context.Add(tb_WMS_SanPham); TempData["success"] = "success"; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(SanPham))); } ViewData["IDLSP"] = new SelectList(_context.tb_WMS_LoaiSanPham, "ID", "ID", tb_WMS_SanPham.IDLSP); return(View(tb_WMS_SanPham)); }