public void AddTimetableHistory(Route route, StopGroup stop, int weight = 1) { lock (ctx) { DateTime now = DateTime.Now; var q = from e in ctx.HistoryEntries where e.RouteID == route.ID && e.StopID == stop.ID select e; HistoryEntry entry = q.SingleOrDefault(x => x.IsActive(now)); if (entry != null) { entry.RawCount = entry.RawCount + (weight << FloatingBits); ctx.Update(entry); } else { entry = new HistoryEntry(now) { Route = route, Stop = stop, RawCount = weight << FloatingBits }; ctx.Insert(entry); } } }
public void Add(Route route, StopGroup stop) { lock (ctx) { if (Contains(route, stop)) { throw new InvalidOperationException("Duplicate key at Favorites.Add"); } var table = ctx.FavoriteEntries; int position = 1; if (table.FirstOrDefault() != null) { position = table.Max(fav => fav.Position ?? 0) + 1; } FavoriteEntry entry = new FavoriteEntry { Route = route, Stop = stop, Position = position }; ctx.Insert(entry); } }