Beispiel #1
0
        public void AddLeague(int id, int leagueId)
        {
            var game = _repo.GetSingle(gm => gm.Id == id);

            if (game == null)
            {
                throw new Exception($"Cannot find game for Id {id}");
            }

            var entity = _lgRepo.GetSingle(lg => lg.Games.Any(gm => gm.Id == id) && lg.Id == leagueId);

            if (entity != null)
            {
                throw new Exception($"Cannot add league to game. League Id '{leagueId}' was previously added.");
            }

            entity = _lgRepo.GetSingle(lg => lg.Id == leagueId);
            if (entity == null)
            {
                throw new Exception($"Cannot find league for Id {leagueId}");
            }
            _repo.AddLeague(id, leagueId);
        }