Exemplo n.º 1
0
        public async Task <ActionResult <VegaDevice> > PostDeviceAsync(VegaDevice vegaTempDevice)
        {
            if (vegaTempDevice is null)
            {
                return(BadRequest());
            }

            try
            {
                await _repository.AddDeviceAsync(vegaTempDevice).ConfigureAwait(false);
            }
            catch (DbUpdateException)
            {
                if (_repository.DeviceExists(vegaTempDevice.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetDevice", new { id = vegaTempDevice.Id }, vegaTempDevice));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddDeviceAsync(Device device)
        {
            if (ModelState.IsValid)
            {
                bool pass = await _deviceReposity.AddDeviceAsync(device);

                if (pass)
                {
                    return(RedirectToAction("Index"));
                }
            }
            ModelState.AddModelError("ParticleDeviceID", "Invalid or Unconnected Particle ID");
            return(View("AddDevice", device));
        }