Пример #1
0
        public static Currency changeFromDTM(CurrencyDTM currencyDtm)
        {
            Currency currency = new Currency();

            currency.Id   = currencyDtm.Id;
            currency.Name = currencyDtm.Name;
            return(currency);
        }
Пример #2
0
        public void WriteCountryData()
        {
            var                 myCountries    = File.ReadAllText(@"Country.json");
            JObject             countries      = JObject.Parse(myCountries);
            JArray              countriesArray = (JArray)countries["results"];
            IList <CountryRead> countriesList  = countriesArray.ToObject <IList <CountryRead> >();

            for (int i = 0; i < countriesList.Count; i++)
            {
                CountryDTM c = new CountryDTM();
                c.Code        = countriesList[i].code;
                c.Name        = countriesList[i].name;
                c.Native      = countriesList[i].native;
                c.PhonePrefix = countriesList[i].phone;
                c.Capital     = countriesList[i].capital;
                c.Currency_   = countriesList[i].currency;
                c.Emoji       = countriesList[i].emoji;
                c.EmojiU      = countriesList[i].emojiU;

                CountriesListDtm.Add(c);
            }

            //Timezone
            var            myZones    = File.ReadAllText(@"Timezone_Time_Zones_Dataset.json");
            JObject        zones      = JObject.Parse(myZones);
            JArray         zonesArray = (JArray)zones["results"];
            IList <TZRead> zonesList  = zonesArray.ToObject <IList <TZRead> >();

            for (int i = 0; i < zonesList.Count; i++)
            {
                Time_zoneDTM t = new Time_zoneDTM();
                t.Zone           = zonesList[i].TimeZone;
                t.CountryCode    = zonesList[i].CountryCode;
                t.UTC_Jan_1_2020 = zonesList[i].UTC_Jan_1_2020;
                t.DST_Jul_1_2020 = zonesList[i].DST_Jul_1_2020;

                ZonesListDtm.Add(t);
            }

            //Currencies
            List <string> tempList = new List <string>();

            foreach (CountryDTM c in CountriesListDtm)
            {
                if (!tempList.Contains(c.Currency_) && c.Currency_ != "")
                {
                    tempList.Add(c.Currency_);
                }
            }
            foreach (var curLine in tempList)
            {
                CurrencyDTM cur = new CurrencyDTM();
                cur.Name = curLine;
                CurrenciesLidtDtm.Add(cur);
            }
        }
Пример #3
0
        public static CurrencyDTM changeToDTM(Currency currency)
        {
            CurrencyDTM currencyDtm = new CurrencyDTM
            {
                Id   = currency.Id,
                Name = currency.Name,
            };

            return(currencyDtm);
        }
