public IActionResult SurveyDetailedView(long Id) { ViewBag.Id = Id; List <TblPoolSurvey> tblPoolSurveys = _survey.GetPoolBySurveyId(Id); var CityList = _lookUps.GetCity(); var FamilyStatusList = _lookUps.GetFamilyStatus(); var GenderList = _lookUps.GetGender(); var PoolList = _pool.GetPools(); foreach (var item in tblPoolSurveys) { if (!string.IsNullOrEmpty(item.PoolTemplate.Gender)) { item.PoolTemplate.GenderName = GenderList.Where(x => x.Id == Convert.ToInt64(item.PoolTemplate.Gender)).SingleOrDefault().Name; } if (!string.IsNullOrEmpty(item.PoolTemplate.FamilyStatus)) { item.PoolTemplate.FamilySName = FamilyStatusList.Where(x => x.Id == Convert.ToInt64(item.PoolTemplate.FamilyStatus)).SingleOrDefault().Name; } if (!string.IsNullOrEmpty(item.PoolTemplate.CityIds)) { string[] cityIdList = item.PoolTemplate.CityIds.Split(","); int counter = 0; foreach (var id in cityIdList) { if (counter < 1) { item.PoolTemplate.CityName = CityList.Where(x => x.Id == Convert.ToInt64(id)).SingleOrDefault().Name; } else { item.PoolTemplate.CityName = item.PoolTemplate.CityName + "," + CityList.Where(x => x.Id == Convert.ToInt64(id)).SingleOrDefault().Name; } counter++; } } var pool = PoolList.Where(x => x.Id == item.PoolTemplate.Id).SingleOrDefault(); PoolList.Remove(pool); } //TblPool tblPool = new TblPool(); //List<TblPoolSurvey> list = new List<TblPoolSurvey>(); //TblPoolSurvey item; //for (int i = 0; i < tblPoolSurveys.Count; i++) //{ // item = new TblPoolSurvey(); // item = tblPoolSurveys[i]; // if (!string.IsNullOrEmpty(item.PoolTemplate.Gender)) // { // item.PoolTemplate.Gender = GenderList.Where(x => x.Id == Convert.ToInt64(item.PoolTemplate.Gender)).SingleOrDefault().Name; // } // if (!string.IsNullOrEmpty(item.PoolTemplate.FamilyStatus)) // { // item.PoolTemplate.FamilyStatus = FamilyStatusList.Where(x => x.Id == Convert.ToInt64(item.PoolTemplate.FamilyStatus)).SingleOrDefault().Name; // } // if (!string.IsNullOrEmpty(item.PoolTemplate.CityIds)) // { // string[] cityIdList = item.PoolTemplate.CityIds.Split(","); // int counter = 0; // foreach (var id in cityIdList) // { // if (counter < 1) // { // item.PoolTemplate.CityIds = CityList.Where(x => x.Id == Convert.ToInt64(id)).SingleOrDefault().Name; // } // else // { // item.PoolTemplate.CityIds = item.PoolTemplate.CityIds + "," + CityList.Where(x => x.Id == Convert.ToInt64(id)).SingleOrDefault().Name; // } // counter++; // } // } // var pool = PoolList.Where(x => x.Id == tblPoolSurveys[i].PoolTemplate.Id).SingleOrDefault(); // PoolList.Remove(pool); // list.Add(item); //} ViewBag.PoolList = PoolList; return(View(tblPoolSurveys)); }