Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #145 from SSchulze1989/develop
Browse files Browse the repository at this point in the history
Release version 0.9.3
  • Loading branch information
SSchulze1989 authored Feb 23, 2021
2 parents 9fce276 + eaaa7e2 commit 1fe9301
Show file tree
Hide file tree
Showing 24 changed files with 508 additions and 70 deletions.
25 changes: 25 additions & 0 deletions DataManager/Data/ASPRestAPIClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using iRLeagueManager.Enums;
using iRLeagueManager.Interfaces;
using System.Runtime.Serialization;
using iRLeagueManager.Models;

//using iRLeagueDatabase.DataTransfer.Messages;

Expand Down Expand Up @@ -324,5 +325,29 @@ public async Task<IEnumerable<string>> GetLeagueNames()
}
return null;
}

public async Task<LeagueDTO> GetLeague(string leagueName)
{
var requestString = $"{BaseUri.AbsoluteUri}/CheckLeague?id={leagueName}";

using (var client = CreateClient())
{
var request = await client.GetAsync(requestString);

if (request.IsSuccessStatusCode)
{
var league = await request.Content.ReadAsAsync<LeagueDTO>();
return league;
}
else if (request.StatusCode == HttpStatusCode.Unauthorized)
{
throw new UserNotAuthorizedException("User not authorized for the service");
}
else
{
throw new LeagueNotFoundException($"League {leagueName} not found in database");
}
}
}
}
}
8 changes: 8 additions & 0 deletions DataManager/Data/ILeagueDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using iRLeagueDatabase.DataTransfer;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -47,6 +48,13 @@ public interface ILeagueDataProvider
/// <exception cref="UserNotAuthorizedException">User is not authorized for this league</exception>
/// <exception cref="LeagueNotFoundException">League name not found in database</exception>
Task<bool> CheckLeagueExists(string leagueName);

/// <summary>
/// Get details for a single league from the API
/// </summary>
/// <param name="leagueName">Shortname of the league</param>
/// <returns></returns>
Task<LeagueDTO> GetLeague(string leagueName);
}
public class UserNotAuthorizedException : Exception
{
Expand Down
1 change: 1 addition & 0 deletions DataManager/DataManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<Compile Include="Models\IModelCache.cs" />
<Compile Include="Models\IModelManager.cs" />
<Compile Include="Data\IModelDataProvider.cs" />
<Compile Include="Models\LeagueModel.cs" />
<Compile Include="Models\Members\TeamModel.cs" />
<Compile Include="Models\ModelBase.cs" />
<Compile Include="Models\ModelCache.cs" />
Expand Down
14 changes: 14 additions & 0 deletions DataManager/LeagueContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ public void SetLeagueName(string leagueName)
ModelDatabase.LeagueName = leagueName;
}

public async Task<LeagueModel> GetLeagueDetails()
{
if (string.IsNullOrEmpty(LeagueName))
{
return null;
}

var leagueDTO = await LeagueDataProvider.GetLeague(LeagueName);
var mapper = MapperConfiguration.CreateMapper();
var league = mapper.Map<LeagueModel>(leagueDTO);

return league;
}

