Пример #1
0
 public static PedestriansInfo SaveDtoToDb(PedestrianDTO pedestrianDTO)
 {
     using (DatabaseModel dbContext = new DatabaseModel())
     {
         PedestriansInfo existingInfo = dbContext.Set <PedestriansInfo>().First(i => i.PersonsInfo.PersonId == Guid.Parse(pedestrianDTO.Id));
         if (existingInfo != null)
         {
             return(existingInfo);
         }
         PersonAccount account = new PersonAccount
         {
             Id          = Guid.Parse(pedestrianDTO.Id),
             PhoneNumber = pedestrianDTO.PhoneNumber,
             SkypeNumber = pedestrianDTO.SkypeNumber
         };
         dbContext.Set <PersonAccount>().Attach(account);
         dbContext.Set <PersonAccount>().Add(account);
         PersonsInfo personInfo = new PersonsInfo
         {
             Altitude  = pedestrianDTO.Altitude,
             Longitude = pedestrianDTO.Longitude,
             Latitude  = pedestrianDTO.Latitude,
             CityId    = pedestrianDTO.CityId,
             PersonId  = account.Id
         };
         dbContext.Set <PersonsInfo>().Attach(personInfo);
         dbContext.Set <PersonsInfo>().Add(personInfo);
         PedestrianAccount pedestrianAccount = new PedestrianAccount
         {
             PersonId = account.Id
         };
         dbContext.Set <PedestrianAccount>().Attach(pedestrianAccount);
         dbContext.Set <PedestrianAccount>().Add(pedestrianAccount);
         PedestriansInfo pedestrianInfo = new PedestriansInfo
         {
             PersonInfo = personInfo.Id
         };
         dbContext.Set <PedestriansInfo>().Attach(pedestrianInfo);
         dbContext.Set <PedestriansInfo>().Add(pedestrianInfo);
         dbContext.SaveChanges();
         return(pedestrianInfo);
     }
 }
Пример #2
0
 public PersonsInfoViewModel(PersonsInfo personsInfo)
 {
     SaveInfoCommand = new RelayCommand <object>(o =>
     {
         personsInfo.Persons = EncodeInfo(o as string);
         personsInfo.SaveInfo();
     }, o =>
     {
         string info = DecodeInfo(personsInfo.Persons);
         return((o as string)?.Trim() != info.Trim());
     });
     personsInfo.PropertyChanged += (o, e) =>
     {
         if (e.PropertyName == "Persons")
         {
             Info = DecodeInfo((o as PersonsInfo).Persons);
         }
     };
     personsInfo.LoadInfo();
 }
Пример #3
0
        private void OnXmlGenerate(object sender, System.Windows.RoutedEventArgs e)
        {
            NodeCollection childs = new Persons("Vinayaka");

            childs.Initialize();
            childs.Add(new Person()
            {
                Name = "Son of ----"
            });
            PersonsInfo info = new PersonsInfo();

            info.Persons.Add(childs);
            Stream stream = null;

            using (stream = File.Open("sample.xml", FileMode.Create))
            {
                TextWriter    writer     = new StreamWriter(stream);
                XmlSerializer serializer = new XmlSerializer(typeof(PersonsInfo));
                serializer.Serialize(writer, info);
                writer.Close();
                Output.Content = "File Created";
            }
        }