Пример #4
0
        public static BusinessDTM changeToDTM(Business business)
        {
            BusinessDTM bDtm = new BusinessDTM();

            bDtm.Id                 = business.Id;
            bDtm.Name               = business.Name;
            bDtm.Phone              = business.Phone;
            bDtm.Logo               = business.Logo;
            bDtm.Webpage            = business.Webpage;
            bDtm.Address            = business.Address;
            bDtm.City               = business.City;
            bDtm.State              = business.State;
            bDtm.ZipCode            = business.ZipCode;
            bDtm.RegistrationNumber = business.RegistrationNumber;

            if (business.Country != null)
            {
                CountryDTM country = new CountryDTM();
                country.Id          = business.Country.Id;
                country.Code        = business.Country.Code;
                country.Name        = business.Country.Name;
                country.Native      = business.Country.Native;
                country.PhonePrefix = business.Country.PhonePrefix;
                country.Capital     = business.Country.Capital;
                country.Currency_   = business.Country.Currency_;
                country.Emoji       = business.Country.Emoji;
                country.EmojiU      = business.Country.EmojiU;
                bDtm.Country        = country;
                bDtm.CountryId      = business.Country.Id;
            }
            if (business.Currency != null)
            {
                CurrencyDTM currency = new CurrencyDTM();
                currency.Id     = business.Currency.Id;
                currency.Name   = business.Currency.Name;
                bDtm.Currency   = currency;
                bDtm.CurrencyId = business.Currency.Id;
            }
            if (business.Time_zone != null)
            {
                Time_zoneDTM tz = new Time_zoneDTM();
                tz.Id             = business.Time_zone.Id;
                tz.Zone           = business.Time_zone.Zone;
                tz.CountryCode    = business.Time_zone.CountryCode;
                tz.UTC_Jan_1_2020 = business.Time_zone.UTC_Jan_1_2020;
                tz.DST_Jul_1_2020 = business.Time_zone.DST_Jul_1_2020;
                bDtm.Time_zone    = tz;
                bDtm.Time_zoneId  = business.Time_zone.Id;
            }
            return(bDtm);
        }
        public async Task <List <BusinessDTM> > GetAll(SearchParams search)
        {
            //var config = new MapperConfiguration(cfg => {
            //    cfg.CreateMap<Business, BusinessDTM>();
            //    cfg.CreateMap<Country, CountryDTM>();
            //    cfg.CreateMap<Currency, CurrencyDTM>();
            //    cfg.CreateMap<Time_zone, Time_zoneDTM>();
            //    cfg.CreateMap<Booking, BookingDTM>();
            //});
            //var mapper = new Mapper(config);
            //return await Task.Run(() => (mapper.Map<List<BusinessDTM>>(
            //    Database.Businesses.GetAll()
            //   .OrderBy(u => u.Name)
            //   .Skip(search.PageSize * search.Page)
            //   .Take(search.PageSize))));
            //return mapper.Map<List<BusinessDTM>>(
            //       Database.Businesses.GetAll()
            //      .OrderBy(u => u.Name)
            //      .Skip(search.PageSize * search.Page)
            //      .Take(search.PageSize));
            List <BusinessDTM> bListDtm = new List <BusinessDTM>();
            List <Business>    bList    = Database.Businesses.GetAll()
                                          .OrderBy(u => u.Name)
                                          .Skip(search.PageSize * search.Page)
                                          .Take(search.PageSize).ToList();

            foreach (Business b in bList)
            {
                BusinessDTM bDtm = new BusinessDTM();
                bDtm.Id                 = b.Id;
                bDtm.Name               = b.Name;
                bDtm.Phone              = b.Phone;
                bDtm.Logo               = b.Logo;
                bDtm.Webpage            = b.Webpage;
                bDtm.Address            = b.Address;
                bDtm.City               = b.City;
                bDtm.State              = b.State;
                bDtm.ZipCode            = b.ZipCode;
                bDtm.RegistrationNumber = b.RegistrationNumber;

                bDtm.CountryId   = b.Country.Id;
                bDtm.CurrencyId  = b.Currency.Id;
                bDtm.Time_zoneId = b.Time_zone.Id;

                CountryDTM country = new CountryDTM();
                country.Id          = b.Country.Id;
                country.Code        = b.Country.Code;
                country.Name        = b.Country.Name;
                country.Native      = b.Country.Native;
                country.PhonePrefix = b.Country.PhonePrefix;
                country.Capital     = b.Country.Capital;
                country.Currency_   = b.Country.Currency_;
                country.Emoji       = b.Country.Emoji;
                country.EmojiU      = b.Country.EmojiU;
                bDtm.Country        = country;

                CurrencyDTM currency = new CurrencyDTM();
                currency.Id   = b.Currency.Id;
                currency.Name = b.Currency.Name;
                bDtm.Currency = currency;

                Time_zoneDTM tz = new Time_zoneDTM();
                tz.Id             = b.Time_zone.Id;
                tz.Zone           = b.Time_zone.Zone;
                tz.CountryCode    = b.Time_zone.CountryCode;
                tz.UTC_Jan_1_2020 = b.Time_zone.UTC_Jan_1_2020;
                tz.DST_Jul_1_2020 = b.Time_zone.DST_Jul_1_2020;
                bDtm.Time_zone    = tz;

                bListDtm.Add(bDtm);
            }

            return(bListDtm);
        }
        public async Task <BusinessDTM> Get(int id)
        {
            int firstBusinessId = 1;

            if (id < firstBusinessId)
            {
                throw new ValidationException("Business id is not specified correctly", "");
            }
            var business = await Database.Businesses.Get(id);

            if (business == null)
            {
                throw new ValidationException("Business is not found", "");
            }

            BusinessDTM bDtm = new BusinessDTM();

            bDtm.Id                 = business.Id;
            bDtm.Name               = business.Name;
            bDtm.Phone              = business.Phone;
            bDtm.Logo               = business.Logo;
            bDtm.Webpage            = business.Webpage;
            bDtm.Address            = business.Address;
            bDtm.City               = business.City;
            bDtm.State              = business.State;
            bDtm.ZipCode            = business.ZipCode;
            bDtm.RegistrationNumber = business.RegistrationNumber;

            if (business.Country != null)
            {
                CountryDTM country = new CountryDTM();
                country.Id          = business.Country.Id;
                country.Code        = business.Country.Code;
                country.Name        = business.Country.Name;
                country.Native      = business.Country.Native;
                country.PhonePrefix = business.Country.PhonePrefix;
                country.Capital     = business.Country.Capital;
                country.Currency_   = business.Country.Currency_;
                country.Emoji       = business.Country.Emoji;
                country.EmojiU      = business.Country.EmojiU;
                bDtm.Country        = country;
                bDtm.CountryId      = business.Country.Id;
            }
            if (business.Currency != null)
            {
                CurrencyDTM currency = new CurrencyDTM();
                currency.Id     = business.Currency.Id;
                currency.Name   = business.Currency.Name;
                bDtm.Currency   = currency;
                bDtm.CurrencyId = business.Currency.Id;
            }
            if (business.Time_zone != null)
            {
                Time_zoneDTM tz = new Time_zoneDTM();
                tz.Id             = business.Time_zone.Id;
                tz.Zone           = business.Time_zone.Zone;
                tz.CountryCode    = business.Time_zone.CountryCode;
                tz.UTC_Jan_1_2020 = business.Time_zone.UTC_Jan_1_2020;
                tz.DST_Jul_1_2020 = business.Time_zone.DST_Jul_1_2020;
                bDtm.Time_zone    = tz;
                bDtm.Time_zoneId  = business.Time_zone.Id;
            }
            //var config = new MapperConfiguration(cfg => cfg.CreateMap<Business, BusinessDTM>());
            //var mapper = new Mapper(config);
            //return mapper.Map<BusinessDTM>(business);
            return(bDtm);
        }