public async Task UpdateMemberList()
{
var mapper = MapperConfiguration.CreateMapper();
Expand Down
11 changes: 6 additions & 5 deletions DataManager/ModelMapperProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ public ModelMapperProfile(IModelCache modelCache)
.ForMember(dest => dest.CleanestDrivers, opt => opt.MapFrom(src => src.CleanesDriverMemberIds.Select(x => GetLeagueMember(x, modelCache))))
.ForMember(dest => dest.HardChargers, opt => opt.UseDestinationValue())
.ForMember(dest => dest.CleanestDrivers, opt => opt.UseDestinationValue())
.ForMember(dest => dest.FastestLapDriver, opt => opt.MapFrom(src => src.FastestLapDriverId))
.Include<ScoredTeamResultDataDTO, ScoredTeamResultModel>();

CreateMap<ScoredTeamResultDataDTO, ScoredTeamResultModel>()
Expand All @@ -460,7 +461,7 @@ public ModelMapperProfile(IModelCache modelCache)
.ForMember(dest => dest.ScoredResultRows, opt => opt.UseDestinationValue())
.ForMember(dest => dest.Team, opt => opt.MapFrom((src, dst) =>
{
return modelCache.PutOrGetModel(new TeamModel() { TeamId = src.TeamId.GetValueOrDefault() });
return modelCache.PutOrGetModel(new TeamModel() { TeamId = src.TeamId });
}));

CreateMap<StandingsDataDTO, StandingsModel>()
Expand All @@ -477,12 +478,10 @@ public ModelMapperProfile(IModelCache modelCache)
//.ConstructUsing(source => ModelCache.PutOrGetModel(new StandingsRowModel() { Scoring = new ScoringInfo(source.Scoring.ScoringId), Member = new LeagueMember(source.Member.MemberId) }))
.ConstructUsing(source => new StandingsRowModel())
.ForMember(dest => dest.Member, opt => opt.MapFrom(src => GetLeagueMember(src.MemberId, modelCache)))
.ForMember(dest => dest.CountedResults, opt => opt.MapFrom(src => src.CountedResults.OrderBy(x => x.Date)))
.ForMember(dest => dest.DroppedResults, opt => opt.MapFrom(src => src.DroppedResults.OrderBy(x => x.Date)))
.ForMember(dest => dest.DriverResults, opt => opt.MapFrom(src => src.DriverResults.OrderBy(x => x.Date)))
.ForMember(dest => dest.Team, opt => opt.MapFrom(src => src.TeamId != null ? modelCache.PutOrGetModel(new TeamModel() { TeamId = src.TeamId.Value }) : null))
.EqualityComparison((src, dest) => src.MemberId == dest.Member.MemberId)
.Include<TeamStandingsRowDataDTO, TeamStandingsRowModel>()
.AfterMap((src, dest) => dest.DroppedResults.ForEach(x => x.IsDroppedResult = true));
.Include<TeamStandingsRowDataDTO, TeamStandingsRowModel>();

CreateMap<TeamStandingsDataDTO, TeamStandingsModel>()
.ConstructUsing(source => modelCache.PutOrGetModel(new TeamStandingsModel() { ScoringTableId = source.ScoringTableId, SessionId = source.SessionId }))
Expand Down Expand Up @@ -574,6 +573,8 @@ public ModelMapperProfile(IModelCache modelCache)
?? new object[0];
}));

CreateMap<LeagueDTO, LeagueModel>();

#region statistic mapping
CreateMap<StatisticSetDTO, StatisticSetInfo>();

Expand Down
19 changes: 19 additions & 0 deletions DataManager/Models/LeagueModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace iRLeagueManager.Models
{
public class LeagueModel : ModelBase
{
private string name;
public string Name { get => name; set => SetValue(ref name, value); }

public string longName;
public string LongName { get => longName; set => SetValue(ref longName, value); }

}
}
9 changes: 9 additions & 0 deletions DataManager/Models/Results/ScoredResultModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public class ScoredResultModel : ResultModel
private ObservableCollection<LeagueMember> cleanestDrivers;
public ObservableCollection<LeagueMember> CleanestDrivers { get => cleanestDrivers; set => SetNotifyCollection(ref cleanestDrivers, value); }

private LeagueMember fastestLapDriver;
public LeagueMember FastestLapDriver { get => fastestLapDriver; set => SetValue(ref fastestLapDriver, value); }

private LeagueMember fastestQualyLapDriver;
public LeagueMember FastestQualyLapDriver { get => fastestQualyLapDriver; set => SetValue(ref fastestQualyLapDriver, value); }

private LeagueMember fastestAvgLapDriver;
public LeagueMember FastestAvgLapDriver { get => fastestAvgLapDriver; set => SetValue(ref fastestAvgLapDriver, value); }

public override long[] ModelId => new long[] { ResultId.GetValueOrDefault(), ScoringId.GetValueOrDefault() };
//public override long[] ModelId => new long[] { ScoredResultId.GetValueOrDefault() };

Expand Down
29 changes: 2 additions & 27 deletions DataManager/Models/Results/StandingsRowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,8 @@ public class StandingsRowModel : MappableModel
private int positionChange;
public int PositionChange { get => positionChange; internal set => SetValue(ref positionChange, value); }

