Esempio n. 1
0
        public async Task <Guid> Setup(SetupDeviceRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (await _deviceRepository.HasAsync(x => x.Udid == request.Udid))
            {
                throw new ApplicationException($"Device with udid: {request.Udid} already exist");
            }
            var device = request.Adapt <Device>();

            device.CreatedOn = DateTime.UtcNow;
            device.IsPending = true;
            return(await _deviceRepository.AddAsync(device));
        }
Esempio n. 2
0
        public async Task <IActionResult> PendingPost([FromBody] SetupDeviceRequest request)
        {
            try
            {
                var deviceId = await _deviceService.Setup(request);

                return(Created(HttpContext.Request.GetEncodedUrl(), deviceId));
            }
            catch (ArgumentNullException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (ApplicationException ex)
            {
                return(BadRequest(ex.Message));
            }
        }