示例#1
0
        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();
            }
        }
示例#2
0
        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();
                }
            }
        }