Ejemplo n.º 1
0
        public void Handle(LeaveLeagueCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                Team team = dbContext.Teams.SingleOrDefault(t => t.Id == command.TeamId);

                if (team == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                League league = dbContext.Leagues.SingleOrDefault(l => l.Teams.Contains(team));

                if (league == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                team.LeaveLeague(league);

                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public void Handle(SendMessageCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                // TODO

                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public void Handle(RemoveTeamCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                Team team = dbContext.Teams.SingleOrDefault(l => l.ManagerId == command.Id);

                dbContext.Teams.Remove(team);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public void Handle(RemovePlayerCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                Player player = dbContext.Players.SingleOrDefault(l => l.Id == command.PlayerId);

                dbContext.Players.Remove(player);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        public void Handle(CreateTeamCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                Team team = CreateTeamEntity(command);

                dbContext.Teams.Add(team);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 6
0
        public void Handle(RemoveLeagueCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                League league = dbContext.Leagues.FirstOrDefault(l => l.OrganizerId == command.Id);

                dbContext.Leagues.Remove(league);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        public void Handle(CreateLeagueCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                League league = CreateLeagueEntity(command);

                dbContext.Leagues.Add(league);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 8
0
        public void Handle(AddPlayerCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                Team   team   = dbContext.Teams.SingleOrDefault(l => l.Id == command.TeamId);
                Player player = CreatePlayerEntity(command, team);

                dbContext.Players.Add(player);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 9
0
        public void Handle(AddLeagueNoteCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                League     league = dbContext.Leagues.SingleOrDefault(l => l.Id == command.LeagueId);
                LeagueNote note   = CreateNoteEntity(command, league);

                dbContext.LeagueNotes.Add(note);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 10
0
        public void Handle(JoinLeagueCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                League league = dbContext.Leagues.SingleOrDefault(l => l.Id == command.LeagueId);
                Team   team   = dbContext.Teams.SingleOrDefault(l => l.Id == command.TeamId);

                JoinToLeague(league, team);

                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 11
0
        public void Handle(UpdateCoachCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                Team team = dbContext.Teams.SingleOrDefault(l => l.Id == command.TeamId);

                if (team == null || team.Coach == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                UpdateCoach(team.Coach, command);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 12
0
        public void Handle(UpdateRegulationsCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                League league = dbContext.Leagues.SingleOrDefault(l => l.Id == command.LeagueId);

                if (league == null || league.Regulations == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                UpdateRegulations(league.Regulations, command);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 13
0
        public void Handle(UpdateTeamStatusCommand command)
        {
            // TODO validate

            using (var dbContext = new ManagementDataContext())
            {
                League league = dbContext.Leagues.SingleOrDefault(l => l.Id == command.LeagueId);
                Team   team   = dbContext.Teams.SingleOrDefault(l => l.Id == command.TeamId);

                if (league == null || league.TeamsWaitingForApprove == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                if (team == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                UpdateTeamStatus(league, team, command.Accept);
                dbContext.SaveChanges();
            }
        }