예제 #1
0
 private void AddSecondEvent(string sendingText, EventsOfMatches eventsOfMatches)
 {
     if (eventsOfMatches.EventName == "ONTARGET" ||
         eventsOfMatches.EventName == "OFFTARGET" ||
         eventsOfMatches.EventName == "BLOCKEDSHOT")
     {
         var eventID = eventsOfMatches.EventOfMatchId;
         if (!string.IsNullOrEmpty(sendingText))
         {
             EventsOfMatches newBigChanceEvent = eventsOfMatches;
             newBigChanceEvent.EventOfMatchId = 0;
             newBigChanceEvent.EventName      = "BIGCHANCE";
             newBigChanceEvent.EventMinute    = GetEventMinute(newBigChanceEvent);
             CreateTextOfEvent(newBigChanceEvent);
             _dystirDBContext.EventsOfMatches.Add(newBigChanceEvent);
             _dystirDBContext.SaveChanges();
             EventsOfMatches currentEvent = _dystirDBContext.EventsOfMatches.Find(eventID);
             if (currentEvent != null)
             {
                 currentEvent.SecondPlayerOfMatchId = newBigChanceEvent.EventOfMatchId;
             }
             _dystirDBContext.SaveChanges();
         }
     }
 }
예제 #2
0
        public IActionResult GetEventsOfMatches(int id)
        {
            EventsOfMatches eventsOfMatches = _dystirDBContext.EventsOfMatches.Find(id);

            if (eventsOfMatches == null)
            {
                return(NotFound());
            }

            return(Ok(eventsOfMatches));
        }
예제 #3
0
 private void RemoveSecondEvent(EventsOfMatches eventsOfMatches)
 {
     if (eventsOfMatches.EventName == "ONTARGET" ||
         eventsOfMatches.EventName == "OFFTARGET" ||
         eventsOfMatches.EventName == "BLOCKEDSHOT")
     {
         EventsOfMatches bindEvent = _dystirDBContext.EventsOfMatches.Find(eventsOfMatches.SecondPlayerOfMatchId);
         if (bindEvent != null)
         {
             _dystirDBContext.EventsOfMatches.Remove(bindEvent);
             _dystirDBContext.SaveChanges();
         }
         eventsOfMatches.SecondPlayerOfMatchId = 0;
     }
 }
예제 #4
0
        public IActionResult DeleteEventsOfMatches(int id)
        {
            EventsOfMatches eventsOfMatches = _dystirDBContext.EventsOfMatches.Find(id);

            if (eventsOfMatches == null)
            {
                return(NotFound());
            }

            RemoveSecondEvent(eventsOfMatches);
            _dystirDBContext.EventsOfMatches.Remove(eventsOfMatches);
            _dystirDBContext.SaveChanges();
            SetNewEventsList((int)eventsOfMatches.MatchId);
            Matches match = _dystirDBContext.Matches.FirstOrDefault(x => x.MatchID == eventsOfMatches.MatchId);

            HubSend(match);
            return(Ok(eventsOfMatches.EventOfMatchId));
        }
예제 #5
0
        private void AddTeamStatistic(EventsOfMatches matchEvent, TeamStatistic teamStatistic)
        {
            switch (matchEvent?.EventName?.ToLower())
            {
            case "goal":
            case "penaltyscored":
                teamStatistic.Goal     += 1;
                teamStatistic.OnTarget += 1;
                break;

            case "owngoal":
                teamStatistic.Goal += 1;
                break;

            case "yellow":
                teamStatistic.YellowCard += 1;
                break;

            case "red":
                teamStatistic.RedCard += 1;
                break;

            case "corner":
                teamStatistic.Corner += 1;
                break;

            case "ontarget":
                teamStatistic.OnTarget += 1;
                break;

            case "offtarget":
                teamStatistic.OffTarget += 1;
                break;

            case "blockedshot":
                teamStatistic.BlockedShot += 1;
                break;

            case "bigchance":
                teamStatistic.BigChance += 1;
                break;
            }
        }
