示例#1
0
        public void CreateLeague(string name, string type, int userid)
        {
            using (var db = new MyLeaguesEntities())
            {
                League l = new League();
                l.LeagueName  = name;
                l.LeagueType  = type;
                l.CreatedOn   = DateTime.Now;
                l.IsDeleted   = false;
                l.MemberCount = 1;
                db.Leagues.Add(l);
                db.SaveChanges();

                UserLeague ul = new UserLeague();
                ul.UserID        = userid;
                ul.PointsAllowed = 0;
                ul.PointsScored  = 0;
                ul.Wins          = 0;
                ul.Losses        = 0;
                ul.LeagueID      = l.ID;
                ul.IsDeleted     = false;
                ul.CreatedOn     = DateTime.Now;
                db.UserLeagues.Add(ul);
                db.SaveChanges();
            }
        }
        public IHttpActionResult PostUserLeague(UserLeague userLeague)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.UserLeagues.Add(userLeague);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = userLeague.ID }, userLeague));
        }
示例#3
0
        public IHttpActionResult PostGame(Game game)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Games.Add(game);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = game.ID }, game));
        }
示例#4
0
        public SecurityToken GenerateSecurityToken(int id)
        {
            var token = db.SecurityTokens.Create();

            token.UserID       = id;
            token.CreatedOn    = DateTime.Now;
            token.SessionToken = SecurityService.GenerateSecurityToken();
            token.isValid      = true;
            db.Configuration.LazyLoadingEnabled = false;
            db.SecurityTokens.Add(token);
            db.SaveChanges();
            return(token);
        }
示例#5
0
 public void LeaveLeague(int userleagueid)
 {
     using (var db = new MyLeaguesEntities())
     {
         var userleague = db.UserLeagues.Where(x => x.ID == userleagueid).FirstOrDefault();
         userleague.IsDeleted = true;
         db.SaveChanges();
     }
 }
 public static User CreateAccount(User user)
 {
     using (var db = new MyLeaguesEntities())
     {
         user.Salt     = GetRandomSalt(20);
         user.Password = sha256_hash(user.Password + user.Salt);
         db.Users.Add(user);
         db.SaveChanges();
         return(db.Users.Where(x => x.Email == user.Email).FirstOrDefault());
     }
 }
示例#7
0
 public void InviteUser(int userid, int inviteeid, int leagueid, string message)
 {
     using (var db = new MyLeaguesEntities())
     {
         var request = db.LeagueRequests.Create();
         request.UserID    = userid;
         request.InviteeID = inviteeid;
         request.LeagueID  = leagueid;
         request.Message   = message;
         request.CreatedOn = DateTime.Now;
         request.IsDecided = false;
         db.LeagueRequests.Add(request);
         db.SaveChanges();
     }
 }
示例#8
0
        public IHttpActionResult DeleteLeague(int id)
        {
            using (var db = new MyLeaguesEntities())
            {
                League league = db.Leagues.Find(id);
                if (league == null)
                {
                    return(NotFound());
                }

                db.Leagues.Remove(league);
                db.SaveChanges();

                return(Ok(league));
            }
        }
示例#9
0
        public void CreateGame(int userid, int opponentid, int userscore, int opponentscore, int lat, int lng, int leagueid)
        {
            using (var db = new MyLeaguesEntities())
            {
                if (userid != opponentid)
                {
                    Game g = db.Games.Create();
                    g.UserID        = userid;
                    g.OpponentID    = opponentid;
                    g.UserScore     = userscore;
                    g.OpponentScore = opponentscore;
                    g.Latitude      = lat;
                    g.Longitude     = lng;
                    g.LeagueID      = leagueid;
                    g.CreatedOn     = DateTime.Now;
                    db.Games.Add(g);

                    var user = db.UserLeagues.Where(x => x.ID == userid).FirstOrDefault();
                    user.PointsScored  += userscore;
                    user.PointsAllowed += opponentscore;

                    var opponent = db.UserLeagues.Where(x => x.ID == opponentid).FirstOrDefault();
                    opponent.PointsScored  += opponentscore;
                    opponent.PointsAllowed += userscore;

                    if (userscore > opponentscore)
                    {
                        user.Wins++;
                        opponent.Losses++;
                    }
                    else if (userscore == opponentscore)
                    {
                        user.Ties++;
                        opponent.Ties++;
                    }
                    else
                    {
                        user.Losses++;
                        opponent.Wins++;
                    }
                    db.SaveChanges();
                }
            }
        }
示例#10
0
        public void AddUserToLeague(int userid, int leagueid)
        {
            using (var db = new MyLeaguesEntities())
            {
                if (db.UserLeagues.Where(x => x.UserID == userid && x.LeagueID == leagueid).Count() == 0)
                {
                    UserLeague ul = new UserLeague();
                    ul.UserID        = userid;
                    ul.PointsAllowed = 0;
                    ul.PointsScored  = 0;
                    ul.Wins          = 0;
                    ul.Losses        = 0;
                    ul.LeagueID      = leagueid;
                    ul.IsDeleted     = false;
                    ul.CreatedOn     = DateTime.Now;
                    db.UserLeagues.Add(ul);

                    League l = db.Leagues.Where(x => x.ID == leagueid).FirstOrDefault();
                    l.MemberCount++;

                    db.SaveChanges();
                }
            }
        }