public async Task <DeviceConfigViewModel> UpdateConfig(UpdateDeviceCofigRequest request)
        {
            var config = await _unitOfWork.GetRepository <DeviceConfig>()
                         .FindAsync(x => x.DeviceId == request.DeviceId &&
                                    x.ApplicationId == request.ApplicationId);

            if (config == null)
            {
                throw new Exception(ErrorMessages.NotFoundDeviceConfig);
            }

            var version = await _unitOfWork.GetRepository <CS.EF.Models.Version>().FindAsync(x => x.Id == request.VersionId);

            if (version == null)
            {
                throw new Exception(ErrorMessages.NotFoundVersion);
            }

            config.VersionCode = version.Code;
            config.VersionId   = version.Id;
            config.VersionName = version.Name;
            config.LogTime     = request.LogTime;
            config.Message     = request.Message;

            _unitOfWork.GetRepository <DeviceConfig>().Update(config);
            await _unitOfWork.CommitAsync();

            return(_mapper.Map <DeviceConfigViewModel>(config));
        }
Example #2
0
        public async Task <IActionResult> UpdateConfig([FromBody] UpdateDeviceCofigRequest request)
        {
            var response = await _deviceConfigService.UpdateConfig(request);

            return(Ok(new ApiOkResponse(response)));
        }