private IEnumerable<ScoredResultRowModel> countedResults;
public IEnumerable<ScoredResultRowModel> CountedResults
{
get => countedResults;
set
{
if (SetValue(ref countedResults, value))
{
OnPropertyChanged(nameof(AllResults));
}
}
}

private IEnumerable<ScoredResultRowModel> droppedResults;
public IEnumerable<ScoredResultRowModel> DroppedResults
{
get => droppedResults;
set
{
if (SetValue(ref droppedResults, value))
{
OnPropertyChanged(nameof(AllResults));
}
}
}

public IEnumerable<ScoredResultRowModel> AllResults => countedResults.Concat(droppedResults).OrderBy(x => x.Date);
private IEnumerable<ScoredResultRowModel> driverResults;
public IEnumerable<ScoredResultRowModel> DriverResults { get => driverResults; set => SetValue(ref driverResults, value); }

private TeamModel team;
public TeamModel Team { get => team; set => SetValue(ref team, value); }
Expand Down
2 changes: 1 addition & 1 deletion iRLeagueManager/Behaviours/DropDownButtonBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void AssociatedObject_Click(object sender, System.Windows.RoutedEventArgs e)
Interlocked.Increment(ref attachedCount);
// If there is a drop-down assigned to this button, then position and display it
source.ContextMenu.PlacementTarget = source;
source.ContextMenu.Placement = PlacementMode.Top;
//source.ContextMenu.Placement = PlacementMode.Top;
source.ContextMenu.IsOpen = true;
isContextMenuOpen = true;
}
Expand Down
Binary file added iRLeagueManager/Graphics/irlm_logo.ico
Binary file not shown.
68 changes: 64 additions & 4 deletions iRLeagueManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,42 @@ SOFTWARE.-->
<DockPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid DockPanel.Dock="Top" Height="75" Background="{StaticResource ThemeColor_DarkBlue}">
<DockPanel>
<controls:IconButton DockPanel.Dock="Left" VerticalAlignment="Stretch" Background="Transparent" Foreground="{StaticResource ThemeColor_Back0}"
IconMargin="10,5" ToolTip="Menu" x:Name="MenuButton" IconFill="{StaticResource ThemeColor_Back0}">
<controls:IconButton.IconContent>
<fa:ImageAwesome Icon="Bars" Width="30"/>
</controls:IconButton.IconContent>
<behaviors:Interaction.Behaviors>
<local:DropDownButtonBehavior/>
</behaviors:Interaction.Behaviors>
<controls:IconButton.ContextMenu>
<ContextMenu Placement="Bottom">
<MenuItem Header="Seasons">
<MenuItem Header="New" Click="CreateSeason_Click">
<MenuItem.Icon>
<fa:FontAwesome Icon="Plus" Foreground="{StaticResource ThemeColor_Green}" HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Delete" Click="DeleteSeason_Click" Tag="{Binding CurrentSeason.Model}">
<MenuItem.Icon>
<fa:FontAwesome Icon="Remove" Foreground="{StaticResource ThemeColor_Red}" HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
<MenuItem Header="Leauge" IsEnabled="False">
<MenuItem Header="Manage Members" IsEnabled="False"/>
<MenuItem Header="Switch League" IsEnabled="False"/>
</MenuItem>
<MenuItem Header="User">
<MenuItem Header="Edit Profile" Click="EditUser_Click"/>
<MenuItem Header="Change Password" Click="ChangePassword_Click"/>
</MenuItem>
<MenuItem Header="Exit" Click="CloseButton_Click"/>
</ContextMenu>
</controls:IconButton.ContextMenu>
</controls:IconButton>
<controls:IconToggleButton DockPanel.Dock="Right" VerticalAlignment="Stretch" Background="Transparent" Foreground="{StaticResource ThemeColor_Back0}"
IconMargin="10,5" ToolTip="Always on Top" x:Name="AlwaysOnTopToggle">
<controls:IconToggleButton.IconContent>
Expand All @@ -205,11 +241,18 @@ SOFTWARE.-->
</controls:IconToggleButton.Style>
</controls:IconToggleButton>
<Image DockPanel.Dock="Left" Source="{StaticResource Logo_Dark}" Margin="25,5"/>
<TextBlock Text="{Binding CurrentLeagueName}" FontFamily="{DynamicResource Header.FontFamily}"
<TextBlock FontFamily="{DynamicResource Header.FontFamily}"
FontSize="{DynamicResource Header.FontSize}"
Foreground="SeaShell" VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="15,0"/>
Margin="15,0">
<TextBlock.Text>
<PriorityBinding>
<Binding Path="League.LongName"/>
<Binding Path="CurrentLeagueName"/>
</PriorityBinding>
</TextBlock.Text>
</TextBlock>
</DockPanel>
</Grid>
<DockPanel DockPanel.Dock="Bottom">
Expand Down Expand Up @@ -294,8 +337,25 @@ SOFTWARE.-->
<StackPanel x:Name="Menu" Grid.Column="0" Orientation="Vertical" Margin="0,0,0,0">
<StackPanel Orientation="Vertical" MinHeight="40">
<ComboBox ItemsSource="{Binding SeasonList}" SelectedItem="{Binding SelectedSeason}"
Padding="10" HorizontalContentAlignment="Center"
DisplayMemberPath="SeasonName" />
Padding="10" HorizontalContentAlignment="Center">
<ComboBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Create Season" Click="CreateSeason_Click"/>
</ContextMenu>
</ComboBox.ContextMenu>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding SeasonName}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Create Season" Click="CreateSeason_Click"/>
<MenuItem Header="Delete Season" Click="DeleteSeason_Click" Tag="{Binding}"/>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!--<StackPanel Orientation="Horizontal" DataContext="{Binding CurrentSeason}">
<TextBlock Text="{Binding SeasonStart, Converter={StaticResource DateTimeConverter}}" />
<TextBlock Text=" - " />
Expand Down
49 changes: 49 additions & 0 deletions iRLeagueManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,54 @@ private void StatsButton_Click(object sender, RoutedEventArgs e)
_ = vm.Load(mainViewModel.CurrentSeason.Model);
}
}