예제 #6
0
        public IActionResult PutEventsOfMatches(int id, EventsOfMatches eventsOfMatches)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eventsOfMatches?.EventOfMatchId)
            {
                return(BadRequest());
            }
            try
            {
                if (eventsOfMatches.EventName != null)
                {
                    _dystirDBContext.Entry(eventsOfMatches).State = EntityState.Modified;
                    RemoveSecondEvent(eventsOfMatches);
                    string sendingText = eventsOfMatches.EventText;
                    eventsOfMatches.EventMinute = GetEventMinute(eventsOfMatches);
                    CreateTextOfEvent(eventsOfMatches);
                    _dystirDBContext.SaveChanges();
                    AddSecondEvent(sendingText, eventsOfMatches);
                    SetNewEventsList((int)eventsOfMatches.MatchId);
                    Matches match = _dystirDBContext.Matches.FirstOrDefault(x => x.MatchID == eventsOfMatches.MatchId);
                    HubSend(match);
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventsOfMatchesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
예제 #7
0
        public IActionResult PostEventsOfMatches(EventsOfMatches eventsOfMatches)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (eventsOfMatches != null && !string.IsNullOrEmpty(eventsOfMatches.EventName))
            {
                string sendingText = eventsOfMatches.EventText;
                eventsOfMatches.EventMinute = GetEventMinute(eventsOfMatches);
                CreateTextOfEvent(eventsOfMatches);
                _dystirDBContext.EventsOfMatches.Add(eventsOfMatches);
                _dystirDBContext.SaveChanges();

                AddSecondEvent(sendingText, eventsOfMatches);
                SetNewEventsList((int)eventsOfMatches.MatchId);
            }
            Matches match = _dystirDBContext.Matches.FirstOrDefault(x => x.MatchID == eventsOfMatches.MatchId);

            HubSend(match);

            return(Ok());
        }
예제 #8
0
        private void PlayersOfMatchValuesFromEvent(PlayersOfMatches playerOfMatch, EventsOfMatches eventMatch)
        {
            try
            {
                switch (eventMatch?.EventName?.ToUpper())
                {
                case "GOAL":
                case "PENALTYSCORED":
                    playerOfMatch.Goal += 1;
                    break;

                case "OWNGOAL":
                    playerOfMatch.OwnGoal += 1;
                    break;

                case "YELLOW":
                    playerOfMatch.YellowCard += 1;
                    break;

                case "RED":
                    playerOfMatch.RedCard += 1;
                    break;

                case "ASSIST":
                    playerOfMatch.Assist += 1;
                    break;

                case "SUBSTITUTION":
                    int    subsMinute  = 0;
                    string eventMinute = eventMatch.EventMinute.TrimStart('0').Replace("'", "");
                    if (string.IsNullOrWhiteSpace(eventMinute))
                    {
                        eventMinute = "0";
                    }
                    switch (eventMatch.EventPeriodId)
                    {
                    case 3:
                        eventMinute = "45";
                        break;

                    case 5:
                        eventMinute = "90";
                        break;

                    case 7:
                        eventMinute = "105";
                        break;

                    case 9:
                    case 10:
                    case 12:
                    case 13:
                    case 14:
                    case 20:
                    case 30:
                        eventMinute = "120";
                        break;
                    }
                    int index = eventMinute.IndexOf('+');
                    if (index > 0)
                    {
                        subsMinute = Convert.ToInt32(eventMinute.Substring(0, index));
                    }
                    else
                    {
                        subsMinute = Convert.ToInt32(eventMinute);
                    }
                    playerOfMatch.SubOut = subsMinute;
                    PlayersOfMatches secondPlayersOfMatches = _dystirDBContext.PlayersOfMatches.FirstOrDefault(x => x.PlayerOfMatchId == eventMatch.SecondPlayerOfMatchId);
                    if (secondPlayersOfMatches != null)
                    {
                        secondPlayersOfMatches.SubIn = subsMinute;
                    }
                    break;
                }
            }
            catch
            {
            };
        }
예제 #9
0
        private void CreateTextOfEvent(EventsOfMatches eventsOfMatches)
        {
            PlayersOfMatches playersOfMatches   = _dystirDBContext.PlayersOfMatches.FirstOrDefault(x => x.PlayerOfMatchId == eventsOfMatches.MainPlayerOfMatchId);
            string           mainPlayerFullName = (playersOfMatches?.FirstName?.Trim() + " " + playersOfMatches?.Lastname?.Trim())?.Trim();

            switch (eventsOfMatches?.EventName?.ToUpper())
            {
            case "GOAL":
                eventsOfMatches.EventText = "MÁL til " + eventsOfMatches.EventTeam + ". " + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : "Málskjútti " + mainPlayerFullName + ".");
                break;

            case "OWNGOAL":
                eventsOfMatches.EventText = "MÁL til " + eventsOfMatches.EventTeam + ". " + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : "Sjálvmál " + mainPlayerFullName + ".");
                break;

            case "YELLOW":
                eventsOfMatches.EventText = "GULKORT " + eventsOfMatches.EventTeam + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "." : " leikari " + mainPlayerFullName + ".");
                break;

            case "RED":
                eventsOfMatches.EventText = "REYTTKORT " + eventsOfMatches.EventTeam + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "." : " leikari " + mainPlayerFullName + ".");
                break;

            case "CORNER":
                eventsOfMatches.EventText = "HORNASPARK til " + eventsOfMatches.EventTeam + ".";
                break;

            case "ONTARGET":
                eventsOfMatches.EventText = "ROYND Á MÁL. " + eventsOfMatches.EventTeam + " leikari" + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : " " + mainPlayerFullName) + " roynd á mál.";
                break;

            case "OFFTARGET":
                eventsOfMatches.EventText = "ROYND FRAMVIÐ MÁL. " + eventsOfMatches.EventTeam + " leikari" + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : " " + mainPlayerFullName) + " roynd framvið mál.";
                break;

            case "BLOCKEDSHOT":
                eventsOfMatches.EventText = "BLOKERA SKOT. " + eventsOfMatches.EventTeam + " leikari" + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : " " + mainPlayerFullName) + " roynd er blokerað.";
                break;

            case "BIGCHANCE":
                eventsOfMatches.EventText = "STÓRUR MØGULEIKI. " + eventsOfMatches.EventTeam + " leikari" + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : " " + mainPlayerFullName) + " stórur mál møguleiki.";
                break;

            case "SUBSTITUTION":
                PlayersOfMatches secondPlayersOfMatches = _dystirDBContext.PlayersOfMatches.FirstOrDefault(x => x.PlayerOfMatchId == eventsOfMatches.SecondPlayerOfMatchId);
                string           secongPlayerFullName   = (secondPlayersOfMatches?.FirstName?.Trim() + " " + secondPlayersOfMatches?.Lastname?.Trim())?.Trim();
                eventsOfMatches.EventText = "ÚTSKIFTING " + eventsOfMatches.EventTeam + ". " + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : "Leikari " + mainPlayerFullName + " út. ") + (string.IsNullOrWhiteSpace(secongPlayerFullName) ? "" : "Leikari " + secongPlayerFullName + " inn.");
                break;

            case "ASSIST":
                eventsOfMatches.EventText = "UPPLEGG " + eventsOfMatches.EventTeam + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "." : " leikari " + mainPlayerFullName + ".");
                break;

            case "PENALTY":
                eventsOfMatches.EventText = "BROTSSPARK til " + eventsOfMatches.EventTeam + ".";
                break;

            case "PENALTYSCORED":
                eventsOfMatches.EventText = "BROTSSPARK SKORA " + eventsOfMatches.EventTeam + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "." : " leikari " + mainPlayerFullName + ".");
                break;

            case "PENALTYMISSED":
                eventsOfMatches.EventText = "BROTSSPARK BRENT " + eventsOfMatches.EventTeam + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "." : " leikari " + mainPlayerFullName + ".");
                break;

            case "COMMENTARY":
                eventsOfMatches.EventText = "HENDINGAR: " + eventsOfMatches.EventText;
                break;
            }
        }
