public AddSoftwareViewModel(IDeviceRelatedRepository repo)
        {
            Repository = repo;

            AvailableSoftwareTypes = Repository.AllSoftwareTypes.Where(
                st =>
            {
                foreach (var software in Repository.GetAllDeviceSoftware(SelectedDevice))
                {
                    if (st.ID == software.Type.ID)
                    {
                        return(false);
                    }
                }
                return(true);
            }
                ).ToObservableCollection();

            try { SelectedSoftwareType = AvailableSoftwareTypes.First(); }
            catch (Exception)
            {
                MessageToUser         = "******";
                CanAdditionBeExecuted = false;
            }

            AddSoftwareCommand = RegisterCommandAction(
                (obj) =>
            {
                try
                {
                    AddSoftwareToDevice();
                    RemoveChosenSoftwareTypeFromList();
                    PickFirstSoftwareTypeInList();

                    MessageToUser = "******";

                    Login    = string.Empty;
                    Password = string.Empty;
                    AdditionalInformation = string.Empty;
                }
                catch
                {
                    MessageToUser = "******";
                    Repository.RemoveSoftware(_newSoftware);
                }
            },
                (obj) => SelectedSoftwareType != null && CanAdditionBeExecuted
                );

            DeviceEvents.OnSoftwareAdded += (software) =>
            {
            };
        }
예제 #2
0
        public SoftwareListViewModel(IDeviceRelatedRepository repo)
        {
            Repository = repo;

            ShowAddSoftwareViewCommand = RegisterCommandAction(
                (obj) =>
            {
                var _addSoftwareView         = new AddSoftwareView();
                _addSoftwareView.DataContext = ResolveDependency <IAddSoftwareViewModel>()
                                               as AddSoftwareViewModel;
                _addSoftwareView.ShowDialog();
            },
                (obj) => SelectedDevice != null
                );

            ShowEditSoftwareViewCommand = RegisterCommandAction(
                (obj) =>
            {
                var _editSoftwareView         = new EditSoftwareInfoView();
                _editSoftwareView.DataContext = ResolveDependency <IEditSoftwareInfoViewModel>()
                                                as EditSoftwareInfoViewModel;
                _editSoftwareView.ShowDialog();
            },
                (obj) => SelectedSoftware != null
                );

            RemoveSoftwareCommand = RegisterCommandAction(
                (obj) =>
            {
                Repository.RemoveSoftware(SelectedSoftware);
                Repository.SaveChanges();
                SelectedDeviceSoftware.Remove(SelectedSoftware);
            },
                (obj) => SelectedSoftware != null
                );

            DeviceEvents.OnDeviceSelectionChanged += (device) =>
            {
                if (device != null)
                {
                    SelectedDeviceSoftware = Repository.GetAllDeviceSoftware(
                        SelectedDevice
                        ).ToObservableCollection();
                }
            };

            DeviceEvents.OnSoftwareAdded += (software) =>
                                            SelectedDeviceSoftware.Add(software);
        }