Commit före flytt avStatusparameter från point till round

This commit is contained in:
2025-09-13 08:43:17 +02:00
parent a2d47debfe
commit b4898660f2
13 changed files with 226 additions and 34 deletions

View File

@ -6,4 +6,5 @@ public interface IRepository<TEntity>
Task<TEntity?> Get(int id); Task<TEntity?> Get(int id);
Task<int> Save(TEntity entity); Task<int> Save(TEntity entity);
bool Delete(TEntity entity); bool Delete(TEntity entity);
Task<bool> DeleteById(int Id);
} }

View File

@ -0,0 +1,36 @@
using GreadyPoang.DataLayer.Database;
using GreadyPoang.EntityLayer;
namespace GreadyPoang.DataLayer;
public class CombinedRepository : ICombinedRepository
{
private readonly DataContext _context;
public CombinedRepository(DataContext context)
{
_context = context;
}
IEnumerable<RoundBuilderElement> ICombinedRepository.roundBuilderElements()
{
var result = (from gameRound in _context.GameRounds
join gamePoint in _context.GamePoints on gameRound.GameRoundId equals gamePoint.GameRoundId
join participant in _context.Participants on gamePoint.ParticipantId equals participant.ParticipantId
orderby gameRound.GameRoundStartDate descending, participant.LastName, participant.FirstName, gamePoint.GameRoundRegNr
select new RoundBuilderElement
{
ParticipantId = participant.ParticipantId,
ParticipantName = participant.LastNameFirstName,
GamePointId = gamePoint.GamePointId,
GameRoundRegNr = gameRound.GameRoundId,
GameRegPoints = gamePoint.GameRegPoints,
GameRoundId = gameRound.GameRoundId,
GameRoundStartDate = gameRound.GameRoundStartDate,
Status = gamePoint.PointStatus
}).ToList();
return result;
}
}

View File

@ -25,7 +25,7 @@ public class GamePointRepository : IRepository<GamePoint>
{ {
var res = -1; var res = -1;
if ((entity.GameRoundRegNr == 0) if ((entity.GameRoundRegNr == 0)
|| (entity.GameRegPoints == 0)) && (entity.GameRegPoints == 0))
{ {
return res; // Validation failed return res; // Validation failed
} }
@ -51,7 +51,7 @@ public class GamePointRepository : IRepository<GamePoint>
try try
{ {
_dataContext.GamePoints.Remove(entity); _dataContext.GamePoints.Remove(entity);
_dataContext.SaveChanges(); _dataContext.SaveChangesAsync();
res = true; res = true;
} }
catch (Exception ex) catch (Exception ex)
@ -62,6 +62,22 @@ public class GamePointRepository : IRepository<GamePoint>
return res; return res;
} }
public async Task<bool> DeleteById(int Id)
{
var ok = false;
var delObject = await this.Get(Id);
if (delObject != null)
{
try
{
ok = this.Delete(delObject);
}
catch (Exception ex)
{
throw new Exception("Unsuccessful remove of GamePoint: " + ex.Message);
}
}
return ok;
}
} }

View File

@ -58,4 +58,24 @@ public class GameRoundRepository : IRepository<GameRound>
} }
return res; return res;
} }
public async Task<bool> DeleteById(int Id)
{
var ok = false;
var delObject = await this.Get(Id);
if (delObject != null)
{
try
{
ok = this.Delete(delObject);
}
catch (Exception ex)
{
throw new Exception("Unsuccessful remove of GameRound: " + ex.Message);
}
}
return ok;
}
} }

View File

@ -62,4 +62,23 @@ public class ParticipantRepository : IRepository<Participant>
} }
return res; return res;
} }
public async Task<bool> DeleteById(int Id)
{
var ok = false;
var delObject = await this.Get(Id);
if (delObject != null)
{
try
{
ok = this.Delete(delObject);
}
catch (Exception ex)
{
throw new Exception("Unsuccessful remove of Participant: " + ex.Message);
}
}
return ok;
}
} }

