public SmcDto Save(SmcDto smcDto) { var savedSmc = _smcRepository.GetBySerial(smcDto.Serial); var smc = _mapper.Map <SmcDto, Smc>(smcDto); smc.SmcModel = _smcModelService.GetExistingSmcModel(smc.SmcModel.Name); if (savedSmc == null) { return(_mapper.Map <Smc, SmcDto>(_smcRepository.Save(smc))); } if (savedSmc.Active) { throw new ExistentEntityException("O smc de serial " + savedSmc.Serial + " já existe"); } savedSmc.UpdateFields(smc); savedSmc.Active = true; return(_mapper.Map <Smc, SmcDto>(_smcRepository.Update(savedSmc))); }
public void RemoveModemOfAllEntities(Modem modem) { List <Smc> smcs = _smcRepository.GetByModem(modem); List <Meter> meters = _meterRepository.GetByModem(modem); smcs.ForEach(smc => { smc.Modem = null; _smcRepository.Update(smc); }); meters.ForEach(meter => { meter.Modem = null; _meterRepository.Update(meter); }); }