public static Boolean AcceptMember(Member user, Team team, OnGameContext _db) { try { var teamRecruit = from t in _db.teamRecruits where t.memberID.ID == user.ID && t.teamID.ID == team.ID select t; if (teamRecruit.Count() == 1) { TeamRecruit tp = teamRecruit.First(); if (teamRecruit.Count() == 1) { try { _db.teamRecruits.Remove(_db.teamRecruits.Find(tp.ID)); _db.teamPlayers.Add(new TeamPlayer{ status = 2, memberID = _db.members.Find(user.ID), teamID = _db.teams.Find(team.ID) }); } catch (NullReferenceException NullEx) { Trace.WriteLine(NullEx.StackTrace); } _db.SaveChanges(); return true; } } return false; } catch (Exception ex) { Trace.WriteLine(ex.StackTrace); return false; } }
public static Boolean UpdateTeam(string description, Team model, OnGameContext _db) { Boolean success = false; Team teamDB = _db.teams.Find(model.ID); if (teamDB != null) { try { teamDB.description = description; _db.Entry(teamDB).State = EntityState.Modified; _db.SaveChanges(); success = true; } catch (Exception ex) { Trace.WriteLine(ex.Message); } } return success; }
public static Boolean LeaveTeam(Member user, Team team, OnGameContext _db) { try { var teamPlayer = from t in _db.teamPlayers where t.memberID.ID == user.ID && t.teamID.ID == team.ID select t; if (teamPlayer.Count() == 1) { TeamPlayer tp = teamPlayer.First(); if (tp.status == 3) { var teamPlayers = from tps in _db.teamPlayers where tps.teamID.ID == team.ID select tps; if (teamPlayers.Count() > 0) { try { teamPlayers.ToList<TeamPlayer>().ForEach(row => _db.teamPlayers.Remove(row)); } catch (NullReferenceException NullEx) { Trace.WriteLine(NullEx.StackTrace); } _db.SaveChanges(); } return true; } else { _db.teamPlayers.Remove(teamPlayer.First()); _db.SaveChanges(); return true; } } else { return false; } } catch (Exception ex) { Trace.WriteLine(ex.StackTrace); return false; } }
public static Boolean KickMember(Member user, Team team, OnGameContext _db) { try { var teamPlayer = from t in _db.teamPlayers where t.memberID.ID == user.ID && t.teamID.ID == team.ID select t; if (teamPlayer.Count() == 1) { TeamPlayer tp = teamPlayer.First(); if (tp.status != 3) { try { _db.teamPlayers.Remove(_db.teamPlayers.Find(tp.ID)); } catch (NullReferenceException NullEx) { Trace.WriteLine(NullEx.StackTrace); } _db.SaveChanges(); return true; } } return false; } catch (Exception ex) { Trace.WriteLine(ex.StackTrace); return false; } }
public static Boolean JoinTeam(Member user,Team team ,OnGameContext _db) { try { var teamRecruitModel = from t in _db.teamRecruits where t.memberID.ID == user.ID && t.teamID.ID == team.ID select t; if (teamRecruitModel.Count() == 0) { var teamPlayer = from tp in _db.teamPlayers where tp.memberID.ID == user.ID && tp.teamID.ID == team.ID select tp; if (teamPlayer.Count() == 0) { _db.teamRecruits.Add(new TeamRecruit { memberID = _db.members.Find(user.ID), teamID = _db.teams.Find(team.ID) }); _db.SaveChanges(); return true; } } return false; }catch(Exception ex){ Trace.WriteLine(ex.Message); return false; } }