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);
            }
                );
        }
Example #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);
        }
        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; }
            }
                );
        }
Example #4
0
        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;
                }
            };
        }
Example #5
0
        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()
                );
        }