コード例 #1
0
        public async Task <ActionResult <Device> > GetDeviceAsync(string id)
        {
            ExtractToken();

            if (accessTokenHeader != null)
            {
                var token = appUserTokensRepository.Get(accessTokenHeader);
                if (token != null)
                {
                    var device = await devicesRepository.GetDeviceAsync(id);

                    if (device.AppUserId == token.AppUserId)
                    {
                        return(device);
                    }
                }
            }
            return(Unauthorized());
        }
コード例 #2
0
        public async Task <ActionResult <InfoIP> > PostInfoIp([FromBody] InfoIpModel infoIpModel)
        {
            ExtractToken();
            if (accessTokenHeader != null)
            {
                var token = appUserTokensRepository.Get(accessTokenHeader);
                if (token != null)
                {
                    var device = await devicesRepository.GetDeviceAsync(infoIpModel.deviceId);

                    var infoIp = new InfoIP
                    {
                        DeviceId = infoIpModel.deviceId,
                        Ip       = infoIpModel.ip,
                        Record   = DateTime.UtcNow
                    };
                    await infoIpRepository.CreateAsync(infoIp);

                    infoIp.Device = null; //If not null cause Error
                    return(infoIp);
                }
            }
            return(Unauthorized(new { message = "Unauthorized" }));
        }