public async Task InsertNetworkEvent(Model.InsertNetworkEventCommand command) { using (var ctx = IOC.CreateNetworkTrackerContext()) { var eventType = (from et in ctx.EventTypes where et.Type == command.EventType select et).FirstOrDefaultAsync(); if (await eventType == null) { throw new ArgumentOutOfRangeException("EventType does not exist."); } var newEvent = new Database.Model.NetworkEvent() { EventType = await eventType, Value = command.Value, CreateTime = DateTimeOffset.UtcNow }; await ctx.NetworkEvents.AddAsync(newEvent); await ctx.SaveChangesAsync(); } }
public async Task InsertNetworkEventType(Model.InsertNetworkEventTypeCommand command) { using (var ctx = IOC.CreateNetworkTrackerContext()) { var eventType = ctx.EventTypes.Where(x => x.Type == command.Value).FirstOrDefault(); if (eventType == null) { var newType = new NetworkTracker.Database.Model.EventType() { Type = command.Value }; await ctx.EventTypes.AddAsync(newType); await ctx.SaveChangesAsync(); } } }