Skip to content

Instantly share code, notes, and snippets.

@sethdorris
Created February 24, 2021 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethdorris/f2dabc15577e18bcf74a88067880213f to your computer and use it in GitHub Desktop.
Save sethdorris/f2dabc15577e18bcf74a88067880213f to your computer and use it in GitHub Desktop.
public async Task AddAllAsync(PostedJsonData data)
{
try
{
//refactor for async enumerables
foreach (var t in data.Triggers)
{
t.Device = _context.Devices.FirstOrDefault(x => x.Serial.Equals(t.Device.Serial)) ?? t.Device;
t.DeviceAssignment.Unit = _context.Units.FirstOrDefault(x => x.SummaryDataUnitID.Equals(t.DeviceAssignment.Unit.SummaryDataUnitID)) ?? t.DeviceAssignment.Unit;
_context.Triggers.Add(t);
_context.SaveChanges();
}
} catch (Exception e)
{
//TO DO: Handle this later.
Console.WriteLine(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment