예제 #1
0
 public string AddCountry(CountryWithDetails country)
 {
     try
     {
         if (country.Id <= 0)
         {
             return("Id cannot be lower than 1");
         }
         XDocument xmlDoc;
         if (!File.Exists(_fileLocalization))
         {
             xmlDoc = new XDocument(new XElement("countries"));
             Directory.CreateDirectory(Path.GetDirectoryName(_fileLocalization));
         }
         else
         {
             xmlDoc = XDocument.Load(_fileLocalization);
         }
         if (xmlDoc.Root.Elements("country").Any(x => int.Parse(x.Element("id").Value) == country.Id))
         {
             return("Country with this id currently exists");
         }
         XElement root = new XElement("country");
         root.Add(new XElement("id", country.Id));
         root.Add(new XElement("name", country.Name));
         root.Add(new XElement("capital", country.Capital));
         root.Add(new XElement("areacode", country.AreaCode));
         xmlDoc.Element("countries").Add(root);
         xmlDoc.Save(_fileLocalization);
         return("Country Added");
     }
     catch (Exception ex)
     {
         //Log Exception
         return("Unable to Add country");
     }
 }
예제 #2
0
 public string AddCountry(CountryWithDetails country)
 {
     return(_dataManager.AddCountry(country));
 }