public AddDeviceAccountViewModel(IDeviceRelatedRepository repo) { Repository = repo; AddDeviceAccountCommand = RegisterCommandAction( (obj) => AddAccountToDevice(), (obj) => !(string.IsNullOrWhiteSpace(InputtedLogin) || string.IsNullOrWhiteSpace(InputtedPassword)) ); }
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) => { }; }
public AddDeviceViewModel(IDeviceRelatedRepository repo) { Repository = repo; AddDeviceCommand = RegisterCommandAction( (obj) => { var newDevice = new Device { InventoryNumber = InputtedInventoryNumber, DeviceTypeID = SelectedDeviceType.ID, NetworkName = InputtedNetworkName, }; try { Repository.AddDevice(newDevice); Repository.SaveChanges(); // Device should be counted as added to storage when added var addedDeviceNote = new DeviceMovementHistoryNote { // N/A cabinet in N/A housing TargetCabinetID = -4, DeviceID = newDevice.ID, Reason = "Доставлено на склад", Date = DateTime.Now }; Repository.FixDeviceMovement(addedDeviceNote); Repository.SaveChanges(); DeviceEvents.RaiseOnNewDeviceAdded(newDevice); InputtedInventoryNumber = ""; InputtedNetworkName = ""; MessageToUser = "******"; } catch (Exception e) { MessageToUser = e.Message; Repository.RemoveDevice(newDevice); } }, (obj) => { return(!string.IsNullOrEmpty(InputtedInventoryNumber) && !string.IsNullOrEmpty(InputtedNetworkName) && SelectedDeviceType != null); } ); }
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); }
public DeviceHistoryViewModel(IDeviceRelatedRepository repo) { Repository = repo; ShowDeviceMovementHistoryCommand = RegisterCommandAction( (obj) => { RefreshSelectedDeviceHistory(); var _historyView = new DeviceMovementHistoryView(); _historyView.DataContext = ResolveDependency <IDeviceMovementHistoryViewModel>(); _historyView.Title = $"История перемещений {SelectedDevice.InventoryNumber}"; _historyView.ShowDialog(); }, (obj) => SelectedDevice != null ); }
public AddIPToDeviceViewModel(IDeviceRelatedRepository repo) { Repository = repo; AllAvailableIPAddresses = Repository. AllAvailableIPAddresses. ToList(); SelectFirstIPInList(); AddIPToDeviceCommand = RegisterCommandAction( (obj) => { AddIPToDevice(); RefreshAvailableIPList(); SelectFirstIPInList(); }, (obj) => SelectedIPAddress != null ); }
public DeviceIPListViewModel(IDeviceRelatedRepository repo) { Repository = repo; SubscribeActionOnIPAddition( (ipAddress) => SelectedDeviceIPAddresses.Add(ipAddress) ); SubscribeActionOnDeviceSelectionChanged( (device) => { if (device != null) { SelectedDeviceIPAddresses = Repository.GetAllDeviceIPAddresses(device).ToObservableCollection(); } } ); SubscribeActionOnNetworkMaskChanges((ip, mask) => ClearDevicesIPLists()); ShowAddIPViewCommand = RegisterCommandAction( (obj) => { var _addIpToDeviceView = new AddIPAddressView(); _addIpToDeviceView.DataContext = ResolveDependency <IAddIPToDeviceViewModel>(); _addIpToDeviceView.ShowDialog(); }, (obj) => SelectedDevice != null ); RemoveIPFromDeviceCommand = RegisterCommandAction( (o) => { RemoveIPAddress(SelectedIPAddress); SelectedDeviceIPAddresses.Remove(SelectedIPAddress); }, (obj) => SelectedIPAddress != null ); }
public DeviceAccountsListViewModel(IDeviceRelatedRepository repo) { Repository = repo; SubscribeActionOnDeviceAccountAddition( (newAcc) => SelectedDeviceAccounts.Add(newAcc) ); SubscribeActionOnDeviceSelectionChanged( (device) => { if (device != null) { SelectedDeviceAccounts = Repository. GetAllDeviceAccounts(device). ToObservableCollection(); } } ); ShowAddDeviceAccountViewCommand = RegisterCommandAction( (obj) => { var _addDeviceAccountView = new AddDeviceAccountView(); _addDeviceAccountView.DataContext = ResolveDependency <IAddDeviceAccountViewModel>(); _addDeviceAccountView.ShowDialog(); }, (obj) => SelectedDevice != null ); RemoveDeviceAccountCommand = RegisterCommandAction( (obj) => { RemoveAccountFromDevice(SelectedAccount); SelectedDeviceAccounts.Remove(SelectedAccount); }, (obj) => SelectedAccount != null ); }
public EditSoftwareInfoViewModel(IDeviceRelatedRepository repo) { Repository = repo; FillFieldsWithSoftwareConfiguration(); ApplyChangesCommand = RegisterCommandAction( (obj) => { var newConfig = new SoftwareConfiguration(); try { InitializeSoftwareConfiguration(newConfig); Repository.UpdateSoftwareConfiguration(newConfig); Repository.SaveChanges(); MessageToUser = "******"; } catch (Exception e) { MessageToUser = e.Message; } } ); }
public DeviceLocationViewModel(IDeviceRelatedRepository repo) { Repository = repo; AllHousings = Repository.AllHousings.ToList(); AllCabinets = Repository.AllCabinets.ToList(); IsDeviceLocationChoosingAvailable = false; ApplyDeviceLocationChangesCommand = RegisterCommandAction( (obj) => { SelectedDevice.Cabinet = SelectedCabinet; SelectedDevice.Cabinet.Housing = SelectedHousing; try { Repository.UpdateDevice(SelectedDevice); var newRecord = new DeviceMovementHistoryNote() { DeviceID = SelectedDevice.ID, TargetCabinetID = SelectedDevice.Cabinet.ID, Date = DateTime.Now, // Reason field is temporary. Need to create entity with reasons // and use it instead of this hard coding Reason = "Перемещение" }; try { Repository.FixDeviceMovement(newRecord); Repository.SaveChanges(); } catch { Repository.RemoveDeviceMovementNote(newRecord); } Repository.SaveChanges(); } catch (Exception e) { MessageToUser = e.Message; } }, (obj) => (SelectedDevice != null) && (SelectedDevice.Cabinet != SelectedCabinet) ); SubscribeActionOnHousingChanged( (h) => { if (h != null) { SelectedHousingCabinets = GetAllSelectedHousingCabinets(); SelectDeviceCabinetIfHousingIsTheSame(); } else { SelectedHousingCabinets = null; } } ); SubscribeActionOnDeviceSelectionChanging( (device) => { if (device != null) { SelectedHousing = device.Cabinet.Housing; SelectedCabinet = device.Cabinet; } } ); DeviceEvents.OnDeviceSelectionChanged += device => { if (device != null) { IsDeviceLocationChoosingAvailable = true; } else { SelectedCabinet = null; SelectedHousing = null; IsDeviceLocationChoosingAvailable = false; } }; }
public DevicesManagementViewModel(IDeviceRelatedRepository repo) { Repository = repo; }
public DevicesListViewModel(IDeviceRelatedRepository repo, IUserSession userSession) { Repository = repo; UserSession = userSession; AllDevices = Repository.AllDevices.ToList(); InitDevicesLocationWithInstances(); FilterDevicesAccordingToCriteria(); ShowAddDeviceViewCommand = RegisterCommandAction( (obj) => { AddDeviceView = new AddDeviceView(); AddDeviceView.DataContext = ResolveDependency <IAddDeviceViewModel>(); AddDeviceView.ShowDialog(); }, (obj) => UserSession.IsAuthorizedUserAllowedTo(UserActions.AddDevice) ); RemoveDeviceCommand = RegisterCommandAction( (obj) => { Repository.RemoveDevice(SelectedDevice); Repository.DeleteAllDeviceMovementHistory(SelectedDevice); Repository.SaveChanges(); AllDevices.Remove(AllDevices.Find(d => d.ID == SelectedDevice.ID)); FilteredDevices.Remove(SelectedDevice); }, (obj) => { if (UserSession.IsAuthorizedUserAllowedTo(UserActions.RemoveDevice)) { return(SelectedDevice != null); } else { return(false); } } ); SubscribeActionOnDeviceAddition( (device) => { device.DeviceType = Repository.AllDeviceTypes.Single(dt => dt.ID == device.DeviceTypeID); device.Cabinet = Repository.FindCabinet(device.CabinetID); device.Cabinet.Housing = DeviceLocationViewModel. AllHousings. First(h => h.ID == device.Cabinet.HousingID); AllDevices.Add(device); if (DevicesFilter.DoesMeetSearchingAndFilteringCriteria(device)) { FilteredDevices.Add(device); } } ); SubscribeActionOnFilteringCriteraChanges( (filteredDevices) => FilteredDevices = filteredDevices.ToObservableCollection() ); }