Esempio n. 1
0
 public static DeviceRequestDomainModel RequestToDomain(this DeviceRequestModel @this)
 {
     return(new DeviceRequestDomainModel
     {
         limit = @this.limit ?? 0,
         offset = @this.offset ?? 0,
         type = @this.type
     });
 }
Esempio n. 2
0
        public async Task <DeviceResponseModel> Post([FromBody] DeviceRequestModel model)
        {
            var device = model.ToDevice(_userService.GetProperUserId(User));
            await _deviceService.SaveAsync(device);

            var response = new DeviceResponseModel(device);

            return(response);
        }
Esempio n. 3
0
        public async Task <IActionResult> GetDevices(string user_id, [FromQuery] DeviceRequestModel model)
        {
            var response = await GetCollectionResultAsync <DeviceResponseModel>(
                getCount : () => _deviceService.DeviceAllCount(user_id),
                getItems : async() =>
            {
                var devices = await _deviceService.GetDevicesAsync(user_id, model.RequestToDomain());
                return(devices.Select(x => x.DomainToResponse()));
            },
                modelState : ModelState
                );

            return(Result(response));
        }
Esempio n. 4
0
        public async Task <DeviceResponseModel> Put(string id, [FromBody] DeviceRequestModel model)
        {
            var device = await _deviceRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);

            if (device == null)
            {
                throw new NotFoundException();
            }

            await _deviceService.SaveAsync(model.ToDevice(device));

            var response = new DeviceResponseModel(device);

            return(response);
        }
Esempio n. 5
0
        public async void Create(DeviceRequestModel device_req)
        {
            Device new_device = new Device();

            new_device.Name       = device_req.Name;
            new_device.DeviceHome = null;
            new_device.DeviceType = null;
            new_device.Device_Parameter_Current_Value = null;
            try
            {
                _context.Devices.Add(new_device);
                _context.SaveChanges();
            }
            catch { }
        }
Esempio n. 6
0
        public void persistSubscriptionInfo([FromBody] DeviceRequestModel model)
        {
            Application application = _dbContext.Application.SingleOrDefault(m => m.publicKey == model.publicKey);

            if (application != null)
            {
                Device device = new Device
                {
                    appId        = application.id,
                    pushAuth     = model.pushAuth,
                    pushEndpoint = model.pushEndpoint,
                    pushP256DH   = model.pushP256DH,
                    externalId   = model.externalId,
                    lastUpdated  = System.DateTime.Now,
                    createdAt    = System.DateTime.Now
                };

                _dbContext.Device.Add(device);
                _dbContext.SaveChanges();
            }
        }
Esempio n. 7
0
        public TableDataModel LoadData(DeviceRequestModel model)
        {
            var devices = _dbContext.Devices.ToList();

            if (!string.IsNullOrEmpty(model.Key))
            {
                devices = devices.Where(t => t.Name.Contains(model.Key)).ToList();
            }
            List <DeviceDTO> list = new List <DeviceDTO>();

            foreach (var device in devices)
            {
                list.Add(Todto(device));
            }


            var table = new TableDataModel()
            {
                count = list.Count,
                data  = list
            };

            return(table);
        }
Esempio n. 8
0
        public string LoadData([FromQuery] DeviceRequestModel model)
        {
            var tableData = _deviceService.LoadData(model);

            return(JsonHelper.ObjectToJSON(tableData));
        }