View File

@ -0,0 +1,9 @@

using GreadyPoang.EntityLayer;
namespace GreadyPoang.DataLayer;
public interface ICombinedRepository
{
IEnumerable<RoundBuilderElement> roundBuilderElements();
}

View File

@ -13,7 +13,6 @@ public class GamePoint : EntityBase
_gameDate = DateTime.Now; _gameDate = DateTime.Now;
_gameRoundRegNr = 0; _gameRoundRegNr = 0;
_gameRegPoints = 0; _gameRegPoints = 0;
_pointStatus = GamePointStatus.New;
} }
private int _gamePointId; private int _gamePointId;
@ -22,7 +21,6 @@ public class GamePoint : EntityBase
private DateTime _gameDate; private DateTime _gameDate;
private int _gameRoundRegNr; private int _gameRoundRegNr;
private int _gameRegPoints; private int _gameRegPoints;
private GamePointStatus _pointStatus;
[PrimaryKey] [PrimaryKey]
[AutoIncrement] [AutoIncrement]
@ -91,16 +89,6 @@ public class GamePoint : EntityBase
} }
} }
[Column("PointStatus")]
public GamePointStatus PointStatus
{
get { return _pointStatus; }
set
{
_pointStatus = value;
RaisePropertyChanged(nameof(PointStatus));
}
}
} }

View File

@ -12,11 +12,13 @@ public class GameRound : EntityBase
{ {
_gameRoundId = 0; _gameRoundId = 0;
_gameRoundStartDate = DateTime.Now; _gameRoundStartDate = DateTime.Now;
_gameStatus = GamePointStatus.New;
_gameRoundFinished = null; _gameRoundFinished = null;
} }
private int _gameRoundId; private int _gameRoundId;
private DateTime _gameRoundStartDate; private DateTime _gameRoundStartDate;
private GamePointStatus _gameStatus;
private DateTime? _gameRoundFinished; private DateTime? _gameRoundFinished;
[Column("GameRoundFinished")] [Column("GameRoundFinished")]
@ -41,6 +43,18 @@ public class GameRound : EntityBase
} }
} }
[Column("GameStatus")]
public GamePointStatus PointStatus
{
get { return _gameStatus; }
set
{
_gameStatus = value;
RaisePropertyChanged(nameof(PointStatus));
}
}
[PrimaryKey] [PrimaryKey]
[AutoIncrement] [AutoIncrement]
[Column("GameRoundId")] [Column("GameRoundId")]
@ -54,6 +68,10 @@ public class GameRound : EntityBase
} }
} }
public string GameRoundStartDateString
{
get { return _gameRoundStartDate.ToString("yyyy-MM-dd"); }
}
} }

View File

@ -80,7 +80,7 @@ public class RoundStartingViewModel : ViewModelBase
ParticipantId = item.ParticipantId, ParticipantId = item.ParticipantId,
GameRoundId = GameRoundObject?.GameRoundId ?? 0, GameRoundId = GameRoundObject?.GameRoundId ?? 0,
GameDate = DateTime.Now, GameDate = DateTime.Now,
GameRoundRegNr = 0, GameRoundRegNr = -1,
GameRegPoints = 0, GameRegPoints = 0,
PointStatus = GamePointStatus.New PointStatus = GamePointStatus.New
}; };
@ -187,11 +187,22 @@ public class RoundStartingViewModel : ViewModelBase
if (tmp) if (tmp)
{ {
GameRoundObject = new GameRound(); GameRoundObject = new GameRound();
RoundElements.Clear();
this.Get(); this.Get();
} }
return tmp; return tmp;
} }
public void Rensa()
{
foreach (var element in RoundElements)
{
_pointsRepo.DeleteById(element.GamePointId);
}
_Repository?.DeleteById(GameRoundObject?.GameRoundId ?? 0);
RoundElements.Clear();
}
#endregion #endregion
} }

View File

