Exemple #1
0
        public static List <User> LoadFriends(User user)
        {
            using (BoBEntities bob = new BoBEntities())
            {
                List <Relationship> friends = new List <Relationship>();

                bob.tblRelationships
                .Where(f => (f.FriendId == user.Id || f.SenderId == user.Id) && f.isFriend)
                .ToList()
                .ForEach(f => friends.Add(new Relationship
                {
                    Id        = f.Id,
                    Friend1   = UserManager.LoadById(f.SenderId),
                    Friend2   = UserManager.LoadById(f.FriendId),
                    StartDate = f.FriendDate,
                    isFriend  = f.isFriend
                }));

                List <User> users = new List <User>();
                foreach (var friend in friends)
                {
                    if (friend.Friend1 == user)
                    {
                        users.Add(friend.Friend2);
                    }
                    else
                    {
                        users.Add(friend.Friend1);
                    }
                }
                return(users);
            }
        }
Exemple #2
0
 public static int Delete(Guid id)
 {
     try
     {
         using (BoBEntities bob = new BoBEntities())
         {
             tblBracket row     = bob.tblBrackets.FirstOrDefault(c => c.Id == id);
             int        results = 0;
             if (row != null)
             {
                 bob.tblBrackets.Remove(row);
                 results = bob.SaveChanges();
             }
             else
             {
                 throw new Exception("Row was not found");
             }
             return(results);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #3
0
 public static bool isRelated(User user1, User user2)
 {
     using (BoBEntities bob = new BoBEntities())
     {
         return(bob.tblRelationships
                .Where(f => (f.FriendId == user1.Id || f.SenderId == user1.Id) && (f.FriendId == user2.Id || f.SenderId == user2.Id)).Count()
                == 1);
     }
 }
Exemple #4
0
 public static User LoadById(Guid id)
 {
     using (BoBEntities bob = new BoBEntities())
     {
         tblUser row = bob.tblUsers.FirstOrDefault(u => u.Id == id);
         return(new User {
             Id = row.Id, FirstName = row.FirstName, LastName = row.LastName, Username = row.Username, ImageSource = row.ImageSource, Password = row.Password
         });
     }
 }
Exemple #5
0
        public static int Delete(Guid id)
        {
            using (BoBEntities bob = new BoBEntities())
            {
                tblRelationship row = bob.tblRelationships.FirstOrDefault(r => id == r.Id);

                bob.tblRelationships.Remove(row);

                return(bob.SaveChanges());
            }
        }
Exemple #6
0
 public static Bracket LoadById(Guid id)
 {
     using (BoBEntities bob = new BoBEntities())
     {
         tblBracket row = bob.tblBrackets
                          .FirstOrDefault(b => b.Id == id);
         return(new BL.Bracket {
             CurrentDivision = row.CurrentDivision, Id = row.Id, ImageSource = row.ImageSource, Moderator = UserManager.LoadById(row.ModeratorId), Name = row.Name, Matches = MatchManager.Load(row.Id), Game = row.Game, OriginalRoundCount = row.OriginalRoundCount
         });
     }
 }
Exemple #7
0
        public static int Update(Relationship relationship)
        {
            using (BoBEntities bob = new BoBEntities())
            {
                tblRelationship row = bob.tblRelationships.FirstOrDefault(r => relationship.Id == r.Id);

                row.isFriend = relationship.isFriend;

                return(bob.SaveChanges());
            }
        }
Exemple #8
0
        public static int Delete(Guid id)
        {
            using (BoBEntities bob = new BoBEntities())
            {
                tblMatch row = bob.tblMatches.FirstOrDefault(m => m.Id == id);

                if (row != null)
                {
                    bob.tblMatches.Remove(row);
                }
                return(bob.SaveChanges());
            }
        }
Exemple #9
0
 public static bool Login(User user)
 {
     try
     {
         if (!string.IsNullOrEmpty(user.Username.ToString()))
         {
             if (!string.IsNullOrEmpty(user.Password))
             {
                 using (BoBEntities bob = new BoBEntities())
                 {
                     tblUser tblUser = bob.tblUsers.FirstOrDefault(u => u.Username == user.Username);
                     if (tblUser != null)
                     {
                         //Check password
                         if (tblUser.Password == GetHash(user.Password))
                         {
                             //User could login
                             user.FirstName   = tblUser.FirstName;
                             user.LastName    = tblUser.LastName;
                             user.ImageSource = tblUser.ImageSource;
                             user.Id          = tblUser.Id;
                             return(true);
                         }
                         else
                         {
                             throw new Exception("Could not login with these credentials");
                         }
                     }
                     else
                     {
                         throw new Exception("UserId could not be found");
                     }
                 }
             }
             else
             {
                 throw new Exception("Password was not set");
             }
         }
         else
         {
             throw new Exception("UserId was not set");
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #10
0
 public static int Insert(Relationship relationship)
 {
     using (BoBEntities bob = new BoBEntities())
     {
         tblRelationship row = new tblRelationship
         {
             Id         = Guid.NewGuid(),
             SenderId   = relationship.Friend1.Id,
             FriendId   = relationship.Friend2.Id,
             isFriend   = relationship.isFriend,
             FriendDate = DateTime.Now
         };
         relationship.Id = row.Id;
         bob.tblRelationships.Add(row);
         return(bob.SaveChanges());
     }
 }
Exemple #11
0
 public static int Update(Match match)
 {
     using (BoBEntities bob = new BoBEntities())
     {
         tblMatch row = bob.tblMatches.FirstOrDefault(m => m.Id == match.Id);
         if (row != null)
         {
             row.Team1           = match.Player1.Id;
             row.Team2           = match.Player2.Id;
             row.Outcome         = match.Winner.Id;
             row.ReportingPlayer = match.ReportingPlayer.Id;
             row.Round           = match.Round;
             row.Division        = match.Division;
         }
         return(bob.SaveChanges());
     }
 }
Exemple #12
0
        public static Relationship LoadById(Guid id)
        {
            using (BoBEntities bob = new BoBEntities())
            {
                tblRelationship row = bob.tblRelationships.FirstOrDefault(r => r.Id == id);

                Relationship relationship = new Relationship
                {
                    Id        = row.Id,
                    Friend1   = UserManager.LoadById(row.SenderId),
                    Friend2   = UserManager.LoadById(row.FriendId),
                    isFriend  = row.isFriend,
                    StartDate = row.FriendDate
                };
                return(relationship);
            }
        }
Exemple #13
0
 public static Match LoadById(Guid id)
 {
     using (BoBEntities bob = new BoBEntities())
     {
         tblMatch row = bob.tblMatches.FirstOrDefault(m => m.Id == id);
         return(new Match
         {
             Id = row.Id,
             Player1 = UserManager.LoadById(row.Team1),
             Player2 = UserManager.LoadById(row.Team2),
             Winner = UserManager.LoadById(row.Outcome),
             BracketId = row.BracketId,
             ReportingPlayer = UserManager.LoadById(row.ReportingPlayer),
             Round = row.Round,
             Division = row.Division
         });
     }
 }
Exemple #14
0
 public static List <User> Load()
 {
     using (BoBEntities bob = new BoBEntities())
     {
         List <User> users = new List <User>();
         bob.tblUsers
         .ToList()
         .ForEach(u => users.Add(new BL.User
         {
             Id          = u.Id,
             FirstName   = u.FirstName,
             LastName    = u.LastName,
             Password    = u.Password,
             Username    = u.Username,
             ImageSource = u.ImageSource
         }));
         return(users);
     }
 }
Exemple #15
0
 public static int Insert(User user)
 {
     using (BoBEntities bob = new BoBEntities())
     {
         tblUser row = new tblUser
         {
             Id          = Guid.NewGuid(),
             FirstName   = user.FirstName,
             LastName    = user.LastName,
             Password    = GetHash(user.Password),
             Username    = user.Username,
             ImageSource = user.ImageSource
         };
         bob.tblUsers.Add(row);
         user.Id       = row.Id;
         user.Password = row.Password;
         return(bob.SaveChanges());
     }
 }
Exemple #16
0
 public static int Insert(Match match, Guid bracketid)
 {
     using (BoBEntities bob = new BoBEntities())
     {
         tblMatch row = new tblMatch
         {
             Id              = Guid.NewGuid(),
             Team1           = match.Player1.Id,
             Team2           = match.Player2.Id,
             Outcome         = match.Winner.Id,
             BracketId       = bracketid,
             ReportingPlayer = match.ReportingPlayer.Id,
             Round           = match.Round,
             Division        = match.Division
         };
         match.Id = row.Id;
         bob.tblMatches.Add(row);
         return(bob.SaveChanges());
     }
 }
Exemple #17
0
        public static List <Relationship> LoadUnapprovedReceived(User user)
        {
            using (BoBEntities bob = new BoBEntities())
            {
                List <Relationship> friends = new List <Relationship>();

                bob.tblRelationships
                .Where(f => f.FriendId == user.Id && !f.isFriend)
                .ToList()
                .ForEach(f => friends.Add(new Relationship
                {
                    Id        = f.Id,
                    Friend1   = UserManager.LoadById(f.SenderId),
                    Friend2   = UserManager.LoadById(f.FriendId),
                    StartDate = f.FriendDate,
                    isFriend  = f.isFriend
                }));
                return(friends);
            }
        }
Exemple #18
0
 public static List <Match> Load()
 {
     using (BoBEntities bob = new BoBEntities())
     {
         List <Match> matches = new List <Match>();
         bob.tblMatches
         .ToList()
         .ForEach(m => matches.Add(new Match
         {
             Id              = m.Id,
             Player1         = UserManager.LoadById(m.Team1),
             Player2         = UserManager.LoadById(m.Team2),
             Winner          = UserManager.LoadById(m.Outcome),
             BracketId       = m.BracketId,
             ReportingPlayer = UserManager.LoadById(m.ReportingPlayer),
             Round           = m.Round,
             Division        = m.Division
         }));
         return(matches);
     }
 }
Exemple #19
0
 public static List <Bracket> Load()
 {
     using (BoBEntities bob = new BoBEntities())
     {
         List <Bracket> brackets = new List <Bracket>();
         bob.tblBrackets
         .ToList()
         .ForEach(b => brackets.Add(new Bracket
         {
             Id                 = b.Id,
             Moderator          = UserManager.LoadById(b.ModeratorId),
             Name               = b.Name,
             ImageSource        = b.ImageSource,
             Matches            = MatchManager.Load(b.Id),
             Game               = b.Game,
             OriginalRoundCount = b.OriginalRoundCount,
             CurrentDivision    = b.CurrentDivision
         }));
         return(brackets);
     }
 }
Exemple #20
0
        public static int Update(User user)
        {
            using (BoBEntities bob = new BoBEntities())
            {
                tblUser row     = bob.tblUsers.FirstOrDefault(c => c.Id == user.Id);
                int     results = 0;
                if (row != null)
                {
                    row.FirstName   = user.FirstName;
                    row.LastName    = user.LastName;
                    row.Password    = GetHash(user.Password);
                    row.Username    = user.Username;
                    row.ImageSource = user.ImageSource;

                    results = bob.SaveChanges();
                }
                else
                {
                    throw new Exception("Row was not found");
                }
                return(results);
            }
        }
Exemple #21
0
 public static int Update(Bracket bracket)
 {
     using (BoBEntities bob = new BoBEntities())
     {
         tblBracket row     = bob.tblBrackets.FirstOrDefault(c => c.Id == bracket.Id);
         int        results = 0;
         if (row != null)
         {
             row.Name               = bracket.Name;
             row.ModeratorId        = bracket.Moderator.Id;
             row.ImageSource        = bracket.ImageSource;
             row.OriginalRoundCount = bracket.OriginalRoundCount;
             row.Game               = bracket.Game;
             row.CurrentDivision    = bracket.CurrentDivision;
             results = bob.SaveChanges();
         }
         else
         {
             throw new Exception("Row was not found");
         }
         return(results);
     }
 }
Exemple #22
0
        public static int Insert(Bracket bracket)
        {
            using (BoBEntities bob = new BoBEntities())
            {
                tblBracket row = new tblBracket
                {
                    Id                 = Guid.NewGuid(),
                    Name               = bracket.Name,
                    ImageSource        = bracket.ImageSource,
                    ModeratorId        = bracket.Moderator.Id,
                    Game               = bracket.Game,
                    OriginalRoundCount = bracket.OriginalRoundCount,
                    CurrentDivision    = bracket.CurrentDivision
                };

                bracket.Id = row.Id;
                if (bracket.Matches.Count > 0)
                {
                    bracket.Matches.ForEach(m => MatchManager.Insert(m, bracket.Id));
                }
                bob.tblBrackets.Add(row);
                return(bob.SaveChanges());
            }
        }