public async Task <IActionResult> Index(ProductGroupDependenciesSearchViewModel searchModel) { var model = await _productGroupDependenciesRepository.LoadAsyncCount( this.CurrentPage, this.PageSize, searchModel); var featureIds = model.Item2.Select(x => x.Feature1.Value).ToList(); featureIds.AddRange(model.Item2.Select(x => x.Feature2).ToList()); ViewBag.featureValueSelected = await _featureItemRepository.GetListAsync(x => featureIds.Contains(x.FeatureId)); this.TotalNumber = model.Item1; ViewBag.SearchModel = searchModel; ViewBag.ProductGroups = await _productGroupRepository.GetAllAsync(); ViewBag.Products = await _featureRepository.GetAllAsync(); return(View(model.Item2)); }
public async Task <Tuple <int, List <ProductGroupDependenciesFullDTO> > > LoadAsyncCount( int skip = -1, int take = -1, ProductGroupDependenciesSearchViewModel model = null) { var query = (from productGroupDependencies in DbContext.ProductGroupDependencies // ارتباط برای گروه وابسته join productGroup1 in DbContext.ProductGroup on productGroupDependencies.GroupId1 equals productGroup1.Id // برای ویژگی از جدول وابسته join feature1 in DbContext.Feature on productGroupDependencies.Feature1 equals feature1.Id //join featureItem1 in DbContext.FeatureItem on feature1.Id equals featureItem1.FeatureId //where featureItem1.Id == productGroupDependencies.Value1 // ارتباط برای جدولی که وابستگی به آن است join productGroup2 in DbContext.ProductGroup on productGroupDependencies.GroupId2 equals productGroup2.Id // برای ویژگی از جدول وابسته join feature2 in DbContext.Feature on productGroupDependencies.Feature2 equals feature2.Id select new ProductGroupDependenciesFullDTO { Id = productGroupDependencies.Id, Title = productGroupDependencies.Title, #region جدول اول GroupId1 = productGroupDependencies.GroupId1, GroupId1Title = productGroup1.Title, Feature1 = productGroupDependencies.Feature1, Feature1Title = feature1.Title, Value1 = productGroupDependencies.Value1, //FeatureValueSelected = (featureItem1.Value == ) #endregion #region جدول دوم GroupId2 = productGroupDependencies.GroupId2, GroupId2Title = productGroup2.Title, Feature2 = productGroupDependencies.Feature2, Feature2Title = feature2.Title, Value2 = productGroupDependencies.Value2, #endregion ConditionId = productGroupDependencies.ConditionId, ConditionTitle = productGroupDependencies.Condition.Title }); // شرط if (model.ConditionId != null) { query = query.Where(x => x.ConditionId == model.ConditionId); } if (!string.IsNullOrEmpty(model.Title)) { query = query.Where(x => x.Title.Contains(model.Title)); } #region جستجو در آیتمهای مربوط به گروه اول if (model.GroupId1 != null) { query = query.Where(x => x.GroupId1 == model.GroupId1); } if (model.Feature1 != null) { query = query.Where(x => x.Feature1 == model.Feature1); } if (!string.IsNullOrEmpty(model.Value1)) { query = query.Where(x => x.Value1.Contains(model.Value1)); } #endregion #region جستجو در آیتمهای مربوط به گروه دوم if (model.GroupId2 != null) { query = query.Where(x => x.GroupId2 == model.GroupId2); } if (model.Feature2 != null) { query = query.Where(x => x.Feature2 == model.Feature2); } if (!string.IsNullOrEmpty(model.Value2)) { query = query.Where(x => x.Value2.Contains(model.Value2)); } #endregion int Count = query.Count(); query = query.OrderByDescending(x => x.Id); if (skip != -1) { query = query.Skip((skip - 1) * take); } if (take != -1) { query = query.Take(take); } return(new Tuple <int, List <ProductGroupDependenciesFullDTO> >(Count, await query.ToListAsync())); }