예제 #1
0
파일: DbData.cs 프로젝트: vorzhev/crmguru
 private void AddCountryHandler(CountryData countryData)
 {
     using var db = new CountryContext();
     try
     {
         db.Countries.Add(new Country
         {
             Name       = countryData.countryName,
             Code       = countryData.countryCode,
             Area       = countryData.countryArea,
             Population = countryData.countryPopulation,
             Capital    = CityID == null
             ? (new City()
             {
                 Name = countryData.countryCapital
             })
             : db.Cities.Where(city => city.Name.Equals(countryData.countryCapital)).FirstOrDefault(),
             Region = RegionID == null
             ? (new Region()
             {
                 Name = countryData.countryRegion
             })
             : db.Regions.Where(region => region.Name.Equals(countryData.countryRegion)).FirstOrDefault()
         });
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         ExceptionsHandler.CallExceptionMessage(ex, "While adding a new country");
     }
 }
예제 #2
0
파일: DbData.cs 프로젝트: vorzhev/crmguru
        public void NewCountry(string countryName)
        {
            var countryData = new CountryData();

            countryData.GetData(countryName);
            RegionsHandler(countryData);
            CitiesHandler(countryData);
            using var db = new CountryContext();
            try
            {
                if (!db.Countries
                    .Any(country => country.Code.Equals(countryData.countryCode)))
                {
                    AddCountryHandler(countryData);
                }
                else
                {
                    UpdateCountryHandler(countryData);
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                ExceptionsHandler.CallExceptionMessage(ex, "Saving data");
            }
        }
예제 #3
0
파일: DbSet.cs 프로젝트: vorzhev/crmguru
 public CountryContext()
 {
     try
     {
         Database.EnsureCreated();
     }
     catch (Exception ex)
     {
         ExceptionsHandler.CallExceptionMessage(ex);
     }
 }
예제 #4
0
 private void ReadFile(string address)
 {
     try
     {
         DataText = (new WebClient()).DownloadString(address);
     }
     catch (Exception ex)
     {
         ExceptionsHandler.CallExceptionMessage(ex, "Reading the JSON");
     }
 }
예제 #5
0
파일: DbData.cs 프로젝트: vorzhev/crmguru
 private void UpdateCountryHandler(CountryData countryData)
 {
     try
     {
         using var db = new CountryContext();
         var Country = db.Countries.Where(country => country.Code.Equals(countryData.countryCode)).FirstOrDefault();
         db.Countries.Update(Country);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         ExceptionsHandler.CallExceptionMessage(ex, "While update data");
     }
 }
예제 #6
0
파일: DbData.cs 프로젝트: vorzhev/crmguru
 private void GetAllCountries()
 {
     try
     {
         using var db    = new CountryContext();
         ListOfCountries = db.Countries
                           .Include(city => city.Capital)
                           .Include(region => region.Region)
                           .ToList();
     }
     catch (Exception ex)
     {
         ExceptionsHandler.CallExceptionMessage(ex, "While getting data from the db");
     }
 }
예제 #7
0
파일: DbData.cs 프로젝트: vorzhev/crmguru
 private void RegionsHandler(CountryData countryData)
 {
     using var db = new CountryContext();
     try
     {
         if (db.Regions
             .Any(region => region.Name.Equals(countryData.countryRegion)))
         {
             RegionID = db.Regions
                        .Where(region => region.Name.Equals(countryData.countryRegion))
                        .Select(region => region.Id)
                        .FirstOrDefault();
         }
     }
     catch (Exception ex)
     {
         ExceptionsHandler.CallExceptionMessage(ex, "Handle Regions");
     }
 }
예제 #8
0
파일: DbData.cs 프로젝트: vorzhev/crmguru
 private void CitiesHandler(CountryData countryData)
 {
     try
     {
         using var db = new CountryContext();
         if (db.Cities
             .Any(city => city.Name.Equals(countryData.countryCapital)))
         {
             CityID = db.Cities
                      .Where(city => city.Name.Equals(countryData.countryCapital))
                      .Select(city => city.Id)
                      .FirstOrDefault();
         }
     }
     catch (Exception ex)
     {
         ExceptionsHandler.CallExceptionMessage(ex, "Handle Cities");
     }
 }
예제 #9
0
        public List <JsonCountry> FillCountries(string countryName)
        {
            var dataFile = new FileContext();

            dataFile.GetJson(countryName);
            try
            {
                modelRoot        = JsonConvert.DeserializeObject <List <Root> >(dataFile.DataText);
                modelJsonCountry = JsonConvert.DeserializeObject <List <JsonCountry> >(dataFile.DataText);
                //modelTranslations = JsonConvert.DeserializeObject<List<Translations>>(dataFile.DataText);
                //modelLanguage = JsonConvert.DeserializeObject<List<Language>>(dataFile.DataText);
                //modelCurrency = JsonConvert.DeserializeObject<List<Currency>>(dataFile.DataText);
            }
            catch (Exception ex)
            {
                ExceptionsHandler.CallExceptionMessage(ex, "Converting data from the JSON");
            }
            return(modelJsonCountry);
        }