private void CreateSeason_Click(object sender, RoutedEventArgs e)
{
if (sender is FrameworkElement element && mainViewModel != null)
{
var createControl = new ModalOkCancelControl()
{
ModalContent = new CreateSeasonControl(mainViewModel)
};

MainGrid.Children.Add(createControl);
try
{
createControl.ShowDialog();
}
finally
{
MainGrid.Children.Remove(createControl);
}
}
}

private async void DeleteSeason_Click(object sender, RoutedEventArgs e)
{
if (sender is FrameworkElement element && mainViewModel != null)
{
var season = element.Tag as SeasonModel;
if (season == null)
{
season = mainViewModel.CurrentSeason.Model;
}
if (MessageBox.Show("Do you really want to delete this season?\n" +
$" \"{season.SeasonName}\"\n" +
"Deleting a season will also remove all associated data such as:\n" +
"- Sessions\n" +
"- Results\n" +
"- Reviews & Penalites\n\nThis action cannot be undone!", "Delete Season", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes)
{
return;
}

await mainViewModel.RemoveSeason(season);
}
}

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}
4 changes: 2 additions & 2 deletions iRLeagueManager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.2.0")]
[assembly: AssemblyFileVersion("0.9.2.0")]
[assembly: AssemblyVersion("0.9.3.0")]
[assembly: AssemblyFileVersion("0.9.3.0")]
4 changes: 2 additions & 2 deletions iRLeagueManager/ViewModels/LeagueContainerModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public virtual async Task Load(params long[] modelId)
try
{
IsLoading = true;
Model = await LeagueContext.GetModelAsync<TSource>(modelId);
Model = (await LeagueContext.GetModelAsync<TSource>(modelId)) ?? Template;
}
catch (Exception e)
{
Expand All @@ -123,7 +123,7 @@ public virtual async Task Update()
try
{
IsLoading = true;
Model = await LeagueContext.UpdateModelAsync(Model);
Model = (await LeagueContext.UpdateModelAsync(Model)) ?? Template;
}
catch (Exception e)
{
Expand Down
Loading

0 comments on commit 1fe9301

Please sign in to comment.