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 #132 from SSchulze1989/develop
Browse files Browse the repository at this point in the history
release v0.9
  • Loading branch information
SSchulze1989 authored Jan 14, 2021
2 parents 964576d + a3c3c84 commit 3fff52b
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 328 deletions.
70 changes: 47 additions & 23 deletions DataManager/ModelMapperProfile.cs

Large diffs are not rendered by default.

51 changes: 49 additions & 2 deletions DataManager/Models/ModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System.Runtime.CompilerServices;
using System.Collections.Specialized;
using System.Collections;
using iRLeagueDatabase.Extensions;

namespace iRLeagueManager.Models
{
Expand Down Expand Up @@ -61,7 +62,30 @@ public virtual void CopyTo(ModelBase targetObject, params string[] excludeProper
if (property.GetMethod == null || property.SetMethod == null)
continue;

property.SetValue(targetObject, property.GetValue(this));
if (property.PropertyType.IsGenericType &&
property.PropertyType.GetInterfaces().Any(x => x.GetGenericTypeDefinition() == typeof(ICollection<>)))
{
var interfaceType = property.PropertyType.GetInterfaces().SingleOrDefault(x => x == typeof(ICollection<>));
// If target type implements ICollection use target collection instead of overwriting property
dynamic targetCollection = property.GetValue(targetObject);
IEnumerable sourceCollection = property.GetValue(this) as IEnumerable;
if (targetCollection == null || sourceCollection == null)
{
property.SetValue(targetObject, sourceCollection);
}
else
{
targetCollection.Clear();
foreach(var item in sourceCollection)
{
targetCollection.Add(item);
}
}
}
else
{
property.SetValue(targetObject, property.GetValue(this));
}
}

if (isInitialized)
Expand All @@ -85,7 +109,30 @@ public virtual void CopyFrom(ModelBase sourceObject, params string[] excludeProp
if (property.GetMethod == null || property.SetMethod == null)
continue;

property.SetValue(this, property.GetValue(sourceObject));
if (property.PropertyType.IsGenericType &&
property.PropertyType.GetInterfaces().Any(x => x.GetGenericTypeDefinition() == typeof(ICollection<>)))
{
var interfaceType = property.PropertyType.GetInterfaces().SingleOrDefault(x => x == typeof(ICollection<>));
// If target type implements ICollection use target collection instead of overwriting property
dynamic targetCollection = property.GetValue(this);
IEnumerable sourceCollection = property.GetValue(sourceObject) as IEnumerable;
if (targetCollection == null || sourceCollection == null)
{
property.SetValue(this, sourceCollection);
}
else
{
targetCollection.Clear();
foreach (dynamic item in sourceCollection)
{
targetCollection.Add(item);
}
}
}
else
{
property.SetValue(this, property.GetValue(sourceObject));
}
}

if (sourceObject.isInitialized)
Expand Down
66 changes: 0 additions & 66 deletions DataManager/Models/Results/ScoredResultRowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,72 +58,6 @@ public class ScoredResultRowModel : ResultRowModel

public override int PositionChange => StartPosition - FinalPosition;

//public int PositionChange => StartPosition - FinalPosition;

//public long? ResultRowId { get; internal set; }
//public long ResultId { get; set; }

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

////private int finalPosition;
////public int FinalPosition { get => finalPosition; set { finalPosition = value; OnPropertyChanged(); } }

//private int startPosition;
//public int StartPosition { get => startPosition; set { startPosition = value; OnPropertyChanged(); } }

//private int finishPosition;
//public int FinishPosition { get => finishPosition; set { finishPosition = value; OnPropertyChanged(); } }

//private LeagueMember member;
//public LeagueMember Member { get => member; set { member = value; OnPropertyChanged(); OnPropertyChanged(nameof(MemberId)); } }

//private string teamName;
//public string TeamName { get => teamName; set => SetValue(ref teamName, value); }

//public long? MemberId { get => Member?.MemberId; }

//private int carNumber;
//public int CarNumber { get => carNumber; set { carNumber = value; OnPropertyChanged(); } }

//private int classId;
//public int ClassId { get => classId; set { classId = value; OnPropertyChanged(); } }

//private string car;
//public string Car { get => car; set { car = value; OnPropertyChanged(); } }

//private string carClass;
//public string CarClass { get => carClass; set { carClass = value; OnPropertyChanged(); } }

//public int completedLaps;
//public int CompletedLaps { get => completedLaps; set { completedLaps = value; OnPropertyChanged(); } }

//private int leadLaps;
//public int LeadLaps { get => leadLaps; set { leadLaps = value; OnPropertyChanged(); } }

//private int fastLapNr;
//public int FastLapNr { get => fastLapNr; set { fastLapNr = value; OnPropertyChanged(); } }

//private int incidents;
//public int Incidents { get => incidents; set { incidents = value; OnPropertyChanged(); } }

//private RaceStatusEnum status;
//public RaceStatusEnum Status { get => status; set { status = value; OnPropertyChanged(); } }

//private LapTime qualifyingTime = new LapTime();
//public LapTime QualifyingTime { get => qualifyingTime; set { qualifyingTime = value; OnPropertyChanged(); } }

//private LapInterval interval;
//public LapInterval Interval { get => interval; set { interval = value; OnPropertyChanged(); } }

//private LapTime avgLapTime;
//public LapTime AvgLapTime { get => avgLapTime; set { avgLapTime = value; OnPropertyChanged(); } }

//private LapTime fastestLapTime;
//public LapTime FastestLapTime { get => fastestLapTime; set { fastestLapTime = value; OnPropertyChanged(); } }

//private Location location;
//public Location Location { get => location; set => SetValue(ref location, value); }

private DateTime date;
public DateTime Date { get => date; set => SetValue(ref date, value); }

Expand Down
35 changes: 19 additions & 16 deletions DataManager/Models/Reviews/IncidentReviewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using iRLeagueManager.Enums;
using System.Collections.ObjectModel;
using iRLeagueManager.Models.User;
using iRLeagueDatabase.Extensions;

namespace iRLeagueManager.Models.Reviews
{
Expand All @@ -49,8 +50,10 @@ public class IncidentReviewModel : IncidentReviewInfo, IHierarchicalModel
//public ScheduleModel Schedule => Session?.Schedule;
//public SeasonModel Season => Schedule?.Season;

private SessionInfo session;
public SessionInfo Session { get => session; internal set { SetValue(ref session, value); } }
//private SessionInfo session;
//public SessionInfo Session { get => session; internal set { SetValue(ref session, value); } }
private long sessionId;
public long SessionId { get => sessionId; internal set => SetValue(ref sessionId, value); }

private string incidentNr;
public string IncidentNr { get => incidentNr; set => SetValue(ref incidentNr, value); }
Expand Down Expand Up @@ -102,7 +105,7 @@ public IncidentReviewModel(UserModel author, SessionInfo session) : base(author)
Comments = new ObservableCollection<ReviewCommentModel>();
AcceptedReviewVotes = new ObservableCollection<ReviewVoteModel>();

Session = session;
SessionId = session.SessionId.GetValueOrDefault();
}

//public IncidentReviewModel(ResultModel result) : this ()
Expand Down Expand Up @@ -138,19 +141,19 @@ internal override void InitializeModel()

public override void CopyFrom(ModelBase sourceObject, params string[] excludeProperties)
{
base.CopyFrom(sourceObject, excludeProperties);
base.CopyFrom(sourceObject, excludeProperties.Concat(new string[] { nameof(Comments), nameof(AcceptedReviewVotes) }).ToArray());

if (sourceObject is IncidentReviewModel reviewModel)
{
InitReset();
InvolvedMembers = new ObservableCollection<LeagueMember>(reviewModel.InvolvedMembers.ToList());
Comments = new ObservableCollection<ReviewCommentModel>(reviewModel.Comments.Select(x =>
{
var comment = new ReviewCommentModel();
comment.CopyFrom(x);
return comment;
}).ToList());
AcceptedReviewVotes = new ObservableCollection<ReviewVoteModel>(reviewModel.AcceptedReviewVotes.Select(x =>
//InvolvedMembkers.MapCollection(reviewModel.InvolvedMembers.ToList());
Comments.MapCollection(reviewModel.Comments.Select(x =>
{
var comment = new ReviewCommentModel();
comment.CopyFrom(x);
return comment;
}).ToList());
AcceptedReviewVotes.MapCollection(reviewModel.AcceptedReviewVotes.Select(x =>
{
var vote = new ReviewVoteModel();
vote.CopyFrom(x);
Expand All @@ -166,19 +169,19 @@ public override void CopyFrom(ModelBase sourceObject, params string[] excludePro

public override void CopyTo(ModelBase targetObject, params string[] excludeProperties)
{
base.CopyTo(targetObject, excludeProperties);
base.CopyTo(targetObject, excludeProperties.Concat(new string[] { nameof(Comments), nameof(AcceptedReviewVotes) }).ToArray());

if (targetObject is IncidentReviewModel reviewModel)
{
reviewModel.InitReset();
reviewModel.InvolvedMembers = new ObservableCollection<LeagueMember>(InvolvedMembers.ToList());
reviewModel.Comments = new ObservableCollection<ReviewCommentModel>(Comments.Select(x =>
//reviewModel.InvolvedMembers = new ObservableCollection<LeagueMember>(InvolvedMembers.ToList());
reviewModel.Comments.MapCollection(Comments.Select(x =>
{
var comment = new ReviewCommentModel();
comment.CopyFrom(x);
return comment;
}).ToList());
reviewModel.AcceptedReviewVotes = new ObservableCollection<ReviewVoteModel>(AcceptedReviewVotes.Select(x =>
reviewModel.AcceptedReviewVotes.MapCollection(AcceptedReviewVotes.Select(x =>
{
var vote = new ReviewVoteModel();
vote.CopyFrom(x);
Expand Down
17 changes: 10 additions & 7 deletions DataManager/Models/Reviews/ReviewCommentModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using iRLeagueManager.Interfaces;
using System.Collections.ObjectModel;
using iRLeagueManager.Models.User;
using iRLeagueDatabase.Extensions;

namespace iRLeagueManager.Models.Reviews
{
Expand All @@ -47,8 +48,10 @@ public class ReviewCommentModel : CommentModel, IReviewComment, INotifyPropertyC
//public ScheduleModel Schedule => Review?.Schedule;

//public override SeasonModel Season => Schedule?.Season;
private IncidentReviewInfo review;
public IncidentReviewInfo Review { get => review; internal set => SetValue(ref review, value); }
//private IncidentReviewInfo review;
//public IncidentReviewInfo Review { get => review; internal set => SetValue(ref review, value); }
private long? reviewId;
public long? ReviewId { get => reviewId; internal set => SetValue(ref reviewId, value); }

private ObservableCollection<ReviewVoteModel> commentReviewVotes;
public ObservableCollection<ReviewVoteModel> CommentReviewVotes { get => commentReviewVotes; set => SetNotifyCollection(ref commentReviewVotes, value); }
Expand All @@ -70,7 +73,7 @@ public ReviewCommentModel(UserModel author) : base(author)

public ReviewCommentModel(UserModel author, IncidentReviewInfo review) : this(author)
{
Review = review;
ReviewId = review.ReviewId;
}

internal override void InitializeModel()
Expand All @@ -84,13 +87,13 @@ internal override void InitializeModel()

public override void CopyFrom(ModelBase sourceObject, params string[] excludeProperties)
{
base.CopyFrom(sourceObject, excludeProperties);
base.CopyFrom(sourceObject, excludeProperties.Concat(new string[] { nameof(CommentReviewVotes) }).ToArray());

if (sourceObject is ReviewCommentModel commentModel)
{
InitReset();

CommentReviewVotes = new ObservableCollection<ReviewVoteModel>(commentModel.CommentReviewVotes.Select(x =>
CommentReviewVotes.MapCollection(commentModel.CommentReviewVotes.Select(x =>
{
var vote = new ReviewVoteModel();
vote.CopyFrom(x);
Expand All @@ -106,12 +109,12 @@ public override void CopyFrom(ModelBase sourceObject, params string[] excludePro

public override void CopyTo(ModelBase targetObject, params string[] excludeProperties)
{
base.CopyTo(targetObject, excludeProperties);
base.CopyTo(targetObject, excludeProperties.Concat(new string[] { nameof(CommentReviewVotes) }).ToArray());

if (targetObject is ReviewCommentModel commentModel)
{
commentModel.InitReset();
commentModel.CommentReviewVotes = new ObservableCollection<ReviewVoteModel>(CommentReviewVotes.Select(x =>
commentModel.CommentReviewVotes.MapCollection(CommentReviewVotes.Select(x =>
{
var vote = new ReviewVoteModel();
vote.CopyFrom(x);
Expand Down
63 changes: 1 addition & 62 deletions DataManager/Models/SeasonModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

namespace iRLeagueManager.Models
{
public class SeasonModel : SeasonInfo, IHierarchicalModel //, ISeason
public class SeasonModel : SeasonInfo //, ISeason
{
private ObservableCollection<ScheduleInfo> schedules;
public ObservableCollection<ScheduleInfo> Schedules
Expand Down Expand Up @@ -72,8 +72,6 @@ public ScoringModel MainScoring
//private ObservableCollection<ResultInfo> results;
//public ObservableCollection<ResultInfo> Results { get => results; internal set => SetNotifyCollection(ref results, value); }

string IHierarchicalModel.Description => SeasonName;

private DateTime seasonStart;
public DateTime SeasonStart { get => seasonStart; internal set => SetValue(ref seasonStart, value); }

Expand All @@ -89,12 +87,6 @@ public ScoringModel MainScoring
private bool hideCommentsBeforeVoted;
public bool HideCommentsBeforeVoted { get => hideCommentsBeforeVoted; set => SetValue(ref hideCommentsBeforeVoted, value); }

IEnumerable<object> IHierarchicalModel.Children => new List<IEnumerable<object>> { Schedules.Cast<object>() };

public IEnumerable<ResultModel> GetResults()
{
return null;
}
// client.Results.Where(x => Sessions.Select(y => y.SessionId).Contains(x.SessionId));

//public IEnumerable<ISession> Sessions => Schedules.Select(x => x.Sessions.AsEnumerable()).Aggregate((x, y) => x.Concat(y));
Expand All @@ -119,41 +111,6 @@ public SeasonModel(long? seasonId) : this()
SeasonId = seasonId;
}

//public IEnumerable<SessionInfo> GetSessions()
//{
// return Schedules.Select(x => x.Sessions.AsEnumerable()).Aggregate((x, y) => x.Concat(y));
//}

//public int GetSessionCount()
//{
// return GetSessions().Count();
//}

//public SessionInfo GetLastSession()
//{
// return GetSessions().OrderBy(x => x.Date).Last();
//}

//internal override void InitReset()
//{
// foreach (var schedule in Schedules)
// {
// schedule.Season = this;
// schedule.InitReset();
// }

// foreach (var result in Results)
// {
// result.InitReset();
// }

// foreach (var review in Reviews)
// {
// review.InitReset();
// }
// base.InitReset();
//}

internal override void InitializeModel()
{
if (!isInitialized)
Expand All @@ -170,26 +127,8 @@ internal override void InitializeModel()
}
foreach (var scoringTable in ScoringTables)
{
//for (int i = 0; i < scoringTable.Scorings.Count(); i++)
//{
// var scoring = Scorings.SingleOrDefault(x => x.ScoringId == scoringTable.Scorings.ElementAt(i).Key.ScoringId);
// if (scoring != null)
// {
// scoringTable.Scorings.ElementAt(i).Key = scoring;
// }
//}
scoringTable.InitializeModel();
}

//foreach (var result in Results)
//{
// result.InitializeModel();
//}

//foreach (var review in Reviews)
//{
// review.InitializeModel();
//}
}
base.InitializeModel();
}
Expand Down
Loading

0 comments on commit 3fff52b

Please sign in to comment.