示例#1
0
        public async Task <Result <Accommodation> > Get(string supplier, string supplierAccommodationCode,
                                                        string languageCode)
        {
            var searchJson    = "{" + $"\"{supplier}\":\"{supplierAccommodationCode}\"" + "}";
            var accommodation = await _context.Accommodations
                                .Where(ac => ac.IsActive && EF.Functions.JsonContains(ac.SupplierAccommodationCodes, searchJson))
                                .Select(ac => new
            {
                Id             = ac.Id,
                CountryId      = ac.CountryId,
                LocalityId     = ac.LocalityId,
                LocalityZoneId = ac.LocalityZoneId,
                Data           = ac.FinalAccommodation,
                SupplierCodes  = ac.SupplierAccommodationCodes,
                Modified       = ac.Modified
            })
                                .SingleOrDefaultAsync();

            if (accommodation == null)
            {
                return(Result.Failure <Accommodation>("Accommodation does not exists"));
            }

            return(AccommodationConverter.Convert(accommodation.Id, accommodation.CountryId,
                                                  accommodation.LocalityId, accommodation.LocalityZoneId,
                                                  accommodation.Data, languageCode, accommodation.SupplierCodes, accommodation.Modified));
        }
示例#2
0
        public async Task <List <Accommodation> > Get(int skip, int top, IEnumerable <string> suppliersFilter,
                                                      bool?hasDirectContractFilter, DateTimeOffset?modifiedDate, string languageCode)
        {
            var suppliersKeys       = suppliersFilter.ToArray();
            var accommodationsQuery = _context.Accommodations
                                      .Where(ac => ac.IsActive);

            if (modifiedDate.HasValue)
            {
                accommodationsQuery = accommodationsQuery.Where(a => a.Modified > modifiedDate);
            }

            if (suppliersKeys.Any())
            {
                accommodationsQuery = accommodationsQuery.Where(ac
                                                                => EF.Functions.JsonExistAny(ac.SupplierAccommodationCodes, suppliersKeys));
            }

            if (hasDirectContractFilter != null)
            {
                accommodationsQuery =
                    accommodationsQuery.Where(ac => ac.HasDirectContract == hasDirectContractFilter.Value);
            }

            accommodationsQuery = accommodationsQuery
                                  .OrderBy(ac => ac.Id)
                                  .Skip(skip)
                                  .Take(top);

            var accommodations = await accommodationsQuery
                                 .Select(ac => new
            {
                Id             = ac.Id,
                CountryId      = ac.CountryId,
                LocalityId     = ac.LocalityId,
                LocalityZoneId = ac.LocalityZoneId,
                Data           = ac.FinalAccommodation,
                SupplierCodes  = ac.SupplierAccommodationCodes,
                ModifiedDate   = ac.Modified
            })
                                 .ToListAsync();

            return(accommodations.Select(ac
                                         => AccommodationConverter.Convert(ac.Id, ac.CountryId, ac.LocalityId, ac.LocalityZoneId, ac.Data,
                                                                           languageCode, ac.SupplierCodes, ac.ModifiedDate))
                   .ToList());
        }
示例#3
0
        public async Task <Result <Accommodation> > Get(string htId, string languageCode)
        {
            var accommodations = await GetRichDetails(new List <string> {
                htId
            });

            var accommodation = accommodations.SingleOrDefault();

            if (accommodation == default)
            {
                return(Result.Failure <Accommodation>("Accommodation does not exists"));
            }

            return(AccommodationConverter.Convert(accommodation.Id, accommodation.CountryId,
                                                  accommodation.LocalityId, accommodation.LocalityZoneId, accommodation.FinalAccommodation,
                                                  languageCode, accommodation.SupplierAccommodationCodes,
                                                  accommodation.Modified));
        }