Exemplo n.º 1
0
        public async Task <GatewayResponse> DeleteAsync(string Id)
        {
            var existing = await _gatewayRepo.FindByIdAsync(Id);

            if (existing == null)
            {
                return(new GatewayResponse("Gateway not found."));
            }

            try {
                _gatewayRepo.Delete(existing);
                await _gatewayRepo.SaveAllAsync();

                return(new GatewayResponse(existing));
            } catch (Exception ex) {
                return(new GatewayResponse($"An error occurred : {ex.Message}"));
            }
        }
Exemplo n.º 2
0
        public async Task <DeviceResponse> CreateAsync(Device device)
        {
            try {
                var gateway = _gatewayRepo.FindByIdAsync(device.GatewayId.ToString()).Result;
                if (gateway != null && gateway.DeviceNumb >= 10)
                {
                    return(new DeviceResponse("No more than 10 devices allowed per gateway."));
                }
                else
                {
                    gateway.DeviceNumb++;
                    _gatewayRepo.Update(gateway);
                    await _deviceRepo.CreateAync(device);

                    await _deviceRepo.SaveAllAsync();
                }
                return(new DeviceResponse(device));
            } catch (Exception ex) {
                return(new DeviceResponse($"An error occurred : {ex.Message}")); //handle concurency here
            }
        }