コード例 #1
0
 public DeviceResponse(DevicePrincipalResponse principal, IEnumerable <TriggerResponse> triggers,
                       IEnumerable <ProgramResponse> programs)
 {
     Principal = principal;
     Triggers  = triggers;
     Programs  = programs;
 }
コード例 #2
0
        public async Task <ActionResult <DeviceResponse> > Get(Guid deviceId)
        {
            var user = HttpContext.User.Identity?.Name;

            if (user == null)
            {
                return(Unauthorized("Unknown user"));
            }

            var d = await Db.Users
                    .Where(x => x.Aud == user)
                    .Include(x => x.Device)
                    .ThenInclude(x => x.Programs)
                    .Include(x => x.Device)
                    .ThenInclude(x => x.Triggers)
                    .FirstOrDefaultAsync(x => x.Device.DeviceId == deviceId);

            if (d == null)
            {
                return(NotFound("Cannot find device"));
            }


            var device = new DevicePrincipalResponse(
                d.Device.DeviceId,
                d.Name,
                d.Description,
                d.Device.PowerState
                );

            var triggers = d.Device.Triggers.Select(x => new TriggerResponse(x.Id, x.Name));
            var programs = d.Device.Programs.Select(x => new ProgramResponse(x.Id, x.Name, x.Code));

            var resp = new DeviceResponse(device, triggers, programs);

            return(Ok(resp));
        }