@ -35,6 +35,7 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
#region Commands #region Commands
public ICommand SaveCommand { get; private set; } public ICommand SaveCommand { get; private set; }
public ICommand EditCommand { get; private set; } public ICommand EditCommand { get; private set; }
public ICommand RensaCommand { get; private set; }
#endregion #endregion
#region Init Method #region Init Method
@ -43,6 +44,13 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
base.Init(); base.Init();
SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled); SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled);
EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0); EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
RensaCommand = new Command(async () => RensaAsync());
}
private async Task RensaAsync()
{
base.Rensa();
await Shell.Current.GoToAsync("..");
} }
#endregion #endregion

View File

@ -15,6 +15,7 @@ public static class MauiProgram
public static MauiApp CreateMauiApp() public static MauiApp CreateMauiApp()
{ {
var builder = MauiApp.CreateBuilder(); var builder = MauiApp.CreateBuilder();
builder builder
.UseMauiApp<App>() .UseMauiApp<App>()
.ConfigureFonts(fonts => .ConfigureFonts(fonts =>
@ -23,6 +24,8 @@ public static class MauiProgram
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
}); });
builder.Services.AddDbContext<DataContext>(options => builder.Services.AddDbContext<DataContext>(options =>
{ {
var MauiDataPath = FileSystem.Current.AppDataDirectory; var MauiDataPath = FileSystem.Current.AppDataDirectory;
@ -34,8 +37,6 @@ public static class MauiProgram
options.UseSqlite($"Data Source={dbPath}"); options.UseSqlite($"Data Source={dbPath}");
}); });
builder.Services.AddScoped<IRepository<Participant>, ParticipantRepository>(); builder.Services.AddScoped<IRepository<Participant>, ParticipantRepository>();
builder.Services.AddScoped<ParticipantViewModelCommands>(); builder.Services.AddScoped<ParticipantViewModelCommands>();
builder.Services.AddScoped<ParticipantListView>(); builder.Services.AddScoped<ParticipantListView>();
@ -49,6 +50,8 @@ public static class MauiProgram
builder.Services.AddScoped<IMethodSharingService<Participant>, MethodSharingService>(); builder.Services.AddScoped<IMethodSharingService<Participant>, MethodSharingService>();
builder.Services.AddScoped<ICombinedRepository, CombinedRepository>();
#if DEBUG #if DEBUG
builder.Logging.AddDebug(); builder.Logging.AddDebug();
#endif #endif

View File

@ -72,8 +72,8 @@
Text="{Binding LastNameFirstName}" /> Text="{Binding LastNameFirstName}" />
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Button Text="Edit" Style="{StaticResource HoverButtonBlueStyle}" CommandParameter="{Binding EditCommand}"/> <Button Text="Edit" Style="{StaticResource HoverButtonBlueStyle}" CommandParameter="{Binding EditCommand}"/>
<Button Style="{StaticResource HoverButtonRedStyle}" Text="Delete" /> <Button Style="{StaticResource HoverButtonRedStyle}" Text="Delete" />
</HorizontalStackLayout> </HorizontalStackLayout>
</VerticalStackLayout> </VerticalStackLayout>
</Border> </Border>

View File

