Пример #1
0
        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
            }
        }
Пример #2
0
        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;
        }
Пример #3
0
 public Inti_Position GetPosition(string positionCode)
 {
     using (var db = new IntiDataContext(_connectionString))
     {
         return db.Inti_Position.Single(p => p.ShortName == positionCode);
     }
 }
Пример #4
0
        private void LoadPlayers(Guid clubGuid, IntiDataContext db)
        {
            //visa lineup
            var totalLineUp = from ac in db.Inti_AthleteClub
                              where ac.Inti_Club.GUID == clubGuid
                              && ((ac.IsActive ?? false) || ac.Inti_Position.ShortName == "MGR")
                              select new LineUp
                              {
                                  GUID = ac.GUID,
                                  Name = ac.Inti_Athlete.FirstName + " " + ac.Inti_Athlete.LastName,
                                  Club = ac.Inti_Club.Name,
                                  Position = ac.Inti_Position.Name,
                                  PositionShort = ac.Inti_Position.ShortName,
                                  PositionSortOrder = ac.Inti_Position.SortOrder,
                                  Price = ac.Price,
                                  Points = ac.Inti_MatchPointEvent.Any() ? ac.Inti_MatchPointEvent.Sum(p=>p.Points) : 0,
                                  IsActive = ac.IsActive
                              };

            var dataSource = totalLineUp.OrderBy(l => l.PositionSortOrder).ThenByDescending(l=>l.Points).ToList();

            //mark first and last in each group
            for (int i = 0; i < dataSource.Count; i++)
            {
                if (i == 0 || dataSource[i - 1].PositionShort != dataSource[i].PositionShort)
                    dataSource[i].FirstInGroup = true;

                if (i == (dataSource.Count - 1) || dataSource[i].PositionShort != dataSource[i + 1].PositionShort)
                    dataSource[i].LastInGroup = true;

            }

            rptPlayers.DataSource = dataSource;
            rptPlayers.DataBind();
        }
Пример #5
0
        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();
        }
Пример #6
0
        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();
        }
Пример #7
0
        public void LoadClubEvaluation(Guid clubGuid, IntiDataContext db)
        {
            var athletes = GetAthletesForClub(clubGuid, db);

            LoadStakeholders(athletes.ToList(), db);

            lblHeader.Text = "Lag med intressen";
        }
Пример #8
0
        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();
        }
Пример #9
0
        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();
            }
        }
Пример #10
0
        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";
        }
Пример #11
0
        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;
            }
        }
Пример #12
0
        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];
            }
        }
Пример #13
0
        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();
            }
        }
Пример #14
0
        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();
            }
        }
Пример #15
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;
            }
        }
Пример #16
0
        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;
        }
Пример #17
0
        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);
        }
Пример #18
0
        /// <summary>
        /// Return the current transfer period if any
        /// </summary>
        /// <returns></returns>
        public Inti_TransferPeriod GetCurrentTransferPeriod(DateTime date)
        {
            using (var db = new IntiDataContext(_connectionString))
            {
                var transferPeriods = db.Inti_TransferPeriod.Where(tf => tf.TournamentGUID == SessionProperties.SelectedTournament.GUID).ToList();
                foreach (var tf in transferPeriods)
                {
                    if (tf.StartDate <= date && tf.EndDate >= date)
                    {
                        return tf;
                    }
                }
            }

            return null;
        }
Пример #19
0
        public void ClearTeamPoints(Guid matchId)
        {
            using (var db = new IntiDataContext(_connectionString))
            {
                var teamPointEvents = from tpe in db.Inti_TeamPointEvents
                                      where tpe.Inti_MatchPointEvent.MatchGUID == matchId
                                      select tpe;

                db.Inti_TeamPointEvents.DeleteAllOnSubmit(teamPointEvents.ToList());

                if (teamPointEvents.ToList().Count > 0)
                    LogEvent(matchId, typeof(Inti_Match), SessionProperties.UserGuid, SessionProperties.ClientInfo, EventType.Update, "ClearTeamPoints");

                db.SubmitChanges();
            }
        }
Пример #20
0
        private IList<MatchPreviewAthleteDTO> GetAthletesForClub(Guid clubGuid, IntiDataContext db)
        {
            //get a list of athletes represented in teams, sorted by total scores
            var highestScoringAthletes = from ac in db.Inti_AthleteClub
                                         where ac.ClubGUID == clubGuid
                                         select new MatchPreviewAthleteDTO()
                                         {
                                             AthleteGuid = ac.AthleteGUID,
                                             AthleteClubGuid = ac.GUID,
                                             Name = HttpUtility.HtmlDecode(String.Format("{0} {1}", ac.Inti_Athlete.FirstName, ac.Inti_Athlete.LastName).Trim()),
                                             Points = ac.Inti_MatchPointEvent.Any() ? ac.Inti_MatchPointEvent.Sum(mpe => mpe.Points) : 0,
                                             Price = ac.Price ?? 0
                                         };

            //sort by points, then by price
            return highestScoringAthletes.OrderByDescending(a => a.Points).OrderByDescending(a => a.Price).ToList();
        }
