Exemple #1
0
 private void EditEquipment(Type equipmentType, bool isNew)
 {
     if (equipmentType == typeof(Telescope))
     {
         var vm = ViewManager.CreateViewModel <TelescopeVM>();
         vm.Telescopes = Telescopes;
         if (!isNew)
         {
             vm.Telescope.CopyFrom(Telescope);
         }
         if (ViewManager.ShowDialog(vm) ?? false)
         {
             if (isNew)
             {
                 Telescopes.Add(vm.Telescope);
             }
             TelescopeId = Guid.Empty;
             TelescopeId = vm.Telescope.Id;
             Telescope.CopyFrom(vm.Telescope);
             _Equipment.Telescopes = new ObservableCollection <Telescope>(Telescopes.OrderBy(t => t.Name));
             NotifyPropertyChanged(nameof(Telescopes), nameof(TelescopeId), nameof(Telescope));
             Calculate();
             SaveEquipment();
         }
     }
     else if (equipmentType == typeof(Eyepiece))
     {
         var vm = ViewManager.CreateViewModel <EyepieceVM>();
         vm.Eyepieces = Eyepieces;
         if (!isNew)
         {
             vm.Eyepiece.CopyFrom(Eyepiece);
         }
         if (ViewManager.ShowDialog(vm) ?? false)
         {
             if (isNew)
             {
                 Eyepieces.Add(vm.Eyepiece);
             }
             EyepieceId = Guid.Empty;
             EyepieceId = vm.Eyepiece.Id;
             Eyepiece.CopyFrom(vm.Eyepiece);
             _Equipment.Eyepieces = new ObservableCollection <Eyepiece>(Eyepieces.OrderBy(t => t.Name));
             NotifyPropertyChanged(nameof(Eyepieces), nameof(EyepieceId), nameof(Eyepiece));
             Calculate();
             SaveEquipment();
         }
     }
     else if (equipmentType == typeof(Camera))
     {
         var vm = ViewManager.CreateViewModel <CameraVM>();
         vm.Cameras = Cameras;
         if (!isNew)
         {
             vm.Camera.CopyFrom(Camera);
         }
         if (ViewManager.ShowDialog(vm) ?? false)
         {
             if (isNew)
             {
                 Cameras.Add(vm.Camera);
             }
             CameraId = Guid.Empty;
             CameraId = vm.Camera.Id;
             Camera.CopyFrom(vm.Camera);
             _Equipment.Cameras = new ObservableCollection <Camera>(Cameras.OrderBy(t => t.Name));
             NotifyPropertyChanged(nameof(Cameras), nameof(CameraId), nameof(Camera));
             Calculate();
             SaveEquipment();
         }
     }
     else if (equipmentType == typeof(Binocular))
     {
         var vm = ViewManager.CreateViewModel <BinocularVM>();
         vm.Binoculars = Binoculars;
         if (!isNew)
         {
             vm.Binocular.CopyFrom(Binocular);
         }
         if (ViewManager.ShowDialog(vm) ?? false)
         {
             if (isNew)
             {
                 Binoculars.Add(vm.Binocular);
             }
             BinocularId = Guid.Empty;
             BinocularId = vm.Binocular.Id;
             Binocular.CopyFrom(vm.Binocular);
             _Equipment.Binoculars = new ObservableCollection <Binocular>(Binoculars.OrderBy(t => t.Name));
             NotifyPropertyChanged(nameof(Binoculars), nameof(BinocularId), nameof(Binocular));
             Calculate();
             SaveEquipment();
         }
     }
 }