예제 #10
0
        private string GetEventMinute(EventsOfMatches eventsOfMatches)
        {
            string liveMatchTime = string.Empty;

            if (eventsOfMatches?.MatchId != null)
            {
                int      minutes        = 0;
                int      seconds        = 0;
                string[] totalTimeArray = eventsOfMatches?.EventTotalTime?.Split(':');
                if (totalTimeArray != null && totalTimeArray.Length == 2)
                {
                    string totalMinutes = totalTimeArray[0].TrimStart('0').TrimStart('0');
                    totalMinutes = string.IsNullOrWhiteSpace(totalMinutes) ? "0" : totalMinutes;
                    minutes      = int.Parse(totalMinutes) + 1;
                    string totalSeconds = totalTimeArray[1].TrimStart('0').TrimStart('0');
                    totalSeconds = string.IsNullOrWhiteSpace(totalSeconds) ? "0" : totalSeconds;
                    seconds      = int.Parse(totalSeconds);
                }

                string addTime = string.Empty;
                switch (eventsOfMatches.EventPeriodId)
                {
                case 1:
                    return("00'");

                case 2:
                    if (minutes > 45)
                    {
                        addTime = "45+";
                        minutes = minutes - 45;
                    }
                    break;

                case 3:
                    return("hálvleikur");

                case 4:
                    if (minutes > 90)
                    {
                        addTime = "90+";
                        minutes = minutes - 90;
                    }
                    break;

                case 5:
                    return("liðugt");

                case 6:
                    if (minutes > 105)
                    {
                        addTime = "105+";
                        minutes = minutes - 105;
                    }
                    break;

                case 7:
                    return("longd leiktíð hálvleikur");

                case 8:
                    if (minutes > 120)
                    {
                        addTime = "120+";
                        minutes = minutes - 120;
                    }
                    break;

                case 9:
                    return("longd leiktíð liðugt");

                case 10:
                    return("brotsspark");

                default:
                    return("liðugt");
                }
                string min = minutes.ToString();
                string sec = seconds.ToString();
                if (minutes < 10)
                {
                    min = "0" + minutes;
                }
                if (seconds < 10)
                {
                    sec = "0" + seconds;
                }

                liveMatchTime = addTime + " " + min + ":" + sec;
            }
            return((liveMatchTime.Split(':')?[0] +"'").Trim());
        }