Пример #21
0
        internal void LogEvent(Guid objectId, Type objectType, Guid userGuid, string client, EventType action, string message)
        {
            using (var db = new IntiDataContext(_connectionString))
            {
                var logEvent = new Ext_ChangeLog();
                logEvent.ObjectGUID = objectId;
                logEvent.ObjectType = objectType.Name;
                logEvent.UserGUID = userGuid;
                logEvent.Client = client;
                logEvent.Action = action.ToString();
                logEvent.Message = message;
                logEvent.LogDate = DateTime.Now;

                db.Ext_ChangeLog.InsertOnSubmit(logEvent);
                db.SubmitChanges();
            }
        }
Пример #22
0
        public void CommitTransfers(IntiDataContext db, Inti_TransferPeriod transferPeriod, Inti_TeamVersion currentVersion, Inti_TeamVersion transferVersion, Guid teamId)
        {
            //add transfers
            IList<Inti_TeamTransfer> transfers = new List<Inti_TeamTransfer>();
            foreach (var teamAthlete in currentVersion.Inti_TeamAthlete.ToList())
            {
                //is this athlete removed in the new version?
                if (transferVersion.Inti_TeamAthlete.Where(ta => ta.AthleteGUID == teamAthlete.AthleteGUID).ToList().Count == 0)
                {
                    var transfer = new Inti_TeamTransfer();
                    transfer.TeamGUID = teamId;
                    transfer.TransferDate = transferPeriod.EndDate;
                    transfer.AthleteOutGUID = teamAthlete.AthleteGUID;
                    transfer.AthleteInGUID = Guid.Empty;
                    transfers.Add(transfer);
                }

            }

            foreach (var teamAthlete in transferVersion.Inti_TeamAthlete.ToList())
            {
                //is this athlete present in the old version?
                if (currentVersion.Inti_TeamAthlete.Where(ta => ta.AthleteGUID == teamAthlete.AthleteGUID).ToList().Count == 0)
                {
                    foreach (var tr in transfers)
                    {
                        if (tr.AthleteInGUID == Guid.Empty)
                        {
                            tr.AthleteInGUID = teamAthlete.AthleteGUID;
                            db.Inti_TeamTransfer.InsertOnSubmit(tr);
                            break;
                        }
                    }
                }

            }

            //update validTo and ValidFroms
            transferVersion.ValidFrom = transferPeriod.EndDate;
            currentVersion.ValidTo = transferPeriod.EndDate.AddDays(-1);

            db.SubmitChanges();

            LogEvent(teamId, typeof(Inti_Team), SessionProperties.UserGuid, SessionProperties.ClientInfo, EventType.Update, "Genomfört byten");
        }
Пример #23
0
        public void DistributePoints(Guid matchId)
        {
            using (var db = new IntiDataContext(_connectionString))
            {
                var match = db.Inti_Match.Single(m => m.GUID == matchId);

                var mpes = from mpe in db.Inti_MatchPointEvent
                           where mpe.Inti_Match.GUID == matchId
                           orderby mpe.Inti_AthleteClub.Inti_Club.Name
                           orderby mpe.Inti_AthleteClub.Inti_Position.Name
                           orderby mpe.Inti_PointEvent.Name
                           select mpe;

                foreach (var mpe in mpes)
                {
                    //loop the teams that has this athlete
                    var teamAthletes = from ta in db.Inti_TeamAthlete
                                       where ta.Inti_TeamVersion.ValidFrom < match.MatchDate
                                             && (ta.Inti_TeamVersion.ValidTo ?? match.MatchDate) >= match.MatchDate
                                             && (ta.Inti_TeamVersion.Inti_Team.IsActive ?? false)
                                             && (ta.Inti_TeamVersion.Inti_Team.IsPaid ?? false)
                                             && ta.AthleteGUID == mpe.AthleteClubGUID
                                       select new
                                       {
                                           ta.Inti_TeamVersion.TeamGUID
                                       };

                    foreach (var teamAthlete in teamAthletes)
                    {
                        var tpe = new Inti_TeamPointEvents();
                        tpe.MatchPointEventGUID = mpe.GUID;
                        tpe.TeamGUID = teamAthlete.TeamGUID;

                        db.Inti_TeamPointEvents.InsertOnSubmit(tpe);
                    }
                }

                match.IsUpdated = true;

                db.SubmitChanges();

                LogEvent(matchId, typeof(Inti_Match), SessionProperties.UserGuid, SessionProperties.ClientInfo, EventType.Update, "DistributePoints" );
            }
        }
