示例#1
0
        public KeysDto Update(KeysDto keysDto)
        {
            var meterKeys = GetExistingMeterKey(keysDto.Serial);

            meterKeys.UpdateFields(keysDto);
            var meter = _meterRepository.GetBySerial(keysDto.Serial);

            if (meter == null)
            {
                return(_mapper.Map <MeterKeys, KeysDto>(_meterKeyRepository.Update(meterKeys)));
            }
            HttpResponseMessage status;

            meter.MeterKeys = meterKeys;
            if (meter.Smc == null)
            {
                status = _meterForwarderService.ForwardEdition(_mapper.Map <Meter, MeterDto>(meter));
            }
            else
            {
                var smc = _mapper.Map <SmcDto>(meter.Smc);
                smc.KeysDto = keysDto;
                status      = _smcForwarderService.ForwardEdition(smc);
            }

            if (!status.IsSuccessStatusCode)
            {
                throw new BadRequestException(JsonConvert
                                              .DeserializeObject <ErrorMessageDto>(status.Content.ReadAsStringAsync().Result).ErrorMessage);
            }

            return(_mapper.Map <MeterKeys, KeysDto>(_meterKeyRepository.Update(meterKeys)));
        }
示例#2
0
        public static void CreateRSAKey(string privateKeyPath, string publicKeyPath)
        {
            KeysDto keys = GetRSAKey();

            FileHelper.CreateFile(privateKeyPath, keys.PrivateKey);
            FileHelper.CreateFile(publicKeyPath, keys.PublichKey);
        }
示例#3
0
        public KeysDto Create(KeysDto keysDto)
        {
            var meterKeys = _meterKeyRepository.GetBySerial(keysDto.Serial);

            if (meterKeys != null)
            {
                throw new ExistentEntityException("As chaves do medidor de serial " + keysDto.Serial + " já existem na base de dados");
            }
            return(_mapper.Map <MeterKeys, KeysDto>(_meterKeyRepository.Create(_mapper.Map <KeysDto, MeterKeys>(keysDto))));
        }
示例#4
0
        public IActionResult Save(KeysDto keysDto)
        {
            var keys = _meterKeyService.Create(keysDto);

            return(new CreatedResult(
                       _servicesUtils
                       .CreateUri(
                           Request,
                           Url.RouteUrl(
                               "GetBySerialRoute",
                               new { serial = keys.Serial })),
                       keysDto));
        }
示例#5
0
        private Smc CreateSmc(SmcDto smc, KeysDto keysDto)
        {
            smc.KeysDto  = keysDto;
            smc.SmcModel = _smcModelService.GetByName(smc.SmcModel.Name);
            var status = _smcForwarderService.ForwardCreation(smc);

            if (!status.IsSuccessStatusCode)
            {
                throw new BadRequestException(JsonConvert
                                              .DeserializeObject <ErrorMessageDto>(status.Content.ReadAsStringAsync().Result).ErrorMessage);
            }
            _smcService.Save(smc);
            return(_smcService.GetExistingSmc(smc.Serial));
        }
示例#6
0
 public void UpdateFields(KeysDto keysDto)
 {
     Ak = keysDto.Ak;
     Ek = keysDto.Ek;
     Mk = keysDto.Mk;
 }
示例#7
0
 public IActionResult Update(KeysDto keysDto)
 {
     return(new OkObjectResult(_meterKeyService.Update(keysDto)));
 }