// // GET: /CS_tbWorkCount/Details/5 public ActionResult Details(int id) { using (OnlineShopDbContext db = new OnlineShopDbContext()) { CS_tbWorkCountViewModels model = new CS_tbWorkCountViewModels(); //--------Select ID trả kết quả về View-----------// model.CS_tbWorkCount_Select = db.CS_tbWorkCount.Find(id); model.CS_tbWorkCount_Sub = db.CS_tbWorkCount_Sub.Where(m => m.CS_tbWorkCount_ID == id).ToList(); model.CS_tbLLTCTypeSub = new List <CS_tbLLTCTypeSub>(); model.LLTC_temp = new List <LLTC>(); model.CS_tbWorkType_temp = new List <CS_tbWorkType>(); int j = 0; foreach (var CS_tbWorkCount_Sub in model.CS_tbWorkCount_Sub) { CS_tbLLTCTypeSub obj_temp = db.CS_tbLLTCTypeSub.Find(CS_tbWorkCount_Sub.CS_tbLLTCTypeSub_ID); model.CS_tbLLTCTypeSub.Add(obj_temp); LLTC obj_temp_2 = db.LLTCs.Find(CS_tbWorkCount_Sub.CS_LLTC_ID); model.LLTC_temp.Add(obj_temp_2); CS_tbWorkType obj_temp_3 = db.CS_tbWorkType.Find(model.CS_tbLLTCTypeSub[j].CS_tbLLTCNameJobDetailsSub); model.CS_tbWorkType_temp.Add(obj_temp_3); j++; } return(View("Details", model)); } }
public ActionResult DetailsEditGet(int id, CS_tbWorkCountViewModels collection) { using (OnlineShopDbContext db = new OnlineShopDbContext()) { CS_tbWorkCountViewModels model = new CS_tbWorkCountViewModels(); foreach (var CS_tbWorkCount_Sub_Temp in collection.CS_tbWorkCount_Sub) { CS_tbWorkCount_Sub obj = db.CS_tbWorkCount_Sub.Find(CS_tbWorkCount_Sub_Temp.ID); obj.CS_tbNumberDailyCount = CS_tbWorkCount_Sub_Temp.CS_tbNumberDailyCount; db.SaveChanges(); } //--------Select ID trả kết quả về View-----------// model.CS_tbWorkCount_Select = db.CS_tbWorkCount.Find(id); model.CS_tbWorkCount_Sub = db.CS_tbWorkCount_Sub.Where(m => m.CS_tbWorkCount_ID == id).ToList(); int mTotalCount = 0; foreach (var CS_tbWorkCount_Sub in model.CS_tbWorkCount_Sub) { mTotalCount = mTotalCount + (int)CS_tbWorkCount_Sub.CS_tbNumberDailyCount; } CS_tbWorkCount objTotalCount = db.CS_tbWorkCount.Find(id); objTotalCount.tb_mTotalCount = mTotalCount; db.SaveChanges(); model.CS_tbLLTCTypeSub = new List <CS_tbLLTCTypeSub>(); model.LLTC_temp = new List <LLTC>(); model.CS_tbWorkType_temp = new List <CS_tbWorkType>(); int j = 0; model.CS_tbWorkCount_Sub = db.CS_tbWorkCount_Sub.Where(m => m.CS_tbWorkCount_ID == id).ToList(); foreach (var CS_tbWorkCount_Sub in model.CS_tbWorkCount_Sub) { CS_tbLLTCTypeSub obj_temp = db.CS_tbLLTCTypeSub.Find(CS_tbWorkCount_Sub.CS_tbLLTCTypeSub_ID); model.CS_tbLLTCTypeSub.Add(obj_temp); LLTC obj_temp_2 = db.LLTCs.Find(CS_tbWorkCount_Sub.CS_LLTC_ID); model.LLTC_temp.Add(obj_temp_2); CS_tbWorkType obj_temp_3 = db.CS_tbWorkType.Find(model.CS_tbLLTCTypeSub[j].CS_tbLLTCNameJobDetailsSub); model.CS_tbWorkType_temp.Add(obj_temp_3); j++; } return(View("Details", model)); } }