Пример #24
0
        public void ActivateTeam(Guid teamGUID)
        {
            using (var db = new IntiDataContext(_connectionString))
            {
                try
                {
                    var team = db.Inti_Team.Single(t => t.GUID == teamGUID);

                    team.IsActive = !team.IsActive;

                    db.SubmitChanges();

                }
                catch (System.InvalidOperationException)
                {
                    //team was not to be found
                }
            }
        }
Пример #25
0
        public Guid StoreNewNews(string header, string body, string picture, DateTime? validFrom, DateTime? validTo)
        {
            using (var db = new IntiDataContext(_connectionString))
            {
                var news = new Ext_News();
                news.Header = header;
                news.Body = body;
                news.Picture = picture;
                news.ValidFrom = validFrom;
                news.ValidTo = validTo;

                db.Ext_News.InsertOnSubmit(news);

                LogEvent(news.GUID, news.GetType(), SessionProperties.UserGuid, SessionProperties.ClientInfo, EventType.Create, "New news");

                db.SubmitChanges();

                return news.GUID;
            }
        }
Пример #26
0
        public void ClearPointEvents(Guid matchId)
        {
            //always clear teamPoints first
            ClearTeamPoints(matchId);

            using (var db = new IntiDataContext(_connectionString))
            {
                var matchPointEvents = from mpe in db.Inti_MatchPointEvent
                                       where mpe.MatchGUID == matchId
                                       select mpe;

                db.Inti_MatchPointEvent.DeleteAllOnSubmit(matchPointEvents.ToList());

                var match = db.Inti_Match.Single(m => m.GUID == matchId);
                match.IsUpdated = false;

                LogEvent(matchId, typeof(Inti_Match), SessionProperties.UserGuid, SessionProperties.ClientInfo, EventType.Update, "ClearPointEvents");

                db.SubmitChanges();
            }
        }
Пример #27
0
        public Inti_Athlete GetAthleteByName(string firstName, string lastName)
        {
            using (var db = new IntiDataContext(_connectionString))
            {
                var athletes = from a in db.Inti_Athlete
                               where a.FirstName.ToLower().Trim() == firstName.ToLower().Trim()
                                     && a.LastName.ToLower().Trim() == lastName.ToLower().Trim()
                               select a;

                if (athletes.ToList().Count == 1)
                {
                    return athletes.ToList()[0];
                }

                if (athletes.ToList().Count > 1)
                {
                    throw new ArgumentException("More than one player is named {0}. Correct this in player data.", String.Format("{0} {1}", firstName, lastName).Trim());
                }
            }

            return null;
        }
Пример #28
0
        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;
        }
Пример #29
0
        public Dictionary<Sys_User, int> GetTopUpdaters(Guid tournamentId)
        {
            var updatersFullUserObjects = new Dictionary<Sys_User, int>(10);
            using (var db = new IntiDataContext(_connectionString))
            {
                var matches = db.Inti_Match.Where(m => m.TournamentGUID == tournamentId && (m.IsUpdated ?? false));

                var updaters = new Dictionary<Guid, int>(10);

                //lock in the object log of each updated match - get the earliest DistributePoints - that's the one that counts.
                foreach (var intiMatch in matches)
                {
                    var log =
                        db.Ext_ChangeLog.Where(l => l.ObjectGUID == intiMatch.GUID && l.Message == "DistributePoints").
                            OrderBy(l => l.LogDate).FirstOrDefault();

                    if (log == null) continue;

                    if (!updaters.ContainsKey(log.UserGUID))
                        updaters.Add(log.UserGUID, 0);

                    updaters[log.UserGUID]++;

                }

                //populate users list
                foreach (var updater in updaters)
                {
                    var user = db.Sys_User.SingleOrDefault(u => u.GUID == updater.Key);
                    if (user == null) continue;

                    updatersFullUserObjects.Add(user, updater.Value);
                }
            }

            return updatersFullUserObjects;
        }
        private void LoadParticipants(Guid tournamentGUID, IntiDataContext db)
        {
            //load participants
            pnlAddParticipants.Visible = true;

            var participants = from p in db.Ext_PrivateTournamentParticipant
                               where p.PrivateTournamentGUID == tournamentGUID
                               select new
                               {
                                   GUID = p.Inti_Team.GUID,
                                   TeamName =
                        p.Inti_Team.Sys_User.FirstName + " " + p.Inti_Team.Sys_User.LastName + "(" +
                        p.Inti_Team.Name + ")",
                                   p.IsAccepted
                               };

            grdChallengedTeams.DataSource = participants.OrderBy(t => t.TeamName).ToList();
            grdChallengedTeams.DataBind();
        }