public async Task <VendorDto> GetByIdAsync(Guid id) { var vendor = await _vendorRepository.GetByIdAsync(id); var vendorDiscounts = (await _discountService.GetAllAsync()) .Where(d => d.VendorId == id); return(GetVendorDto(vendor, vendorDiscounts)); }
public async Task <VendorDTO> GetVendorByIdAsync(int id) { var vendor = await _vendorRepository.GetByIdAsync(id); var vendorDTO = _mapper.Map <VendorDTO>(vendor); await AddRatingAndTicketCountToVendorAsync(vendorDTO); return(vendorDTO); }
public async Task <bool> VendorFromLocationAsync(Guid vendorId, CancellationToken token) { var user = await _userService.GetProfileAsync(); var vendor = await _vendorRepository.GetByIdAsync(vendorId); 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); return(countryCities.ContainsKey(user.Address.CountryId) && (!countryCities[user.Address.CountryId].Any() || countryCities[user.Address.CountryId] .Contains(user.Address.CityId))); }
public async Task <VendorDto> GetVendorByIdAsync(Guid id, CancellationToken cancellationToken) { if (id == Guid.Empty) { throw new ArgumentNullException("", Resources.IdentifierIsNull); } var result = await _vendorRepository.GetByIdAsync(id, cancellationToken); return(result is null ? throw new ArgumentException("", Resources.FindbyIdError) : _mapper.Map <VendorDto>(result)); }
public async Task <DiscountViewModel> CreateDiscountWithPointOfSalesAndTagsAsync(DiscountViewModel discountViewModel) { using var transaction = await _discountRepository.BeginTrancation(); try { var discount = _mapper.Map <Discount>(discountViewModel); var vendorDiscount = await _vendorRepository.GetByIdAsync(discountViewModel.VendorId.Value); var tags = await _tagRepository.GetTagsAndCreateIfNotExistAsync(discountViewModel.Tags); var pointOfSales = _mapper.Map <PointOfSale[]>(discountViewModel.PointOfSales); var resultPointOfSales = await _pointOfSaleService.GetPointOfSalesAndCreateIfNotExistAsync(pointOfSales); discount.VendorId = vendorDiscount.Id; discount.Vendor = vendorDiscount; discount.Tags = tags; discount.PointOfSales = resultPointOfSales; discount.StartDate = discountViewModel.StartDate.Value.AddHours(12).Date; discount.EndDate = discountViewModel.EndDate.Value.AddHours(12).Date; await _discountRepository.CreateAsync(discount); await _discountRepository.SaveChangesAsync(); var createDiscountViewModel = _mapper.Map <DiscountViewModel>(discount); createDiscountViewModel.Tags = discountViewModel.Tags; createDiscountViewModel.PointOfSales = _mapper.Map <PointOfSaleViewModel[]>(resultPointOfSales); await transaction.CommitAsync(); return(createDiscountViewModel); } catch { await transaction.RollbackAsync(); throw; } }
public async Task <DiscountExtendedDto> GetByIdAsync(Guid id) { var discount = await _discountRepository.GetByIdAsync(id); var vendor = await _vendorRepository.GetByIdAsync(discount.VendorId); var discountDto = _mapper.Map <DiscountExtendedDto>(discount); discountDto.IsFavorite = await _favoritesService.DiscountIsInFavorites(discountDto.Id); discountDto.Links = _mapper.Map <IEnumerable <LinkDto> >(vendor.Links); discountDto.WorkingHours = vendor.WorkingHours; discountDto.Phones = _mapper.Map <IEnumerable <PhoneDto> >(vendor.Phones.Join( discount.PhonesIds, p => p.Id, i => i, (p, i) => p)); return(discountDto); }
public async Task <ActionResult <VendorDto> > Get(Guid id) { var result = await _vendorRepository.GetByIdAsync(id); return(result); }
public async Task <Vendor> GetByIdAsync(long id) { return(await _vendorRepository.GetByIdAsync(id)); }