Till slut fick jag personvalet att fungera
This commit is contained in:
@ -4,6 +4,6 @@ public interface IRepository<TEntity>
|
||||
{
|
||||
Task<IEnumerable<TEntity>> Get();
|
||||
Task<TEntity?> Get(int id);
|
||||
Task<bool> Save(TEntity entity);
|
||||
Task<int> Save(TEntity entity);
|
||||
bool Delete(TEntity entity);
|
||||
}
|
||||
|
||||
@ -21,9 +21,9 @@ public class GamePointRepository : IRepository<GamePoint>
|
||||
{
|
||||
return await _dataContext.GamePoints.FindAsync(id);
|
||||
}
|
||||
public async Task<bool> Save(GamePoint entity)
|
||||
public async Task<int> Save(GamePoint entity)
|
||||
{
|
||||
var res = false;
|
||||
var res = -1;
|
||||
if ((entity.GameRoundRegNr == 0)
|
||||
|| (entity.GameRegPoints == 0))
|
||||
{
|
||||
@ -34,13 +34,13 @@ public class GamePointRepository : IRepository<GamePoint>
|
||||
{
|
||||
_dataContext.GamePoints.Add(entity);
|
||||
await _dataContext.SaveChangesAsync();
|
||||
res = true;
|
||||
res = entity.GamePointId;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dataContext.GamePoints.Update(entity);
|
||||
await _dataContext.SaveChangesAsync();
|
||||
res = true;
|
||||
res = entity.GamePointId;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -41,20 +41,20 @@ public class GameRoundRepository : IRepository<GameRound>
|
||||
return await _dataContext.GameRounds.FindAsync(id);
|
||||
}
|
||||
|
||||
public async Task<bool> Save(GameRound entity)
|
||||
public async Task<int> Save(GameRound entity)
|
||||
{
|
||||
var res = false;
|
||||
var res = -1;
|
||||
if (entity.GameRoundId == 0)
|
||||
{
|
||||
_dataContext.GameRounds.Add(entity);
|
||||
await _dataContext.SaveChangesAsync();
|
||||
res = true;
|
||||
res = entity.GameRoundId;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dataContext.GameRounds.Update(entity);
|
||||
await _dataContext.SaveChangesAsync();
|
||||
res = true;
|
||||
res = entity.GameRoundId;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -22,9 +22,9 @@ public class ParticipantRepository : IRepository<Participant>
|
||||
// Fix: Use FindAsync with key value array, not a predicate
|
||||
return await _dataContext.Participants.FindAsync(id);
|
||||
}
|
||||
public async Task<bool> Save(Participant entity)
|
||||
public async Task<int> Save(Participant entity)
|
||||
{
|
||||
var res = false;
|
||||
var res = -1;
|
||||
if (string.IsNullOrEmpty(entity.FirstName)
|
||||
|| string.IsNullOrEmpty(entity.LastName))
|
||||
{
|
||||
@ -35,13 +35,13 @@ public class ParticipantRepository : IRepository<Participant>
|
||||
{
|
||||
_dataContext.Participants.Add(entity);
|
||||
await _dataContext.SaveChangesAsync();
|
||||
res = true;
|
||||
res = entity.ParticipantId;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dataContext.Participants.Update(entity);
|
||||
await _dataContext.SaveChangesAsync();
|
||||
res = true;
|
||||
res = entity.ParticipantId;
|
||||
}
|
||||
return res;
|
||||
|
||||
|
||||
@ -54,4 +54,6 @@ public class GameRound : EntityBase
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -4,13 +4,125 @@ namespace GreadyPoang.EntityLayer;
|
||||
|
||||
public class RoundBuilderElement : EntityBase
|
||||
{
|
||||
public int ParticipantId { get; set; }
|
||||
public string ParticipantName { get; set; } = string.Empty;
|
||||
public int GameRoundRegNr { get; set; }
|
||||
public int GameRegPoints { get; set; }
|
||||
public int GameRoundPoints { get; set; }
|
||||
public GamePointStatus Status { get; set; }
|
||||
public DateTime GameRoundStartDate { get; set; }
|
||||
public int GameRoundId { get; set; }
|
||||
public RoundBuilderElement()
|
||||
{
|
||||
_participantId = 0;
|
||||
_participantName = string.Empty;
|
||||
_gameRoundRegNr = 0;
|
||||
_gameRegPoints = 0;
|
||||
_status = GamePointStatus.New;
|
||||
_gameRoundStartDate = DateTime.MinValue;
|
||||
_gameRoundId = 0;
|
||||
_gamePointId = 0;
|
||||
}
|
||||
|
||||
private int _participantId;
|
||||
private string _participantName;
|
||||
private int _gameRoundRegNr;
|
||||
private int _gameRegPoints;
|
||||
private GamePointStatus _status;
|
||||
private DateTime _gameRoundStartDate;
|
||||
private int _gameRoundId;
|
||||
private int _gamePointId;
|
||||
|
||||
public int ParticipantId
|
||||
{
|
||||
get { return _participantId; }
|
||||
set
|
||||
{
|
||||
_participantId = value;
|
||||
RaisePropertyChanged(nameof(ParticipantId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string ParticipantName
|
||||
{
|
||||
get { return _participantName; }
|
||||
set
|
||||
{
|
||||
_participantName = value;
|
||||
RaisePropertyChanged(nameof(ParticipantName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int GameRoundRegNr
|
||||
{
|
||||
get { return _gameRoundRegNr; }
|
||||
set
|
||||
{
|
||||
_gameRoundRegNr = value;
|
||||
RaisePropertyChanged(nameof(GameRoundRegNr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int GameRegPoints
|
||||
{
|
||||
get { return _gameRegPoints; }
|
||||
set
|
||||
{
|
||||
_gameRegPoints = value;
|
||||
RaisePropertyChanged(nameof(GameRegPoints));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public GamePointStatus Status
|
||||
{
|
||||
get { return _status; }
|
||||
set
|
||||
{
|
||||
_status = value;
|
||||
RaisePropertyChanged(nameof(Status));
|
||||
RaisePropertyChanged(nameof(StatusString));
|
||||
}
|
||||
}
|
||||
|
||||
public string StatusString
|
||||
{
|
||||
get { return _status.ToString(); }
|
||||
}
|
||||
|
||||
public DateTime GameRoundStartDate
|
||||
{
|
||||
get { return _gameRoundStartDate; }
|
||||
set
|
||||
{
|
||||
_gameRoundStartDate = value;
|
||||
RaisePropertyChanged(nameof(GameRoundStartDate));
|
||||
RaisePropertyChanged(nameof(GameRoundStartDateString));
|
||||
}
|
||||
}
|
||||
|
||||
public string GameRoundStartDateString
|
||||
{
|
||||
get { return _gameRoundStartDate.ToString("yyyy-MM-dd"); }
|
||||
}
|
||||
|
||||
public int GameRoundId
|
||||
{
|
||||
get { return _gameRoundId; }
|
||||
set
|
||||
{
|
||||
_gameRoundId = value;
|
||||
RaisePropertyChanged(nameof(GameRoundId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int GamePointId
|
||||
{
|
||||
get { return _gamePointId; }
|
||||
set
|
||||
{
|
||||
_gamePointId = value;
|
||||
RaisePropertyChanged(nameof(GamePointId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -84,13 +84,13 @@ public class ParticipantViewModel : ViewModelBase
|
||||
return false;
|
||||
}
|
||||
var tmpTask = _Repository.Save(ParticipantObject);
|
||||
bool tmp = tmpTask.GetAwaiter().GetResult();
|
||||
if (tmp)
|
||||
int tmp = tmpTask.GetAwaiter().GetResult();
|
||||
if (tmp != -1)
|
||||
{
|
||||
ParticipantObject = new Participant();
|
||||
this.Get();
|
||||
}
|
||||
return tmp;
|
||||
return tmp != -1;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@ -13,9 +13,10 @@ public class RoundStartingViewModel : ViewModelBase
|
||||
|
||||
}
|
||||
|
||||
public RoundStartingViewModel(IRepository<GameRound> repo, IMethodSharingService<Participant> sharingService) : base()
|
||||
public RoundStartingViewModel(IRepository<GameRound> repo, IRepository<GamePoint> pointsRepo, IMethodSharingService<Participant> sharingService) : base()
|
||||
{
|
||||
_Repository = repo;
|
||||
_pointsRepo = pointsRepo;
|
||||
_sharingService = sharingService;
|
||||
_roundElements = new ObservableCollection<RoundBuilderElement>();
|
||||
}
|
||||
@ -26,6 +27,7 @@ public class RoundStartingViewModel : ViewModelBase
|
||||
private ObservableCollection<GameRound> _GameRoundList = new();
|
||||
private ObservableCollection<Participant> _ParticipantList = new();
|
||||
private readonly IRepository<GameRound>? _Repository;
|
||||
private readonly IRepository<GamePoint> _pointsRepo;
|
||||
private readonly IMethodSharingService<Participant> _sharingService;
|
||||
private Participant _selectedItem;
|
||||
|
||||
@ -65,8 +67,38 @@ public class RoundStartingViewModel : ViewModelBase
|
||||
GameRoundStartDate = DateTime.Now,
|
||||
GameRoundFinished = null
|
||||
};
|
||||
_Repository?.Save(GameRound).GetAwaiter().GetResult();
|
||||
var gameRoundId = _Repository?.Save(GameRound).GetAwaiter().GetResult();
|
||||
if (gameRoundId != null && gameRoundId != -1)
|
||||
{
|
||||
GameRound.GameRoundId = gameRoundId.Value;
|
||||
}
|
||||
GameRoundObject = GameRound;
|
||||
}
|
||||
|
||||
var GamePointStart = new GamePoint
|
||||
{
|
||||
ParticipantId = item.ParticipantId,
|
||||
GameRoundId = GameRoundObject?.GameRoundId ?? 0,
|
||||
GameDate = DateTime.Now,
|
||||
GameRoundRegNr = 0,
|
||||
GameRegPoints = 0,
|
||||
PointStatus = GamePointStatus.New
|
||||
};
|
||||
|
||||
var gamePointId = _pointsRepo.Save(GamePointStart).GetAwaiter().GetResult();
|
||||
GamePointStart.GamePointId = gamePointId;
|
||||
|
||||
var newElement = new RoundBuilderElement();
|
||||
newElement.ParticipantId = item.ParticipantId;
|
||||
newElement.ParticipantName = item.LastNameFirstName;
|
||||
newElement.GameRoundRegNr = GamePointStart.GameRoundRegNr;
|
||||
newElement.GameRegPoints = GamePointStart.GameRegPoints;
|
||||
newElement.Status = GamePointStart.PointStatus;
|
||||
newElement.GameRoundStartDate = GameRoundObject?.GameRoundStartDate ?? DateTime.Now;
|
||||
newElement.GameRoundId = GamePointStart.GameRoundId;
|
||||
newElement.GamePointId = GamePointStart.GamePointId;
|
||||
|
||||
_roundElements.Add(newElement);
|
||||
// Gör något med det valda objektet
|
||||
Debug.WriteLine($"Du valde: {item.LastNameFirstName}");
|
||||
}
|
||||
@ -151,7 +183,7 @@ public class RoundStartingViewModel : ViewModelBase
|
||||
return false;
|
||||
}
|
||||
var tmpTask = _Repository.Save(GameRoundObject);
|
||||
bool tmp = tmpTask.GetAwaiter().GetResult();
|
||||
bool tmp = tmpTask.GetAwaiter().GetResult() != -1;
|
||||
if (tmp)
|
||||
{
|
||||
GameRoundObject = new GameRound();
|
||||
|
||||
@ -11,7 +11,7 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
|
||||
{
|
||||
|
||||
}
|
||||
public RoundStartingViewModelCommands(IRepository<GameRound> repo, IMethodSharingService<Participant> sharingService) : base(repo, sharingService)
|
||||
public RoundStartingViewModelCommands(IRepository<GameRound> repo, IRepository<GamePoint> pointsRepo, IMethodSharingService<Participant> sharingService) : base(repo, pointsRepo, sharingService)
|
||||
{
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
|
||||
RaisePropertyChanged(nameof(IsSaveCommandEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Commands
|
||||
|
||||
@ -72,8 +72,7 @@
|
||||
Text="{Binding LastNameFirstName}" />
|
||||
</HorizontalStackLayout>
|
||||
<HorizontalStackLayout>
|
||||
<Button Text="Edit" Style="{StaticResource HoverButtonBlueStyle}"
|
||||
CommandParameter="{Binding ParticipantId}"/>
|
||||
<Button Text="Edit" Style="{StaticResource HoverButtonBlueStyle}" CommandParameter="{Binding EditCommand}"/>
|
||||
<Button Style="{StaticResource HoverButtonRedStyle}" Text="Delete" />
|
||||
</HorizontalStackLayout>
|
||||
</VerticalStackLayout>
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
|
||||
x:Class="GreadyPoang.Views.RoundStartingView"
|
||||
xmlns:vm="clr-namespace:GreadyPoang.CommandClasses"
|
||||
xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
|
||||
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
|
||||
x:DataType="vm:RoundStartingViewModelCommands"
|
||||
x:Name="GameRoundStartingPage"
|
||||
@ -35,23 +36,53 @@
|
||||
Title="Välj deltagare"/>
|
||||
</Border>
|
||||
<Border Stroke="Gold" StrokeThickness="2" BackgroundColor="LightCyan" >
|
||||
<HorizontalStackLayout>
|
||||
<Border Stroke="red" StrokeThickness="4" BackgroundColor="DarkGoldenrod">
|
||||
<Label Text="Här kommer du kunna välja deltagare och starta en ny spelrunda"
|
||||
FontAttributes="Bold"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Center"/>
|
||||
</Border>
|
||||
<Border Stroke="red" StrokeThickness="4" BackgroundColor="DarkGoldenrod">
|
||||
<Label Text="Här kommer du kunna välja deltagare och starta en ny spelrunda"
|
||||
FontAttributes="Bold"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Center"/>
|
||||
</Border>
|
||||
|
||||
</HorizontalStackLayout>
|
||||
<CollectionView
|
||||
ItemsSource="{Binding RoundElements}"
|
||||
ItemsLayout="HorizontalList"
|
||||
SelectionMode="None">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate x:DataType="model:RoundBuilderElement">
|
||||
<Border
|
||||
Padding="10"
|
||||
Margin="5"
|
||||
WidthRequest="150"
|
||||
HeightRequest="100"
|
||||
Stroke="LightGray"
|
||||
StrokeThickness="1"
|
||||
x:Name="RoundElementBorder"
|
||||
BackgroundColor="{Binding Status, Converter={StaticResource StatusToColorConverter}}"
|
||||
StrokeShape="RoundRectangle 10">
|
||||
<Border.GestureRecognizers>
|
||||
<TapGestureRecognizer
|
||||
Command="{Binding BindingContext.ParticipantTappedCommand, Source={x:Reference Name=GameRoundStartingPage}}"
|
||||
CommandParameter="{Binding .}" />
|
||||
</Border.GestureRecognizers>
|
||||
<Border.Triggers>
|
||||
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="New">
|
||||
<Setter Property="BackgroundColor" Value="LightGreen" />
|
||||
</DataTrigger>
|
||||
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="InProgress">
|
||||
<Setter Property="BackgroundColor" Value="LightYellow" />
|
||||
</DataTrigger>
|
||||
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Completed">
|
||||
<Setter Property="BackgroundColor" Value="DarkGreen" />
|
||||
</DataTrigger>
|
||||
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Cancelled">
|
||||
<Setter Property="BackgroundColor" Value="LightCoral" />
|
||||
</DataTrigger>
|
||||
</Border.Triggers>
|
||||
<VerticalStackLayout>
|
||||
<Label Text="------------------" FontAttributes="Bold" FontSize="12" TextColor="Black"/>
|
||||
<Label Text="{Binding ParticipantName}" FontAttributes="Bold" FontSize="12" TextColor="Black"/>
|
||||
<Label Text="{Binding GameRoundStartDateString}" FontAttributes="Bold" FontSize="12" TextColor="Black"/>
|
||||
<Label Text="{Binding StatusString}" FontSize="12" TextColor="DarkGray" />
|
||||
<Label Text="------------------" FontAttributes="Bold" FontSize="12" TextColor="Black"/>
|
||||
</VerticalStackLayout>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
</Border>
|
||||
|
||||
</HorizontalStackLayout>
|
||||
</Border>
|
||||
<Border Grid.Row="2" Stroke="Gold" BackgroundColor="Ivory" StrokeThickness="2" Padding="5">
|
||||
|
||||
Reference in New Issue
Block a user