public async Task Create(EnergyMeter energyMeter) { try { var dao = new EnergyMeterDao(energyMeter); await _dbContext.AddAsync(dao); await _dbContext.SaveChangesAsync(); } catch (Exception) { throw new ArgumentException(); } }
public async Task Update(EnergyMeter energyMeter) { var dao = await _dbContext.EnergyMetersDaos.Include(m => m.MeterOfPoleDao).FirstOrDefaultAsync(m => m.SerialId == energyMeter.SerialId); if (dao != null) { var newDao = new EnergyMeterDao(energyMeter); dao.Type = newDao.Type; if (newDao.Count != null) { dao.Count = newDao.Count; } dao.SwitchState = newDao.SwitchState; dao.MeterOfPoleDao = newDao.MeterOfPoleDao; _dbContext.Entry(dao).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); } }
public MeterOfPoleDao(EnergyMeterDao meter, string meterId) { MeterOfPoleDaoId = meterId; EnergyMeterDaoId = meter.SerialId; EnergyMeterDao = meter; }