public void MergeAthlete(Guid destinationAthleteGUID, Guid sourceAthleteGUID) { using (var db = new IntiDataContext(_connectionString)) { var destinationAthlete = db.Inti_Athlete.Single(a => a.GUID == destinationAthleteGUID); var sourceAthlete = db.Inti_Athlete.Single(a => a.GUID == sourceAthleteGUID); //check for conflicting athleteclub-references - both instances of the athlete can't be present in the same tournament foreach (var destAthleteClub in destinationAthlete.Inti_AthleteClub) { if ( sourceAthlete.Inti_AthleteClub.Any( ac => ac.Inti_Club.TournamentGUID == destAthleteClub.Inti_Club.TournamentGUID)) { var tournament = db.Inti_Tournament.Single(t => t.GUID == destAthleteClub.Inti_Club.TournamentGUID); throw new Exception("Conflict in tournament: " + tournament.Name); } } //move athletes club-references to the dest athlete //move athletes team-references to the dest athlete //move all referenced point events to the dest athlete //delete all of the old } }
public void ToggleUserFavoriteTeam(Guid teamGUID) { if (SessionProperties.UserGuid == Guid.Empty) { return; } using (var db = new IntiDataContext(_connectionString)) { var userFavoriteTeam = from uft in db.Ext_UserFavoriteTeam where uft.UserGUID == SessionProperties.UserGuid && uft.TeamGUID == teamGUID select uft; if (userFavoriteTeam.ToList().Count > 0) { db.Ext_UserFavoriteTeam.DeleteAllOnSubmit(userFavoriteTeam); } else { var newUserFavoriteTeam = new Ext_UserFavoriteTeam(); newUserFavoriteTeam.UserGUID = SessionProperties.UserGuid; newUserFavoriteTeam.TeamGUID = teamGUID; db.Ext_UserFavoriteTeam.InsertOnSubmit(newUserFavoriteTeam); } db.SubmitChanges(); } }
public Inti_AthleteClub GetAthleteClubByTournament(Guid athleteId, Guid tournamentId) { using (var db = new IntiDataContext(_connectionString)) { var dlo = new DataLoadOptions(); dlo.LoadWith <Inti_AthleteClub>(ac => ac.Inti_Club); dlo.LoadWith <Inti_AthleteClub>(ac => ac.Inti_Position); dlo.LoadWith <Inti_AthleteClub>(ac => ac.Inti_Athlete); db.LoadOptions = dlo; var athleteClubs = from ac in db.Inti_AthleteClub where ac.AthleteGUID == athleteId && ac.Inti_Club.TournamentGUID == tournamentId select ac; if (athleteClubs.ToList().Count == 1) { var athleteClub = athleteClubs.ToList()[0]; return(athleteClub); } if (athleteClubs.ToList().Count > 1) { throw new ArgumentException("More than one club for the athlete with id {0} in the same tournament.", athleteId.ToString()); } } return(null); }
public Inti_Position GetPosition(string positionCode) { using (var db = new IntiDataContext(_connectionString)) { return(db.Inti_Position.Single(p => p.ShortName == positionCode)); } }
public bool ValidateUser(string email, string password) { if (String.IsNullOrEmpty(email)) { throw new IntiGeneralException("Du måste ange en epostadress"); } if (String.IsNullOrEmpty(password)) { throw new IntiGeneralException("Du måste ange ett lösenord"); } using (var db = new IntiDataContext(_connectionString)) { var users = from u in db.Sys_User where u.UserName == email select u; if (users.Count() != 1) { //todo: log failed sign in attempt throw new IntiGeneralException("Inloggningen misslyckades"); } var user = users.ToList()[0]; if (!user.Password.Equals(password)) { //todo: log failed sign in attempt throw new IntiGeneralException("Inloggningen misslyckades"); } } return(true); }
public string ForgotPassword(string email) { if (String.IsNullOrEmpty(email)) { throw new IntiGeneralException("Du måste ange en epostadress"); } using (var db = new IntiDataContext(_connectionString)) { var users = from u in db.Sys_User where u.UserName == email select u; if (users.Count() != 1) { throw new IntiGeneralException("Hittar ingen användare med den epostadressen"); } var user = users.ToList()[0]; user.Password = GetRandomPassword(); db.SubmitChanges(); //send mail MailAndLog.SendMessage(Parameters.Instance.ForgotPasswordSubject, String.Format(Parameters.Instance.ForgotPasswordBody, user.Password), Parameters.Instance.MailSender, email); return(user.Password); } }
public void RemoveDuplicateTransfers(IntiDataContext db, Guid teamId) { var summary = from tf in db.Inti_TeamTransfer where tf.TeamGUID == teamId group tf by new { tf.TransferDate, tf.AthleteInGUID, tf.AthleteOutGUID } into dup select new { dup.Key.TransferDate, dup.Key.AthleteInGUID, dup.Key.AthleteOutGUID, Count = dup.Count() }; var duplicates = summary.Where(s => s.Count > 1).ToList(); foreach (var duplicate in duplicates) { //remove one of the duplicates var toDelete = db.Inti_TeamTransfer.FirstOrDefault( tf => tf.TeamGUID == teamId && tf.TransferDate == duplicate.TransferDate && tf.AthleteInGUID == duplicate.AthleteInGUID && tf.AthleteOutGUID == duplicate.AthleteOutGUID); if (toDelete == null) { continue; } db.Inti_TeamTransfer.DeleteOnSubmit(toDelete); } db.SubmitChanges(); }
public static IList <Inti_Athlete> SearchForAthletes(IntiDataContext db, string searchString) { var splitString = searchString.Replace(",", "").Split(new char[] { ' ' }); IQueryable <Inti_Athlete> athletes = null; if (splitString.Length == 1) { athletes = from a in db.Inti_Athlete where a.FirstName.StartsWith(splitString[0]) || a.LastName.StartsWith(splitString[0]) select a; } if (splitString.Length >= 2) { athletes = from a in db.Inti_Athlete where (a.FirstName.StartsWith(splitString[0]) && a.LastName.StartsWith(splitString[1])) || (a.FirstName.StartsWith(splitString[1]) && a.LastName.StartsWith(splitString[0])) select a; } if (athletes != null) { return(athletes.ToList()); } return(null); }
public IList <Ext_ChangeLog> GetChangeLog(IntiDataContext db, Guid objectId) { var q = from cl in db.Ext_ChangeLog where cl.ObjectGUID == objectId select cl; return(q.ToList()); }
public IList <Ext_ChangeLog> GetChangeLog(IntiDataContext db, Type type) { var q = from cl in db.Ext_ChangeLog where cl.ObjectType == type.Name select cl; return(q.ToList()); }
public void LoadClubEvaluation(Guid clubGuid, IntiDataContext db) { var athletes = GetAthletesForClub(clubGuid, db); LoadStakeholders(athletes.ToList(), db); lblHeader.Text = "Lag med intressen"; }
private void InitParameters() { using (var db = new IntiDataContext(_connectionString)) { var parameters = from param in db.Sys_Parameter select param; foreach (var parameter in parameters) { switch (parameter.Name) { case "MailServer": mailServer = parameter.Value; break; case "MailServerPort": mailServerPort = parameter.Value; break; case "MailServerAuthenticate": mailServerAuthenticate = parameter.Value; break; case "MailServerUserName": mailServerUserName = parameter.Value; break; case "MailServerPassword": mailServerPassword = parameter.Value; break; case "MailSender": mailSender = parameter.Value; break; case "ForgotPasswordSubject": forgotPasswordSubject = parameter.Value; break; case "ForgotPasswordBody": forgotPasswordBody = parameter.Value; break; case "SupportMail": supportMail = parameter.Value; break; case "TwitterAccessToken": twitterAccessToken = parameter.Value; break; case "TwitterAccessTokenSecret": twitterAccessTokenSecret = parameter.Value; break; } } } }
public void UpdateParameters() { using (var db = new IntiDataContext(_connectionString)) { //done //AddParameter(db, "TwitterAccessToken"); //AddParameter(db, "TwitterAccessTokenSecret"); } }
public void RegisterUser(string firstName, string lastName, string email, string password) { if (String.IsNullOrEmpty(firstName)) { throw new IntiGeneralException("Du måste ange ett förnamn"); } if (String.IsNullOrEmpty(lastName)) { throw new IntiGeneralException("Du måste ange ett efternamn"); } if (String.IsNullOrEmpty(email)) { throw new IntiGeneralException("Du måste ange en epostadress"); } if (String.IsNullOrEmpty(password)) { throw new IntiGeneralException("Du måste ange ett lösenord"); } using (var db = new IntiDataContext(_connectionString)) { //username/email must be unique var users = from u in db.Sys_User where u.UserName.ToLower() == email.ToLower() select u; if (users.ToList().Count > 0) { throw new IntiGeneralException("Det finns redan en användare med den epostadressen"); } var user = new Sys_User { FirstName = firstName, LastName = lastName, UserName = email, Password = password }; db.Sys_User.InsertOnSubmit(user); //default permissions var defaultPermissions = from p in db.Sys_Permission where p.Name == "USER" || p.Name == "USER_PVTTOUR" select p; foreach (var perm in defaultPermissions.ToList()) { var userPerm = new Sys_UserPermission(); userPerm.UserGUID = user.GUID; userPerm.PermissionGUID = perm.GUID; db.Sys_UserPermission.InsertOnSubmit(userPerm); } db.SubmitChanges(); } }
public IList <Ext_News> GetAllNews(int pageSize, int pageIndex) { using (var db = new IntiDataContext(_connectionString)) { var news = from n in db.Ext_News select n; return(news.OrderByDescending(order => order.ValidFrom).Take(pageSize).Skip(pageSize * pageIndex).ToList()); } }
private void LoadMatches(Guid clubGuid, IntiDataContext db) { var matches = from m in db.Inti_Match where m.AwayClub == clubGuid || m.HomeClub == clubGuid orderby m.MatchDate ?? DateTime.Now.AddYears(1) select new MatchDTO(m); rptMatches.DataSource = matches; rptMatches.DataBind(); }
public void LoadPreMatchEvaluation(Inti_Match match, IntiDataContext db) { //get a list of athletes represented in teams, sorted by total scores var highestScoringHomeAthletes = GetAthletesForClub(match.HomeClub, db); var highestScoringAwayAthletes = GetAthletesForClub(match.AwayClub, db); LoadStakeholders(highestScoringHomeAthletes.Union(highestScoringAwayAthletes).ToList(), db); lblHeader.Text = "Lag med intressen"; }
public Inti_Club GetClubByCode(Guid selectedTournament, string clubCode) { using (var db = new IntiDataContext(_connectionString)) { var club = db.Inti_Club.Single(c => c.ShortName == clubCode && c.TournamentGUID == selectedTournament); return(club); } }
private void LoadStakeholders(IList <MatchPreviewAthleteDTO> athleteDtos, IntiDataContext db) { var userFavorites = from utf in db.Ext_UserFavoriteTeam where utf.UserGUID == SessionProps.UserGuid select utf; //for each of these players, get a reference to the teams that has selected them var teams = new Dictionary <Guid, MatchPreviewTeamDTO>(10); foreach (var athlete in athleteDtos) { var teamVersions = (from ta in db.Inti_TeamAthlete join u in userFavorites on ta.Inti_TeamVersion.Inti_Team equals u.Inti_Team into oj from utf in oj.DefaultIfEmpty() where (ta.Inti_TeamVersion.Inti_Team.IsPaid ?? false) && (ta.Inti_TeamVersion.Inti_Team.IsActive ?? false) && ta.Inti_TeamVersion.ValidFrom <= DateTime.Today && (ta.Inti_TeamVersion.ValidTo ?? DateTime.Today) >= DateTime.Today && ta.AthleteGUID == athlete.AthleteClubGuid select new MatchPreviewTeamDTO() { TeamGuid = ta.Inti_TeamVersion.TeamGUID, TeamName = ta.Inti_TeamVersion.Inti_Team.Name, Manager = String.Format("{0} {1}", ta.Inti_TeamVersion.Inti_Team.Sys_User.FirstName, ta.Inti_TeamVersion.Inti_Team.Sys_User.LastName).Trim(), CustomClass = (SessionProps.UserGuid == utf.UserGUID) ? "active" : "list-group-item-info" }).ToList(); foreach (var matchPreviewTeamDTO in teamVersions.Where(matchPreviewTeamDTO => !teams.ContainsKey(matchPreviewTeamDTO.TeamGuid))) { teams.Add(matchPreviewTeamDTO.TeamGuid, matchPreviewTeamDTO); } foreach (var matchPreviewTeamDTO in teamVersions) { teams[matchPreviewTeamDTO.TeamGuid].Athletes.Add(new AthleteSubDTO() { AthleteClubGuid = athlete.AthleteClubGuid, Name = athlete.Name }); } } var allData = new AllDataDTO(); allData.Athletes = athleteDtos.ToArray(); allData.Teams = teams.Values.OrderByDescending(t => t.Athletes.Count).ToArray(); //set PreviewData to the Json object for jsRender to work with PreviewData = JsonConvert.SerializeObject(allData); }
public Sys_User GetUserByName(string name) { using (var db = new IntiDataContext(_connectionString)) { var userQ = from u in db.Sys_User where u.UserName == name select u; return(userQ.ToList()[0]); } }
public Sys_User GetUserByGuid(Guid userGuid) { using (var db = new IntiDataContext(_connectionString)) { var userQ = from u in db.Sys_User where u.GUID == userGuid select u; return(userQ.ToList()[0]); } }
/// <summary> /// Returns a disconnected team /// </summary> /// <param name="teamGUID"></param> /// <returns></returns> public Inti_Team GetTeam(Guid teamGUID) { Inti_Team team; using (var db = new IntiDataContext(_connectionString)) { team = db.Inti_Team.Single(t => t.GUID == teamGUID); } return(team); }
public IList <Sys_Permission> GetUserPermissions(string email) { using (var db = new IntiDataContext(_connectionString)) { var permissions = from perm in db.Sys_UserPermission where perm.Sys_User.UserName == email select perm.Sys_Permission; return(permissions.ToList()); } }
public Ext_News GetNewsItem(Guid newsGuid) { using (var db = new IntiDataContext(_connectionString)) { var news = from n in db.Ext_News where n.GUID == newsGuid select n; return(news.ToList()[0]); } }
public int GetNumberOfNews() { using (var db = new IntiDataContext(_connectionString)) { var news = from n in db.Ext_News where n.ValidFrom <= DateTime.Now && (n.ValidTo == null || n.ValidTo >= DateTime.Now) select n; return(news.ToList().Count); } }
public void SetUpdater(Guid matchId) { using (var db = new IntiDataContext(_connectionString)) { var match = db.Inti_Match.Single(m => m.GUID == matchId); match.Updater = SessionProperties.UserGuid; match.StartUpdateDate = DateTime.Now; db.SubmitChanges(); } }
public IList <Ext_News> GetNews(int pageSize, int pageIndex) { using (var db = new IntiDataContext(_connectionString)) { var news = from n in db.Ext_News where n.ValidFrom <= DateTime.Now && (n.ValidTo == null || n.ValidTo >= DateTime.Now) select n; return(news.OrderByDescending(order => order.ValidFrom).Skip(pageSize * pageIndex).Take(pageSize).ToList()); } }
public IList <Inti_Team> GetTeamsForUser(Guid user, Guid tournament) { using (var db = new IntiDataContext(_connectionString)) { var teams = from t in db.Inti_Team where t.Sys_User.GUID == user && t.Inti_Tournament.GUID == tournament select t; return(teams.ToList()); } }
public void UpdateTeamImage(Guid teamGUID, string imageName) { using (var db = new IntiDataContext(_connectionString)) { var team = db.Inti_Team.Single(t => t.GUID == teamGUID); team.Picture = imageName; db.SubmitChanges(); LogEvent(teamGUID, typeof(Inti_Team), SessionProperties.UserGuid, SessionProperties.ClientInfo, EventType.Update, "Ändrat bild"); } }
public IList <Inti_Tournament> AllTournaments() { IList <Inti_Tournament> listToReturn = null; using (var db = new IntiDataContext(_connectionString)) { var tours = from t in db.Inti_Tournament select t; listToReturn = tours.OrderByDescending(t => t.EndRegistration).ToList(); } return(listToReturn); }