Esempio n. 1
0
        public async Task <IEnumerable <VendorShortDto> > GetAllFromLocationAsync()
        {
            var user = await _userService.GetProfileAsync();

            var vendors = await _vendorRepository.GetAllAsync();

            var result = new List <Vendor>();

            foreach (var vendor in vendors)
            {
                var countryCities = vendor.Addresses
                                    .GroupBy(a => a.CountryId)
                                    .Select(g =>
                                            new KeyValuePair <Guid, IEnumerable <Guid?> >(
                                                g.Key, g.Select(a => a.CityId).Where(i => i.HasValue)))
                                    .ToDictionary(a => a.Key, a => a.Value);

                if (countryCities.ContainsKey(user.Address.CountryId) && (!countryCities[user.Address.CountryId].Any() ||
                                                                          countryCities[user.Address.CountryId]
                                                                          .Contains(user.Address.CityId)))
                {
                    result.Add(vendor);
                }
            }

            return(_mapper.Map <IEnumerable <VendorShortDto> >(result));
        }
Esempio n. 2
0
        public async Task <IEnumerable <VendorDto> > GetAllVendorsAsync(CancellationToken cancellationToken)
        {
            var vendors = await _vendorRepository.GetAllAsync(cancellationToken);

            var vendorDtos = _mapper.Map <IEnumerable <VendorDto> >(vendors);

            return(vendorDtos);
        }
Esempio n. 3
0
        public async Task <IEnumerable <VendorDTO> > GetVendorsAsync()
        {
            var vendors = await _vendorRepository.GetAllAsync();

            var vendorDTOs = _mapper.Map <VendorDTO[]>(vendors);

            for (int i = 0; i < vendorDTOs.Length; i++)
            {
                await AddRatingAndTicketCountToVendorAsync(vendorDTOs[i]);
            }

            return(vendorDTOs);
        }
Esempio n. 4
0
        public async Task ReindexAsync()
        {
            await SearchRepository.RemoveAllAsync();

            var vendors = await _vendorRepository.GetAllAsync();

            var allDiscounts = await _discountRepository.GetAllAsync();

            var vendorsDto = vendors.GroupJoin(
                allDiscounts,
                vendor => vendor.Id,
                discount => discount.VendorId,
                (vendor, discounts) =>
            {
                var vendorDto       = _mapper.Map <VendorDto>(vendor);
                vendorDto.Discounts = _mapper.Map <IEnumerable <DiscountShortDto> >(discounts);
                return(vendorDto);
            });

            var searchList = await GetAllSearchAsync(vendorsDto);

            await SearchRepository.CreateManyAsync(searchList);
        }
        public async Task <ActionResult <List <VendorDto> > > Get()
        {
            var result = await _vendorRepository.GetAllAsync();

            return(result);
        }