Skip to content

Commit

Permalink
Add MenuNavigation to UI and BettorRanking.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanDeveloper committed Jun 13, 2017
1 parent e483d6e commit 2fa3e6c
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public interface IBettorClientService {
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ILigaManagerService/GetBets", ReplyAction="http://tempuri.org/ILigaManagerService/GetBetsResponse")]
System.Threading.Tasks.Task<LigaManagerServer.Models.Bet[]> GetBetsAsync(LigaManagerServer.Models.Bettor bettor);

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ILigaManagerService/GetAllBets", ReplyAction="http://tempuri.org/ILigaManagerService/GetAllBetsResponse")]
LigaManagerServer.Models.Bet[] GetAllBets();

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ILigaManagerService/GetAllBets", ReplyAction="http://tempuri.org/ILigaManagerService/GetAllBetsResponse")]
System.Threading.Tasks.Task<LigaManagerServer.Models.Bet[]> GetAllBetsAsync();

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ILigaManagerService/GetBettors", ReplyAction="http://tempuri.org/ILigaManagerService/GetBettorsResponse")]
LigaManagerServer.Models.Bettor[] GetBettors();

Expand Down Expand Up @@ -119,6 +125,14 @@ public LigaManagerServer.Models.Bet[] GetBets(LigaManagerServer.Models.Bettor be
return base.Channel.GetBetsAsync(bettor);
}

public LigaManagerServer.Models.Bet[] GetAllBets() {
return base.Channel.GetAllBets();
}

public System.Threading.Tasks.Task<LigaManagerServer.Models.Bet[]> GetAllBetsAsync() {
return base.Channel.GetAllBetsAsync();
}

public LigaManagerServer.Models.Bettor[] GetBettors() {
return base.Channel.GetBettors();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<wsdl:message name="IBettorClientService_GetBets_OutputMessage">
<wsdl:part name="parameters" element="tns:GetBetsResponse" />
</wsdl:message>
<wsdl:message name="IBettorClientService_GetAllBets_InputMessage">
<wsdl:part name="parameters" element="tns:GetAllBets" />
</wsdl:message>
<wsdl:message name="IBettorClientService_GetAllBets_OutputMessage">
<wsdl:part name="parameters" element="tns:GetAllBetsResponse" />
</wsdl:message>
<wsdl:message name="IBettorClientService_GetBettors_InputMessage">
<wsdl:part name="parameters" element="tns:GetBettors" />
</wsdl:message>
Expand Down Expand Up @@ -76,6 +82,10 @@
<wsdl:input wsaw:Action="http://tempuri.org/ILigaManagerService/GetBets" message="tns:IBettorClientService_GetBets_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/ILigaManagerService/GetBetsResponse" message="tns:IBettorClientService_GetBets_OutputMessage" />
</wsdl:operation>
<wsdl:operation name="GetAllBets">
<wsdl:input wsaw:Action="http://tempuri.org/ILigaManagerService/GetAllBets" message="tns:IBettorClientService_GetAllBets_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/ILigaManagerService/GetAllBetsResponse" message="tns:IBettorClientService_GetAllBets_OutputMessage" />
</wsdl:operation>
<wsdl:operation name="GetBettors">
<wsdl:input wsaw:Action="http://tempuri.org/ILigaManagerService/GetBettors" message="tns:IBettorClientService_GetBettors_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/ILigaManagerService/GetBettorsResponse" message="tns:IBettorClientService_GetBettors_OutputMessage" />
Expand Down Expand Up @@ -129,6 +139,15 @@
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetAllBets">
<soap:operation soapAction="http://tempuri.org/ILigaManagerService/GetAllBets" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetBettors">
<soap:operation soapAction="http://tempuri.org/ILigaManagerService/GetBettors" style="document" />
<wsdl:input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetAllBets">
<xs:complexType>
<xs:sequence />
</xs:complexType>
</xs:element>
<xs:element name="GetAllBetsResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q5="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetAllBetsResult" nillable="true" type="q5:ArrayOfBet" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetBettors">
<xs:complexType>
<xs:sequence />
Expand All @@ -37,7 +49,7 @@
<xs:element name="GetBettorsResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q5="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetBettorsResult" nillable="true" type="q5:ArrayOfBettor" />
<xs:element xmlns:q6="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetBettorsResult" nillable="true" type="q6:ArrayOfBettor" />
</xs:sequence>
</xs:complexType>
</xs:element>
Expand All @@ -51,7 +63,7 @@
<xs:element name="GetBettorResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q6="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetBettorResult" nillable="true" type="q6:Bettor" />
<xs:element xmlns:q7="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetBettorResult" nillable="true" type="q7:Bettor" />
</xs:sequence>
</xs:complexType>
</xs:element>
Expand All @@ -63,21 +75,21 @@
<xs:element name="GetSeasonsResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q7="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetSeasonsResult" nillable="true" type="q7:ArrayOfSeason" />
<xs:element xmlns:q8="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetSeasonsResult" nillable="true" type="q8:ArrayOfSeason" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetTeams">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q8="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="season" nillable="true" type="q8:Season" />
<xs:element xmlns:q9="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="season" nillable="true" type="q9:Season" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetTeamsResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q9="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetTeamsResult" nillable="true" type="q9:ArrayOfSeasonToTeamRelation" />
<xs:element xmlns:q10="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetTeamsResult" nillable="true" type="q10:ArrayOfSeasonToTeamRelation" />
</xs:sequence>
</xs:complexType>
</xs:element>
Expand All @@ -98,7 +110,7 @@
<xs:element name="AddBet">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q10="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="bet" nillable="true" type="q10:Bet" />
<xs:element xmlns:q11="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="bet" nillable="true" type="q11:Bet" />
</xs:sequence>
</xs:complexType>
</xs:element>
Expand All @@ -112,7 +124,7 @@
<xs:element name="ChangeBet">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q11="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="bet" nillable="true" type="q11:Bet" />
<xs:element xmlns:q12="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="bet" nillable="true" type="q12:Bet" />
</xs:sequence>
</xs:complexType>
</xs:element>
Expand All @@ -126,15 +138,15 @@
<xs:element name="GetBet">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q12="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="match" nillable="true" type="q12:Match" />
<xs:element xmlns:q13="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="bettor" nillable="true" type="q13:Bettor" />
<xs:element xmlns:q13="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="match" nillable="true" type="q13:Match" />
<xs:element xmlns:q14="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="bettor" nillable="true" type="q14:Bettor" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetBetResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q14="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetBetResult" nillable="true" type="q14:Bet" />
<xs:element xmlns:q15="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="GetBetResult" nillable="true" type="q15:Bet" />
</xs:sequence>
</xs:complexType>
</xs:element>
Expand Down
125 changes: 121 additions & 4 deletions LigaManagerBettorClient/Controllers/BettorRankingWindowController.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,147 @@
using System.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using LigaManagerBettorClient.Annotations;
using LigaManagerBettorClient.BettorClientService;
using LigaManagerBettorClient.Frameworks;
using LigaManagerBettorClient.Models;
using LigaManagerBettorClient.ViewModels;
using LigaManagerBettorClient.Views;
using LigaManagerServer.Models;
using Match = LigaManagerServer.Models.Match;

namespace LigaManagerBettorClient.Controllers
{
public class BettorRankingWindowController
{
public MainWindow MainWindow { get; set; }
public Season SelectedSeason { get; set; }
public Bettor Bettor { get; set; }

private BettorRankingWindow _view;
private BettorRankingWindowViewModel _viewModel;
private BettorClientServiceClient _bettorClient;
public void Initialize()
{
_view = new BettorRankingWindow();
_bettorClient = new BettorClientServiceClient();
var bettors = _bettorClient.GetBettors();
var matches = _bettorClient.GetMatches(SelectedSeason);
var max = matches.ToList().Max(x => x.MatchDay);
var rankedBettors = GetRankedBettors(0);
var matchDays = new ObservableCollection<string> { "Aktuell" };
for (var i = 1; i <= max; i++)
{
matchDays.Add("Spieltag: " + i);
}
_viewModel = new BettorRankingWindowViewModel
{
Bettors = bettors.ToList()
Bettors = rankedBettors,
SelectedMatchDay = matchDays.First(),
MatchDays = matchDays,
BackCommand = new RelayCommand(ExecuteBackCommand)
};

_viewModel.SelectionMatchDayChanged += UpdateMatchDay;
// set view of Window
_view.DataContext = _viewModel;
MainWindow.Width = 1200;
MainWindow.Height = 800;
MainWindow.Content = _view;
}

private void ExecuteBackCommand(object obj)
{
var menuWindow = new MenuWindowController
{
Bettor = Bettor,
MainWindow = MainWindow
};
menuWindow.Initialize();
}
private void UpdateMatchDay(object sender, string s)
{
var matchday = 0;
if (!s.Equals("Aktuell"))
{
var resultString = Regex.Match(s, @"\d+").Value;
matchday = int.Parse(resultString);
}
var rankedBettors = GetRankedBettors(matchday);
_viewModel.Bettors = rankedBettors;
}

private List<RankedBettor> GetRankedBettors(int matchday)
{
List<RankedBettor> result = null;
if (matchday == 0)
{
var bettors = _bettorClient.GetBettors();
var allBets = _bettorClient.GetAllBets();
var matches = _bettorClient.GetMatches(SelectedSeason);
result = CalucalteRankedBettors(matches.ToList(), bettors.ToList(), allBets.ToList());
}
else
{
var bettors = _bettorClient.GetBettors();
var allBets = _bettorClient.GetAllBets();
var matches = _bettorClient.GetMatches(SelectedSeason);

var filteredMatches = matches.Where(x => x.MatchDay == matchday);
var filteredBets = allBets.Where(x => matches.Contains(x.Match));
result = CalucalteRankedBettors(filteredMatches.ToList(), bettors.ToList(), filteredBets.ToList());
}
result.Sort((x, y) => y.Score.CompareTo(x.Score));
var resultWithPlace = new List<RankedBettor>();
var i = 1;
foreach (var rankedBettor in result)
{
rankedBettor.Place = i;
resultWithPlace.Add(rankedBettor);
i++;
}
return resultWithPlace;
}

private List<RankedBettor> CalucalteRankedBettors([NotNull] List<Match> matches,
[NotNull] List<Bettor> bettors, [NotNull] List<Bet> bets)
{
if (matches == null) throw new ArgumentNullException(nameof(matches));
if (bettors == null) throw new ArgumentNullException(nameof(bettors));
if (bets == null) throw new ArgumentNullException(nameof(bets));
var result = new List<RankedBettor>();
foreach (var bettor in bettors)
{
var rankedBettor = new RankedBettor { Bettor = bettor };
foreach (var match in matches)
{
var find = bets.Find(x => x.Match.Equals(match) && x.Bettor.Equals(bettor));
if (find != null)
{
var isHomeWin = match.HomeTeamScore > match.AwayTeamScore;
var isAwayWin = match.AwayTeamScore > match.HomeTeamScore;
if (find.HomeTeamScore == match.HomeTeamScore && find.AwayTeamScore == match.AwayTeamScore)
{
rankedBettor.Score += 4;
} else if (isAwayWin == (find.AwayTeamScore > find.HomeTeamScore) &&
(find.AwayTeamScore - find.HomeTeamScore) ==
(match.AwayTeamScore - match.HomeTeamScore))
{
rankedBettor.Score += 3;
} else if (isHomeWin == (find.HomeTeamScore > find.AwayTeamScore) &&
(find.HomeTeamScore - find.AwayTeamScore) ==
(match.HomeTeamScore - match.AwayTeamScore))
{
rankedBettor.Score += 3;
} else if (((find.HomeTeamScore > find.AwayTeamScore) && isHomeWin) || ((find.AwayTeamScore < find.HomeTeamScore) && isAwayWin))
{
rankedBettor.Score += 2;
}
}
}
result.Add(rankedBettor);
}
return result;
}
}
}
13 changes: 12 additions & 1 deletion LigaManagerBettorClient/Controllers/MatchesWindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public void Initialize()
{
SelectedSeason = SelectedSeason,
Matches = listCollectionView,
SelectedMatchCommand = new RelayCommand(ExecuteSelectedMatchCommand)
SelectedMatchCommand = new RelayCommand(ExecuteSelectedMatchCommand),
BackCommand = new RelayCommand(ExecuteBackCommand)
};

_view.DataContext = _viewModel;
Expand All @@ -42,6 +43,16 @@ public void Initialize()
MainWindow.Content = _view;
}

private void ExecuteBackCommand(object obj)
{
var menuWindow = new MenuWindowController
{
Bettor = Bettor,
MainWindow = MainWindow
};
menuWindow.Initialize();
}


public void ExecuteSelectedMatchCommand(object obj)
{
Expand Down
Loading

0 comments on commit 2fa3e6c

Please sign in to comment.