public Task PingAsync(Guid sessionId) { return(Task.Run(() => { try { var tracking = _trackingContext.Trackings .Include(p => p.Ex) .Include(p => p.Messages) .Include(p => p.Pings) .Where(p => p.SessionId == sessionId).Single(); if (tracking.Pings == null) { tracking.Pings = new List <PingsModel>(); } tracking.Pings.Add(new PingsModel() { PingData = DateTime.Now, TrackingId = tracking.TrackingId }); _trackingContext.SaveChanges(); }catch (Exception ex) { _logger.LogError(ex, "PyngAsync error:"); } })); }
public static (bool, int[]) AddTestData <TEntity>(this TrackingContext context, int quantity) where TEntity : class { for (int i = 0; i < quantity; i++) { var entity = Activator.CreateInstance <TEntity>(); var properties = entity.GetType().GetProperties(); foreach (var property in properties) { if (property.Name == "Id") { continue; } if (property.PropertyType == typeof(string)) { property.SetValue(entity, Random.GenerateString(10)); } } context.Set <TEntity>().Add(entity); } context.SaveChanges(); return(true, context.Set <TEntity>().Select(x => (int)x.GetType().GetProperty("Id").GetValue(x)).ToArray()); }
public TrackingLogEvent InsertEvent(TrackingLogEvent trackingLogEvent) { var entityEntry = _trackingContext.TrackingLogEvent.Add(trackingLogEvent); _trackingContext.SaveChanges(); return(entityEntry.Entity); }