public ActionResult CreateSP(string CTSP_ID, string SP_ID, string CTSP_TEN, string PN_ID, string CTN_GIA) { CHITIETSANPHAM sANPHAM = new CHITIETSANPHAM(); CHITIETNHAP cHITIETNHAP = new CHITIETNHAP(); CHITIETNHAPsController cHITIETNHAPs = new CHITIETNHAPsController(); string a = db.KiemTraID("ChiTietSanPham", "CTSP_ID", CTSP_ID); if (!string.IsNullOrEmpty(a)) { ModelState.AddModelError("", "Mã sản phẩm đã tồn tại !"); } else if (ModelState.IsValid) { cHITIETNHAP.CTN_ID = db.autottang("CHITIETNHAP", "CTN_ID", db.CHITIETNHAPs.Count()).ToString(); //cHITIETNHAP.PN_ID = Session["PNSP"].ToString(); cHITIETNHAP.PN_ID = PN_ID; cHITIETNHAP.CTSP_ID = CTSP_ID; cHITIETNHAP.CTN_GIA = Convert.ToInt32(CTN_GIA); db.CHITIETNHAPs.Add(cHITIETNHAP); sANPHAM.CTSP_ID = CTSP_ID; sANPHAM.SP_ID = SP_ID; sANPHAM.CTSP_TEN = CTSP_TEN; sANPHAM.CTSP_TRANGTHAI = 1; db.CHITIETSANPHAMs.Add(sANPHAM); db.SaveChanges(); ModelState.AddModelError("", "Đã thêm sản phẩm " + sANPHAM.CTSP_ID); } return(View(sANPHAM)); }
// GET: CHITIETNHAPs public ActionResult Index(string searchTerm, int page = 1, int pageSize = 11) { var SanPhams = new CHITIETNHAPsController(); var mode = SanPhams.ListAllPaging(searchTerm, page, pageSize); ViewBag.SearchTerm = searchTerm; return(View(mode)); }