@ -33,17 +33,17 @@
<Picker ItemsSource="{Binding ParticipantList}" <Picker ItemsSource="{Binding ParticipantList}"
ItemDisplayBinding="{Binding LastNameFirstName}" ItemDisplayBinding="{Binding LastNameFirstName}"
SelectedItem="{Binding SelectedItem}" SelectedItem="{Binding SelectedItem}"
Title="Välj deltagare"/> Title="Välj deltagare"/>
</Border> </Border>
<Border Stroke="Gold" StrokeThickness="2" BackgroundColor="LightCyan" > <Border Stroke="Gold" StrokeThickness="2" BackgroundColor="LightCyan" >
<CollectionView <CollectionView
ItemsSource="{Binding RoundElements}" ItemsSource="{Binding RoundElements}"
ItemsLayout="HorizontalList" ItemsLayout="HorizontalList"
SelectionMode="None"> SelectionMode="None">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:RoundBuilderElement"> <DataTemplate x:DataType="model:RoundBuilderElement">
<Border <Border
Padding="10" Padding="2"
Margin="5" Margin="5"
WidthRequest="150" WidthRequest="150"
HeightRequest="100" HeightRequest="100"
@ -71,25 +71,88 @@
<Setter Property="BackgroundColor" Value="LightCoral" /> <Setter Property="BackgroundColor" Value="LightCoral" />
</DataTrigger> </DataTrigger>
</Border.Triggers> </Border.Triggers>
<VerticalStackLayout> <Border Margin="1" Padding="2" StrokeThickness="3" >
<Label Text="------------------" FontAttributes="Bold" FontSize="12" TextColor="Black"/> <VerticalStackLayout>
<Label Text="{Binding ParticipantName}" FontAttributes="Bold" FontSize="12" TextColor="Black"/> <Label Text="{Binding ParticipantName}" FontAttributes="Bold" FontSize="14" TextColor="Black"/>
<Label Text="{Binding GameRoundStartDateString}" FontAttributes="Bold" FontSize="12" TextColor="Black"/> <Label Text="{Binding GameRoundStartDateString}" FontAttributes="Bold" FontSize="14" TextColor="Black"/>
<Label Text="{Binding StatusString}" FontSize="12" TextColor="DarkGray" /> <Label Text="{Binding StatusString}" FontSize="14" TextColor="White" />
<Label Text="------------------" FontAttributes="Bold" FontSize="12" TextColor="Black"/> </VerticalStackLayout>
</VerticalStackLayout> </Border>
</Border> </Border>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
</Border> </Border>
<Border
HorizontalOptions="End"
Padding="2"
Margin="5"
WidthRequest="150"
HeightRequest="100"
Stroke="LightGray"
StrokeThickness="1"
x:Name="RoundElementBorder"
BackgroundColor="BlanchedAlmond"
StrokeShape="RoundRectangle 10">
<VerticalStackLayout Spacing="5" Padding="4">
<Button Text="Spara omgång" WidthRequest="130"
Style="{StaticResource HoverButtonBlueStyle}"
Command="{Binding SaveCommand}" />
<Button Text="Rensa" WidthRequest="130"
Style="{StaticResource HoverButtonRedStyle}"
Command="{Binding RensaCommand}" />
</VerticalStackLayout>
</Border>
</HorizontalStackLayout> </HorizontalStackLayout>
</Border> </Border>
<Border Grid.Row="2" Stroke="Gold" BackgroundColor="Ivory" StrokeThickness="2" Padding="5"> <Border Grid.Row="2" Stroke="Gold" BackgroundColor="Ivory" StrokeThickness="2" Padding="5">
<Label Text="Här kommer en lista på alla spelrundor att visas" <CollectionView
FontAttributes="Bold" ItemsSource="{Binding GameRoundList}"
HorizontalOptions="Center" ItemsLayout="VerticalList"
VerticalOptions="Center"/> SelectionMode="Single">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:GameRound">
<Border
Padding="2"
Margin="5"
WidthRequest="150"
HeightRequest="100"
Stroke="LightGray"
StrokeThickness="1"
x:Name="RoundElementBorderList"
StrokeShape="RoundRectangle 10">
<!--BackgroundColor="{Binding Status, Converter={StaticResource StatusToColorConverter}}"-->
<!--<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>-->
<Border Margin="1" Padding="2" StrokeThickness="3" >
<VerticalStackLayout>
<Label Text="{Binding GameRoundId}" FontAttributes="Bold" FontSize="14" TextColor="Black"/>
<Label Text="{Binding GameRoundStartDateString}" FontAttributes="Bold" FontSize="14" TextColor="Black"/>
<Label Text="{Binding GameRoundFinished}" FontSize="14" TextColor="White" />
</VerticalStackLayout>
</Border>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Border> </Border>
</Grid> </Grid>
</Border> </Border>