Created
February 24, 2021 19:22
-
-
Save sethdorris/f2dabc15577e18bcf74a88067880213f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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