private async Task <List <ListServiceViewModel> > FilterByTag(IEnumerable <Service> service, string filterName, IEnumerable <Provider> provider, IEnumerable <Model.Entities.ServiceModel.ProviderServiceModel.ProviderService> provideService, IEnumerable <Model.Entities.ServiceModel.UserServiceModel.UserService> userService, IEnumerable <ServiceImage> getAvatar, IEnumerable <Tag> getAllTag, IEnumerable <Model.Entities.ServiceModel.TagService> getAllServiceTag, IEnumerable <ServiceRating> allRating) { var category = await _getAllAsyncCategoryServiceQuery.ExecuteAsync(); var query = (from tag in getAllTag.ToList() join userTag in getAllServiceTag.ToList() on tag.Id equals userTag.TagId join serv in service on userTag.ServiceId equals serv.Id where tag.TagName != null && tag.TagName == filterName && serv.Status == Model.Enums.Status.Active select new ListServiceViewModel { Id = serv.Id, CategoryName = category.Where(x => x.Id == serv.CategoryId).Select(x => x.CategoryName).FirstOrDefault(), Author = _getProviderInformationQuery.ExecuteAsync(serv.Id, service, provider, provideService).NameProvider == "" ? _getUserInformationQuery.ExecuteAsync(serv.Id, service, userService) : _getProviderInformationQuery.ExecuteAsync(serv.Id, service, provider, provideService).NameProvider, Status = serv.Status, isProvider = _getProviderInformationQuery.ExecuteAsync(serv.Id, service, provider, provideService).NameProvider == "" ? false : true, AvtService = _getAvtInformationQuery.ExecuteAsync(serv.Id, getAvatar), PriceOfService = serv.PriceOfService.ToString(), TagList = _getListTagInformationQuery.ExecuteAsync(serv.Id, getAllServiceTag, getAllTag), ServiceName = serv.ServiceName, Rating = _getServiceRatingQuery.ExecuteAsync(serv.Id, allRating) }).OrderByDescending(x => x.Rating).ToList(); return(query); }
public async Task <PagedResult <PostServiceViewModel> > ExecuteAsync(string keyword, int page, int pageSize, bool isAdminPage, int filter) { try { var query = await _serviceRepository.FindAllAsync(); //Get provider information var provider = await _providerRepository.FindAllAsync(); var provideService = await _providerServiceRepository.FindAllAsync(); //Get user information var userService = await _userServiceRepository.FindAllAsync(); //Get image var getAvatar = await _imageRepository.FindAllAsync(x => x.isAvatar == true); //Get all tag var getAllTag = await _tagRepository.FindAllAsync(); var getAllServiceTag = await _tagServiceRepository.FindAllAsync(); //var joinTag //Get allRating var allRating = await _ratingRepository.FindAllAsync(); //Get Category var getAllCateogry = await _getAllAsyncCategoryServiceQuery.ExecuteAsync(); if (!string.IsNullOrEmpty(keyword)) { var listViewModel = await MappingTagService(query, keyword, provider, provideService, userService, getAvatar, getAllTag, getAllServiceTag, allRating); int totalRowSearch = listViewModel.Count(); if (pageSize != 0) { listViewModel = listViewModel.Skip((page - 1) * pageSize).Take(pageSize).ToList(); } return(new PagedResult <PostServiceViewModel> { Results = isAdminPage == true ? listViewModel : listViewModel.Where(x => x.Status == Model.Enums.Status.Active).ToList(), CurrentPage = page, RowCount = totalRowSearch, PageSize = pageSize }); } int totalRow = query.Count(); if (pageSize != 0) { query = query.Skip((page - 1) * pageSize).Take(pageSize); } var data = query.Select(x => new PostServiceViewModel { Id = x.Id.ToString(), CategoryName = getAllCateogry.Where(t => t.Id == x.CategoryId).Select(x => x.CategoryName).FirstOrDefault(), Author = _getProviderInformationQuery.ExecuteAsync(x.Id, query, provider, provideService).NameProvider == "" ? _getUserInformationQuery.ExecuteAsync(x.Id, query, userService) : _getProviderInformationQuery.ExecuteAsync(x.Id, query, provider, provideService).NameProvider, Status = x.Status, AvtService = _getAvtInformationQuery.ExecuteAsync(x.Id, getAvatar), PriceOfService = x.PriceOfService.ToString(), TagList = _getListTagInformationQuery.ExecuteAsync(x.Id, getAllServiceTag, getAllTag).ToString(), ServiceName = x.ServiceName, Description = x.Description, CategoryId = x.CategoryId, Rating = _getServiceRatingQuery.ExecuteAsync(x.Id, allRating), listImages = _imageRepository.FindAllAsync(t => t.ServiceId == x.Id).Result.Select(z => new PostServiceImageViewModel { Path = z.Path, ImageId = z.Id, IsAvatar = z.isAvatar }).ToList(), tagofServices = JoinTag(getAllTag, getAllServiceTag, x.Id), IsProvider = _getProviderInformationQuery.ExecuteAsync(x.Id, query, provider, provideService).NameProvider == "" ? false : true, ProviderId = _getProviderInformationQuery.ExecuteAsync(x.Id, query, provider, provideService).NameProvider == "" ? "" : _getProviderInformationQuery.ExecuteAsync(x.Id, query, provider, provideService).idProvider, }).OrderByDescending(x => x.Rating).ToList(); if (isAdminPage == false) { data = data.Where(x => x.Status == Model.Enums.Status.Active).ToList(); } int filtering = filter; switch (filtering) { case 1: data = data.Where(x => x.Status == Model.Enums.Status.Active).ToList(); break; case 0: data = data.Where(x => x.Status == Model.Enums.Status.InActive).ToList(); break; case 2: data = data.Where(x => x.Status == Model.Enums.Status.Pending).ToList(); break; } var paginationSet = new PagedResult <PostServiceViewModel>() { Results = isAdminPage == true ? data : data.Where(x => x.Status == Model.Enums.Status.Active).ToList(), CurrentPage = page, RowCount = totalRow, PageSize = pageSize }; return(paginationSet); } catch (System.Exception) { return(new PagedResult <PostServiceViewModel>() { Results = null, CurrentPage = page, RowCount = 0, PageSize = pageSize }); } }