Exemple #1
0
        public async Task <IActionResult> CreateDevice([Bind(Bind)][FromBody] Device device)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(device));
            }


            var deviceExists = _deviceCache.DeviceExists(device.Imei, out _);

            if (deviceExists)
            {
                return(BadRequest("Device already exists."));
            }

            var userId = int.Parse(User.FindFirstValue("Id"));
            await _deviceCache.CreateDeviceAsync(device, userId);

            return(Ok(device));
        }