public async void MoveDevice()
        {
            bool updateResult = false;
            bool addResult    = false;

            if (ComboSelectedItem.Key == 1)
            {
                // Move device from warehouse to project
                if (WarehouseSelectedDevice != null)
                {
                    var warehouseDevice       = new DeviceModel(WarehouseSelectedDevice);
                    var warehouseDeviceEntity = await warehouseDevice.ConvertToDeviceEntity();

                    var projectDevice       = new DeviceModel(WarehouseSelectedDevice);
                    var projectDeviceEntity = await warehouseDevice.ConvertToDeviceEntity(true);

                    warehouseDeviceEntity.Quantity -= SelectedQuantity;
                    projectDeviceEntity.Quantity    = SelectedQuantity;

                    updateResult = await _deviceAccess.UpdateDevice(warehouseDeviceEntity);

                    addResult = await _deviceAccess.AddDeviceToProject(_projectId, projectDeviceEntity);
                }
            }
            else if (ComboSelectedItem.Key == 2)
            {
                // Mode device from project to warehouse
                if (ProjectSelectedDevice != null)
                {
                    var projectDevice       = new DeviceModel(ProjectSelectedDevice);
                    var projectDeviceEntity = await projectDevice.ConvertToDeviceEntity();

                    var warehouseDevice       = new DeviceModel(ProjectSelectedDevice);
                    var warehouseDeviceEntity = await warehouseDevice.ConvertToDeviceEntity(true);

                    warehouseDeviceEntity.Quantity += SelectedQuantity;
                    projectDeviceEntity.Quantity   -= SelectedQuantity;

                    updateResult = await _deviceAccess.UpdateDevice(projectDeviceEntity);

                    addResult = await _deviceAccess.AddDeviceToProject(_warehouseProjectId, warehouseDeviceEntity);
                }
            }

            // Check the result of exchange
            if (updateResult && addResult)
            {
                await LoadProjectDevices(_projectId);
                await LoadWarehouseDevices(_warehouseProjectId);
            }
            else
            {
                MessageBox.Show("Wystąpił błąd podczas wymiany urządzeń. Spróbuj ponownie");
            }
        }
Ejemplo n.º 2
0
        public async void ConvertToDeviceEntity_WithoutClearIDs_Test()
        {
            // Arrange
            int sampleProducerId = 2;

            var producerAccess = new Mock <IProducerAccess>();

            producerAccess
            .Setup(x => x.GetProducerId(It.IsAny <string>()))
            .ReturnsAsync(sampleProducerId);

            int    sampleId            = 1;
            string sampleArticleNumber = "SD9F0-SDF98-SDF98";
            string sampleName          = "Panel KTP900 Basic";
            string sampleProducerName  = "SIEMENS";
            string sampleLocation      = "A2";
            int    sampleQuantity      = 14;
            int    sampleProjectId     = 4;


            var deviceModel = new DeviceModel(producerAccess.Object)
            {
                Id            = sampleId,
                Name          = sampleName,
                ArticleNumber = sampleArticleNumber,
                ProducerName  = sampleProducerName,
                Location      = sampleLocation,
                Quantity      = sampleQuantity,
                ProjectId     = sampleProjectId
            };


            // Act
            var deviceEntity = await deviceModel.ConvertToDeviceEntity();


            // Assert

            // Check properties values
            Assert.Equal(sampleId, deviceEntity.Id);
            Assert.Equal(sampleName, deviceEntity.Name);
            Assert.Equal(sampleArticleNumber, deviceEntity.ArticleNumber);
            Assert.Equal(sampleLocation, deviceEntity.Location);
            Assert.Equal(sampleQuantity, deviceEntity.Quantity);
            Assert.Equal(sampleProjectId, deviceEntity.ProjectID);
            Assert.Equal(sampleProducerId, deviceEntity.ProducerID);

            // Check type of converted object
            Assert.True(deviceEntity.GetType() == typeof(DataAccess.Entities.Device));

            // Check default values of converted entity
            Assert.Null(deviceEntity.Producer);
            Assert.Null(deviceEntity.Project);
        }
Ejemplo n.º 3
0
        public async void SaveButton()
        {
            var device = new DeviceModel(_producerAccess)
            {
                Name          = DeviceName,
                ArticleNumber = ArticleNumber,
                ProducerName  = SelectedProducerName,
                Location      = Location,
                Quantity      = Quantity
            };

            var deviceValidator = new DeviceModelValidator();
            var result          = deviceValidator.Validate(device);

            // For testing
            NewDeviceValidationResult = result.IsValid;

            if (result.IsValid)
            {
                var deviceEntity = await device.ConvertToDeviceEntity();

                deviceEntity.ProjectID = 5;
                SaveNewDeviceResult    = await _deviceAccess.AddDevice(deviceEntity);

                SnackbarNotification.MessageQueue = new SnackbarMessageQueue();
                string message = null;

                if (SaveNewDeviceResult)
                {
                    message = "Urządzenie zostało dodane poprawnie.";
                }
                else
                {
                    message = "Urządzenie nie zostało dodane.";
                }

                SnackbarNotification.MessageQueue.Enqueue(message);
                ClearDeviceForm();
            }
            else
            {
                SnackbarNotification.MessageQueue = new SnackbarMessageQueue();
                SnackbarNotification.MessageQueue.Enqueue("Błąd wprowadzonych danych, urządzenie nie zostało dodane.");
            }
        }
Ejemplo n.º 4
0
        public async void SaveButton()
        {
            var device = new DeviceModel(_producerAccess)
            {
                Name          = DeviceName,
                ArticleNumber = ArticleNumber,
                ProducerName  = SelectedProducer,
                Location      = Location,
                Quantity      = Quantity
            };

            var deviceValidator = new DeviceModelValidator();
            var result          = deviceValidator.Validate(device);

            if (result.IsValid)
            {
                var deviceEntity = await device.ConvertToDeviceEntity();

                deviceEntity.ProjectID = ProjectId;
                var resultTask = await _deviceAccess.AddDevice(deviceEntity);

                if (resultTask)
                {
                    _events.PublishOnUIThread(new AddedNewDeviceToProjectEvent());
                    TryClose();
                }
                else
                {
                    MessageBox.Show("Urządzenie nie zostało dodane.");
                }
            }
            else
            {
                MessageBox.Show("Błąd walidacji danych");
            }
        }