public void DeleteRep(int id, bool bulk = false) { _logger.LogInformation("Deleting rep " + id); lock (lockobject) { var replay = _context.DSReplays .Include(o => o.Middle) .Include(p => p.DSPlayer) .ThenInclude(q => q.Breakpoints) .FirstOrDefault(s => s.ID == id); if (DbReplays.Contains(replay.REPLAYPATH)) { DbReplays.Remove(replay.REPLAYPATH); } if (replay.DSPlayer != null) { foreach (DSPlayer pl in replay.DSPlayer) { if (pl.Breakpoints != null) { foreach (DbBreakpoint bp in pl.Breakpoints) { _context.Breakpoints.Remove(bp); } } _context.DSPlayers.Remove(pl); } } if (replay.Middle != null) { foreach (DbMiddle mid in replay.Middle) { _context.Middle.Remove(mid); } } _context.DSReplays.Remove(replay); if (bulk == false) { _context.SaveChanges(); } } }
public static void SaveReplay(DSReplayContext stcontext, DSReplay rep, bool bulk = false) { lock (stlockobject) { stcontext.DSReplays.Add(rep); if (bulk == false) { stcontext.SaveChanges(); } } }
public static void DeleteRep(DSReplayContext stcontext, int id, bool bulk = false) { lock (stlockobject) { var replay = stcontext.DSReplays .Include(o => o.Middle) .Include(p => p.DSPlayer) .ThenInclude(q => q.Breakpoints) .FirstOrDefault(s => s.ID == id); if (replay.DSPlayer != null) { foreach (DSPlayer pl in replay.DSPlayer) { if (pl.Breakpoints != null) { foreach (DbBreakpoint bp in pl.Breakpoints) { stcontext.Breakpoints.Remove(bp); } } stcontext.DSPlayers.Remove(pl); } } if (replay.Middle != null) { foreach (DbMiddle mid in replay.Middle) { stcontext.Middle.Remove(mid); } } stcontext.DSReplays.Remove(replay); if (bulk == false) { stcontext.SaveChanges(); } } }