Ejemplo n.º 1
0
        public void AddDevice(RestServiceRequest <DeviceInfo> request, RestServiceResponse <DeviceInfo> response)
        {
            if (request.Body == null ||
                !request.Body.DeviceNumber.HasValue() ||
                !request.Body.DeviceName.HasValue())
            {
                throw new RequestDataInvalidException("DeviceNumber", "DeviceName");
            }

            var retVal = _DeviceInfoRepository.AddDevice(DeviceInfoTransfer.BuildDeviceInfoSource(request.Body),
                                                         DeviceSparePartTransfer.BuildDeviceSparePartSources(request.Body.DeviceSpareParts),
                                                         DeviceCheckpointTransfer.BuildDeviceCheckpointSources(request.Body.DeviceCheckpoints));

            if (retVal < 0)
            {
                switch (retVal)
                {
                case -1: throw new DeviceAlreadyExistedException(request.Body.DeviceNumber);

                default: throw new UndefinedException(retVal);
                }
            }

            response.Body = new DeviceInfo()
            {
                DeviceNumber = request.Body.DeviceNumber
            };
        }
Ejemplo n.º 2
0
        public void AddCheckpoint(RestServiceRequest <DeviceCheckpoint> request, RestServiceResponse <DeviceCheckpoint> response)
        {
            if (request.Body == null ||
                request.Body.DeviceInfo == null ||
                !request.Body.DeviceInfo.DeviceNumber.HasValue() ||
                !request.Body.Description.HasValue())
            {
                throw new RequestDataInvalidException("DeviceNumber", "Description");
            }

            var retVal = _DeviceCheckpointRepository.AddCheckpoint(DeviceCheckpointTransfer.BuildDeviceCheckpointSource(request.Body));

            if (retVal < 0)
            {
                switch (retVal)
                {
                default: throw new UndefinedException(retVal);
                }
            }

            response.Body = new DeviceCheckpoint()
            {
                Id = retVal
            };
        }
Ejemplo n.º 3
0
        public void QueryDeviceCheckpoints(RestServiceRequest request, RestServiceResponse <DeviceCheckpoint[]> response)
        {
            response.Paging = request.Paging;

            response.Body = DeviceCheckpointTransfer.BuildDeviceCheckpoints(_DeviceCheckpointRepository.QueryDeviceCheckpoints(
                                                                                request.Paging,
                                                                                request.GetValue <int>("DeviceCheckpointId", 0),
                                                                                request.GetValue("DeviceNumber")));
        }
Ejemplo n.º 4
0
        public void DeleteCheckpoint(RestServiceRequest <DeviceCheckpoint> request, RestServiceResponse <DeviceCheckpoint> response)
        {
            if (request.Body == null ||
                request.Body.Id <= 0)
            {
                throw new RequestDataInvalidException("DeviceNumber");
            }

            var retVal = _DeviceCheckpointRepository.DeleteCheckpoint(DeviceCheckpointTransfer.BuildDeviceCheckpointSource(request.Body));

            if (retVal < 0)
            {
                switch (retVal)
                {
                default: throw new UndefinedException(retVal);
                }
            }
        }
Ejemplo n.º 5
0
        public void EditCheckpoint(RestServiceRequest <DeviceCheckpoint> request, RestServiceResponse <DeviceCheckpoint> response)
        {
            if (request.Body == null ||
                request.Body.Id <= 0 ||
                !request.Body.Description.HasValue())
            {
                throw new RequestDataInvalidException("Id", "Description");
            }

            var retVal = _DeviceCheckpointRepository.EditCheckpoint(DeviceCheckpointTransfer.BuildDeviceCheckpointSource(request.Body));

            if (retVal < 0)
            {
                switch (retVal)
                {
                default: throw new UndefinedException(retVal);
                }
            }
        }
Ejemplo n.º 6
0
        public void QueryDetailDevices(RestServiceRequest request, RestServiceResponse <DeviceInfo[]> response)
        {
            response.Paging = request.Paging;

            var deviceInfos = DeviceInfoTransfer.BuildDeviceInfos(_DeviceInfoRepository.QueryDeviceInfos(
                                                                      request.Paging,
                                                                      request.GetValue("DeviceNumber"),
                                                                      request.GetValue("DeviceName")));

            var deviceCheckpoints = DeviceCheckpointTransfer.BuildDeviceCheckpoints(
                _DeviceCheckpointRepository.QueryDeviceCheckpoints(deviceInfos.Select(x => x.DeviceNumber).ToArray()));

            var deviceSparePartDeviceInfoMappings = DeviceSparePartDeviceInfoMappingTransfer.BuildDeviceSparePartDeviceInfoMappings(
                _DeviceSparePartRepository.QueryDeviceSpareParts(deviceInfos.Select(x => x.DeviceNumber).ToArray()));

            foreach (var deviceInfo in deviceInfos)
            {
                deviceInfo.DeviceCheckpoints = deviceCheckpoints.Where(x => x.DeviceInfo != null && x.DeviceInfo.DeviceNumber == deviceInfo.DeviceNumber).ToArray();
                deviceInfo.DeviceSpareParts  = deviceSparePartDeviceInfoMappings.Where(x => x.DeviceInfo != null && x.DeviceInfo.DeviceNumber == deviceInfo.DeviceNumber)
                                               .Select(x => x.DeviceSparePart).ToArray();
            }

            response.Body = deviceInfos;
        }