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); }
private async Task <PostServiceViewModel> MapViewModel( Service serv, AppUser user, Provider provider) { var query = await _serviceRepository.FindAllAsync(); var providerService = await _providerServiceRepository.FindAllAsync(); var userService = await _userServiceRepository.FindAllAsync(); var providers = await _providerRepository.FindAllAsync(); var getTag = await _tagRepository.FindAllAsync(); var getUserTag = await _tagServiceRepository.FindAllAsync(x => x.ServiceId == serv.Id); var getListTag = (from tag in getTag.ToList() join serviceTag in getUserTag.ToList() on tag.Id equals serviceTag.TagId select new { tag.TagName }).ToList(); var getImage = await _imageRepository.FindAllAsync(x => x.ServiceId == serv.Id); PostServiceViewModel postServiceView = new PostServiceViewModel(); postServiceView.Id = serv.Id.ToString(); postServiceView.listImages = getImage.Select(x => new PostServiceImageViewModel { Path = x.Path, ImageId = x.Id }).ToList(); postServiceView.PriceOfService = serv.PriceOfService; postServiceView.CategoryName = _getByIDCategoryServiceQuery.ExecuteAsync(serv.CategoryId).Result.CategoryName; postServiceView.ServiceName = serv.ServiceName; postServiceView.Status = serv.Status; postServiceView.tagofServices = getListTag.Select(x => new TagofServiceViewModel { TagName = x.TagName }).ToList(); postServiceView.Description = serv.Description; postServiceView.ProviderId = _getProviderInformationQuery.ExecuteAsync(serv.Id, query, providers, providerService).idProvider == "" ? _getUserInformationQuery.ExecuteAsync(serv.Id, query, userService) : _getProviderInformationQuery.ExecuteAsync(serv.Id, query, providers, providerService).idProvider; postServiceView.CategoryId = serv.CategoryId; postServiceView.Author = _getProviderInformationQuery.ExecuteAsync(serv.Id, query, providers, providerService).NameProvider == "" ? _getUserInformationQuery.ExecuteAsync(serv.Id, query, userService) : _getProviderInformationQuery.ExecuteAsync(serv.Id, query, providers, providerService).NameProvider; return(postServiceView); }
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 }); } }