public async Task <Battery> UpsertAsync(Battery battery) { var current = await _db.Batteries.FirstOrDefaultAsync(b => b.Id == battery.Id); if (null == current) { _db.Batteries.Add(battery); } else { _db.Entry(current).CurrentValues.SetValues(battery); } await _db.SaveChangesAsync(); return(battery); }
public async Task <Test> UpsertAsync(Test test) { var current = await _db.Tests.FirstOrDefaultAsync(_test => _test.Id == test.Id); if (null == current) { _db.Tests.Add(test); } else { _db.Entry(current).CurrentValues.SetValues(test); } await _db.SaveChangesAsync(); return(test); }