public async Task <IActionResult> PutPeripheralDevice(int id, PeripheralDevice peripheralDevice)
        {
            if (id != peripheralDevice.Id)
            {
                return(BadRequest());
            }

            var devicesCount = _context.PeripheralDevice.Where(a => a.GatewayId == peripheralDevice.GatewayId).Count();

            if (devicesCount > 10)
            {
                return(BadRequest("the number of peripheral devices allowed is 10 only"));
            }

            _context.Entry(peripheralDevice).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PeripheralDeviceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
        public async Task SeedAsync(ApplicationDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext.PeripheralDevices.Any())
            {
                return;
            }

            for (int i = 1; i < 5; i++)
            {
                var peripheralDevices = new List <PeripheralDevice>();
                for (int j = 0; j < 10; j++)
                {
                    var status = j % 2 == 0 ? DeviseStatus.Online : DeviseStatus.Offline;
                    var device = new PeripheralDevice {
                        DateOfCreation = DateTime.UtcNow, Status = status, UID = j, Vendor = $"Vendor {j}"
                    };
                    peripheralDevices.Add(device);
                }

                var gateWay = new Gateway {
                    Name = $"Gateway {i}", IPv4 = $"127.0.0.{i}", SerialNumber = $"SN{i}", PeripheralDevices = peripheralDevices
                };

                await dbContext.Gateways.AddAsync(gateWay);
            }
        }
Example #3
0
        public async Task RemoveDeviceAsync(Gateway gateway, PeripheralDevice device)
        {
            gateway.PeripheralDevices.Remove(device);

            device.GatewayId = null;
            this.peripheralDevicesRepository.Update(device);
            await this.peripheralDevicesRepository.SaveChangesAsync();
        }
        public async Task SaveAsync(PeripheralDevice peripheral)
        {
            var count = _gatewayManagerContext.Peripherals.Where(p => p.GatewayID == peripheral.GatewayID).ToList().Count;

            if (count < 10)
            {
                await _gatewayManagerContext.Peripherals.AddAsync(peripheral);
            }
            else
            {
                throw new Exception("The gateway can not carry more Peripheral Devices");
            }
        }
        public async Task <ActionResult <PeripheralDevice> > PostPeripheralDevice(PeripheralDevice peripheralDevice)
        {
            var devicesCount = _context.PeripheralDevice.Where(a => a.GatewayId == peripheralDevice.GatewayId).Count();

            if (devicesCount > 10)
            {
                return(BadRequest("the number of peripheral devices allowed is 10 only"));
            }
            _context.PeripheralDevice.Add(peripheralDevice);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPeripheralDevice", new { id = peripheralDevice.Id }, peripheralDevice));
        }
Example #6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            PeripheralDevice newPeripherial = new PeripheralDevice();
            DodajUrzadzenie  Okno           = new DodajUrzadzenie(newPeripherial);

            Okno.ShowDialog();

            if (Okno.m_oDevice.PeripheralDeviceName != "" && Okno.m_oDevice.Amount != 0)
            {
                peripheralDevices.Add(Okno.m_oDevice);
                lstPeripheral.ItemsSource = peripheralDevices;
                lstPeripheral.Items.Refresh();
            }
        }
Example #7
0
        public async Task <ServiceResult> AddDeviceAsync(Gateway gateway, PeripheralDevice device)
        {
            var count = this.peripheralDevicesRepository.AllAsNoTrackingWithDeleted().Count(x => x.GatewayId == gateway.Id);

            if (count < GlobalConstants.GatewayMaxPeripheralDevicesCount)
            {
                gateway.PeripheralDevices.Add(device);

                device.GatewayId = gateway.Id;
                this.peripheralDevicesRepository.Update(device);
                await this.peripheralDevicesRepository.SaveChangesAsync();

                return(new ServiceResult());
            }

            return(new ServiceResult()
            {
                ErrorMessage = $"Gateway max peripheral devices count of {GlobalConstants.GatewayMaxPeripheralDevicesCount} is reached."
            });
        }
Example #8
0
        public async Task <PeripheralResponse> SaveAsync(PeripheralDevice peripheral)
        {
            var gateway = await _gatewayService.FindByIDAsync(peripheral.GatewayID);

            if (gateway == null)
            {
                return(new PeripheralResponse($"An error ocurred triying to save the Peripheral Device : The specified gateway does not exist."));
            }

            try
            {
                await _repo.SaveAsync(peripheral);

                await _unitOfWork.CompleteTask();

                return(new PeripheralResponse(peripheral));
            }
            catch (Exception ex)
            {
                return(new PeripheralResponse($"An error ocurred triying to save the Peripheral Device : {ex.Message}"));
            }
        }
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PeripheralDevicePresenter peripheralPresenter = (PeripheralDevicePresenter)this.DataContext;
                PeripheralDevice device = new PeripheralDevice();
                DeepClone.CopyTo((PeripheralDevice)(peripheralPresenter.View.dataGridPeripheralDevices.SelectedItem), device); 

                PeripheralDeviceEditPresenter peripheralEditPresenter = new PeripheralDeviceEditPresenter(new PeripheralDeviceEditView(), device);
                peripheralEditPresenter.View.Label_AddOrEditPeripheral.Content = "Edytowanie urzÄ…dzenia peryferyjnego";

                if (peripheralEditPresenter.View.ShowDialog() == true)
                {
                    peripheralPresenter.SavePeripheralDevice(device, true);
                    PeripheralDevice temp = (PeripheralDevice)peripheralPresenter.View.dataGridPeripheralDevices.SelectedItem;
                    ChangeCurrentRow(peripheralPresenter, peripheralEditPresenter, temp);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public async Task Create(PeripheralDevice gateway)
        {
            await this.repository.AddAsync(gateway);

            await this.repository.SaveChangesAsync();
        }
 private void ChangeCurrentRow(PeripheralDevicePresenter devicePresenter, PeripheralDeviceEditPresenter deviceEdit,
    PeripheralDevice obj)
 {
     PeripheralDevice device = ((PeripheralDevice)deviceEdit.View.DataContext);
     obj.id = device.id;
     obj.name = device.name;
     devicePresenter.View.dataGridPeripheralDevices.Items.Refresh();
 }
 public PeripheralResponse(PeripheralDevice peripheral) : this(true, "", peripheral)
 {
 }
 private PeripheralResponse(bool succes, string responseMessage, PeripheralDevice peripheral) : base(succes, responseMessage)
 {
     Peripheral = peripheral;
 }
 public void RemoveAsync(PeripheralDevice peripheral)
 {
     _gatewayManagerContext.Peripherals.Remove(peripheral);
 }
 public DodajUrzadzenie(PeripheralDevice peripheralDevice)
 {
     InitializeComponent();
     m_oDevice        = peripheralDevice;
     this.DataContext = m_oDevice;
 }
Example #16
0
 public DeviceWithValue(PeripheralDevice dev)
 {
     Dev   = dev;
     Value = "?";
     Tape  = new SourceTape();
 }
 public async Task Delete(PeripheralDevice gateway)
 {
     this.repository.Delete(gateway);
     await this.repository.SaveChangesAsync();
 }