//inside the first transaction so dont call savechanges !
        public void CreateSummonersGames(Summoner summoner)
        {
            var assasinGame = db.Games.First(g => g.Name == "Assassin");
            SummonersGame assasin = new SummonersGame();
            assasin.Game = assasinGame;
            assasin.Summoner = summoner;

            db.SummonersGames.Add(assasin);

            var fighterGame = db.Games.First(g => g.Name == "Fighter");
            SummonersGame fighter = new SummonersGame();
            fighter.Game = fighterGame;
            fighter.Summoner = summoner;

            db.SummonersGames.Add(fighter);

            var mageGame = db.Games.First(g => g.Name == "Mage");
            SummonersGame mage = new SummonersGame();
            mage.Game = mageGame;
            mage.Summoner = summoner;

            db.SummonersGames.Add(mage);

            var supportGame = db.Games.First(g => g.Name == "Support");
            SummonersGame support = new SummonersGame();
            support.Game = supportGame;
            support.Summoner = summoner;

            db.SummonersGames.Add(support);

            var tankGame = db.Games.First(g => g.Name == "Tank");
            SummonersGame tank = new SummonersGame();
            tank.Game = tankGame;
            tank.Summoner = summoner;

            db.SummonersGames.Add(tank);

            var marksmanGame = db.Games.First(g => g.Name == "Marksman");
            SummonersGame marksman = new SummonersGame();
            marksman.Game = marksmanGame;
            marksman.Summoner = summoner;

            db.SummonersGames.Add(marksman);
        }
        /// <summary>
        /// The executor is the summoner itself so it is a personal event !
        /// </summary>
        public void logRegistration(Summoner registeredSummoner)
        {
            try
            {
                Log log = new Log();
                log.ExecutorId = registeredSummoner.SummonerId;
                log.EventId = (int)Events.NewSummonerRegistration;
                log.Description = string.Format("Summoner with the name: {0} was registered!", registeredSummoner.Username);
                log.Date = DateTime.Now;

                db.Logs.Add(log);

                db.SaveChanges();
            }
            catch (Exception exc)
            {
                //Propagate so it is catched in the higher trycatch block
                throw new Exception("LoggException - registration", exc);
            }
        }
        public Summoner Register(SummonerModel newSummoner)
        {
            Summoner summoner = new Summoner();
            summoner.DeviceId = newSummoner.DeviceId;
            summoner.Username = newSummoner.Username;
            summoner.LoLUsername = newSummoner.LolAccount;
            summoner.DateRegistered = DateTime.Now;

            if (newSummoner.Server > 0)
            {
                summoner.Server1 = db.Servers.First(s => s.ServerId == newSummoner.Server);
            }

            db.Summoners.Add(summoner);
            this.CreateSummonersGames(summoner);

            db.SaveChanges();

            return summoner;
        }
        public void logSummonerDeleted(Summoner summoner, HttpContext httpContext)
        {
            try
            {
                string adminCode = httpContext.User.Identity.Name;
                var admin = db.Admins.First(a => a.Code.ToLower() == adminCode.ToLower());

                Log log = new Log();
                log.ExecutorId = admin.AdminId;
                log.EventId = (int)Events.SummonerDeleted;
                log.Description = string.Format("Summoner {0} was deleted by {1}", summoner.Username, admin.Name);
                log.Date = DateTime.Now;

                db.Logs.Add(log);

                db.SaveChanges();
            }
            catch (Exception exc)
            {
                throw new Exception("LoggException - SummonerDeleted", exc);
            }
        }