public object Get(CreateCupFromLeagueRequest request) { var competition = Db.LoadSingleById <Competition>(request.CompetitionId); var leagueIds = competition.Leagues.Select(s => s.Id).ToList(); var teams = Db.Select(Db.From <Team>().Where(p => Sql.In(p.LeagueId, leagueIds))); var cup = Db.SingleById <Cup>(request.Id); using (var transaction = Db.OpenTransaction(IsolationLevel.RepeatableRead)) { Db.Delete(Db.From <Match>().Where(p => p.CupId == request.Id)); var matches = MatchFactory.CreateCupMatches(teams, competition.Leagues, Db); matches.ForEach(m => m.CupId = request.Id); foreach (var match in matches) { Db.Insert(match); } cup.CurrentRound = 1; Db.Save(cup); transaction.Commit(); return(null); } }