public JsonResult ReturnDeviceProject(string Id) { bool result = true; var lstId = Id.Split(','); var check = 0; for (int i = 0; i < lstId.Length; i++) { var IdP = Convert.ToInt32(lstId[i]); //Check thiết bị xem có phải là thiết bị con nằm trong check += data.DeviceDevices.Where(x => x.DeviceCodeChildren == IdP & x.IsDeleted == false & x.TypeComponant == 1).Count(); } if (check > 0) { result = false; } else { // Lấy danh sách thiết bị con từ danh sách thiết bị cha for (int i = 0; i < lstId.Length; i++) { var IdP = Convert.ToInt32(lstId[i]); var lstComponant = data.DeviceDevices.Where(x => x.DeviceCodeParents == IdP & x.IsDeleted == false & x.TypeComponant == 1).Select(x => x.DeviceCodeChildren).ToList(); foreach (var item in lstComponant) { // Trả thiết bị con về kho data.ReturnDeviceProject(Convert.ToInt32(item)); } } // Trả thiết bị về kho for (int i = 0; i < lstId.Length; i++) { if (!lstId[i].Equals("")) { data.ReturnDeviceProject(Convert.ToInt32(lstId[i])); } } result = true; } return(Json(result, JsonRequestBehavior.AllowGet)); }