예제 #11
0
 private bool IsGoal(EventsOfMatches matchEvent)
 {
     return(matchEvent.EventName == "GOAL" ||
            matchEvent.EventName == "OWNGOAL" ||
            matchEvent.EventName == "PENALTYSCORED");
 }
예제 #12
0
        internal List <SummaryEventOfMatch> GetSummaryEventsList(MatchDetails matchDetails)
        {
            List <SummaryEventOfMatch> summaryEventOfMatchesList = new List <SummaryEventOfMatch>();
            Matches selectedMatch   = matchDetails.Match;
            var     homeTeamPlayers = matchDetails.PlayersOfMatch?.Where(x => x.TeamName.Trim() == selectedMatch.HomeTeam.Trim());
            var     awayTeamPlayers = matchDetails.PlayersOfMatch?.Where(x => x.TeamName.Trim() == selectedMatch.AwayTeam.Trim());
            var     eventsList      = matchDetails.EventsOfMatch?.Where(x =>
                                                                        x.EventName == "GOAL" ||
                                                                        x.EventName == "OWNGOAL" ||
                                                                        x.EventName == "PENALTYSCORED" ||
                                                                        x.EventName == "PENALTYMISSED" ||
                                                                        x.EventName == "YELLOW" ||
                                                                        x.EventName == "RED" ||
                                                                        x.EventName == "BIGCHANCE"
                                                                        //|| x.EventName == "SUBSTITUTION"
                                                                        || x.EventName == "ASSIST").ToList();
            int homeScore = 0;
            int awayScore = 0;

            foreach (var eventOfMatch in eventsList ?? new List <EventsOfMatches>())
            {
                SummaryEventOfMatch summaryEventOfMatch = new SummaryEventOfMatch()
                {
                    EventOfMatch  = eventOfMatch,
                    HomeTeamScore = 0,
                    AwayTeamScore = 0,
                    HomeTeam      = eventOfMatch?.EventTeam == selectedMatch.HomeTeam ? selectedMatch.HomeTeam : string.Empty,
                    AwayTeam      = eventOfMatch?.EventTeam == selectedMatch.AwayTeam ? selectedMatch.AwayTeam : string.Empty,
                    EventName     = eventOfMatch?.EventName,
                    EventMinute   = eventOfMatch?.EventMinute,
                };
                PlayersOfMatches mainPlayerOfMatch    = matchDetails.PlayersOfMatch.Find(x => x.PlayerOfMatchId == eventOfMatch.MainPlayerOfMatchId);
                string           mainPlayerFullName   = (mainPlayerOfMatch?.FirstName?.Trim() + " " + mainPlayerOfMatch?.Lastname?.Trim())?.Trim();
                PlayersOfMatches secondPlayerOfMatch  = matchDetails.PlayersOfMatch.Find(x => x.PlayerOfMatchId == eventOfMatch.SecondPlayerOfMatchId);
                string           secondPlayerFullName = (secondPlayerOfMatch?.FirstName?.Trim() + " " + secondPlayerOfMatch?.Lastname?.Trim())?.Trim();
                if (eventOfMatch.EventTeam.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim())
                {
                    summaryEventOfMatch.HomeMainPlayer   = mainPlayerFullName;
                    summaryEventOfMatch.HomeSecondPlayer = secondPlayerFullName;
                }
                else
                {
                    summaryEventOfMatch.AwayMainPlayer   = mainPlayerFullName;
                    summaryEventOfMatch.AwaySecondPlayer = secondPlayerFullName;
                }
                summaryEventOfMatch.HomeTeamVisible = !string.IsNullOrEmpty(summaryEventOfMatch.HomeTeam);
                summaryEventOfMatch.AwayTeamVisible = !string.IsNullOrEmpty(summaryEventOfMatch.AwayTeam);
                if (IsGoal(eventOfMatch))
                {
                    if (eventOfMatch.EventTeam.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim())
                    {
                        homeScore += 1;
                    }
                    if (eventOfMatch.EventTeam.ToUpper().Trim() == selectedMatch.AwayTeam.ToUpper().Trim())
                    {
                        awayScore += 1;
                    }
                }
                summaryEventOfMatch.HomeTeamScore = homeScore;
                summaryEventOfMatch.AwayTeamScore = awayScore;

                if (eventOfMatch.EventName == "GOAL")
                {
                    int eventIndex = eventsList.IndexOf(eventOfMatch);
                    if (eventIndex + 1 < eventsList.Count)
                    {
                        EventsOfMatches nextEvent = eventsList[eventIndex + 1];
                        if (nextEvent.EventName == "ASSIST")
                        {
                            PlayersOfMatches assistPlayerOfMatch  = matchDetails.PlayersOfMatch.Find(x => x.PlayerOfMatchId == nextEvent.MainPlayerOfMatchId);
                            string           assistPlayerFullName = (assistPlayerOfMatch?.FirstName?.Trim() + " " + assistPlayerOfMatch?.Lastname?.Trim())?.Trim();
                            if (eventOfMatch.EventTeam.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim())
                            {
                                summaryEventOfMatch.HomeSecondPlayer = assistPlayerFullName;
                            }
                            if (eventOfMatch.EventTeam.ToUpper().Trim() == selectedMatch.AwayTeam.ToUpper().Trim())
                            {
                                summaryEventOfMatch.AwaySecondPlayer = assistPlayerFullName;
                            }
                        }
                    }
                }
                summaryEventOfMatchesList.Add(summaryEventOfMatch);
            }

            return(summaryEventOfMatchesList.ToList());
        }