Commit före flytt avStatusparameter från point till round
This commit is contained in:
@ -6,4 +6,5 @@ public interface IRepository<TEntity>
|
||||
Task<TEntity?> Get(int id);
|
||||
Task<int> Save(TEntity entity);
|
||||
bool Delete(TEntity entity);
|
||||
Task<bool> DeleteById(int Id);
|
||||
}
|
||||
|
||||
36
GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs
Normal file
36
GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs
Normal 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;
|
||||
|
||||
}
|
||||
}
|
||||
@ -25,7 +25,7 @@ public class GamePointRepository : IRepository<GamePoint>
|
||||
{
|
||||
var res = -1;
|
||||
if ((entity.GameRoundRegNr == 0)
|
||||
|| (entity.GameRegPoints == 0))
|
||||
&& (entity.GameRegPoints == 0))
|
||||
{
|
||||
return res; // Validation failed
|
||||
}
|
||||
@ -51,7 +51,7 @@ public class GamePointRepository : IRepository<GamePoint>
|
||||
try
|
||||
{
|
||||
_dataContext.GamePoints.Remove(entity);
|
||||
_dataContext.SaveChanges();
|
||||
_dataContext.SaveChangesAsync();
|
||||
res = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -62,6 +62,22 @@ public class GamePointRepository : IRepository<GamePoint>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,4 +58,24 @@ public class GameRoundRepository : IRepository<GameRound>
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -62,4 +62,23 @@ public class ParticipantRepository : IRepository<Participant>
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
|
||||
using GreadyPoang.EntityLayer;
|
||||
|
||||
namespace GreadyPoang.DataLayer;
|
||||
|
||||
public interface ICombinedRepository
|
||||
{
|
||||
IEnumerable<RoundBuilderElement> roundBuilderElements();
|
||||
}
|
||||
@ -13,7 +13,6 @@ public class GamePoint : EntityBase
|
||||
_gameDate = DateTime.Now;
|
||||
_gameRoundRegNr = 0;
|
||||
_gameRegPoints = 0;
|
||||
_pointStatus = GamePointStatus.New;
|
||||
}
|
||||
|
||||
private int _gamePointId;
|
||||
@ -22,7 +21,6 @@ public class GamePoint : EntityBase
|
||||
private DateTime _gameDate;
|
||||
private int _gameRoundRegNr;
|
||||
private int _gameRegPoints;
|
||||
private GamePointStatus _pointStatus;
|
||||
|
||||
[PrimaryKey]
|
||||
[AutoIncrement]
|
||||
@ -91,16 +89,6 @@ public class GamePoint : EntityBase
|
||||
}
|
||||
}
|
||||
|
||||
[Column("PointStatus")]
|
||||
public GamePointStatus PointStatus
|
||||
{
|
||||
get { return _pointStatus; }
|
||||
set
|
||||
{
|
||||
_pointStatus = value;
|
||||
RaisePropertyChanged(nameof(PointStatus));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -12,11 +12,13 @@ public class GameRound : EntityBase
|
||||
{
|
||||
_gameRoundId = 0;
|
||||
_gameRoundStartDate = DateTime.Now;
|
||||
_gameStatus = GamePointStatus.New;
|
||||
_gameRoundFinished = null;
|
||||
}
|
||||
|
||||
private int _gameRoundId;
|
||||
private DateTime _gameRoundStartDate;
|
||||
private GamePointStatus _gameStatus;
|
||||
private DateTime? _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]
|
||||
[AutoIncrement]
|
||||
[Column("GameRoundId")]
|
||||
@ -54,6 +68,10 @@ public class GameRound : EntityBase
|
||||
}
|
||||
}
|
||||
|
||||
public string GameRoundStartDateString
|
||||
{
|
||||
get { return _gameRoundStartDate.ToString("yyyy-MM-dd"); }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ public class RoundStartingViewModel : ViewModelBase
|
||||
ParticipantId = item.ParticipantId,
|
||||
GameRoundId = GameRoundObject?.GameRoundId ?? 0,
|
||||
GameDate = DateTime.Now,
|
||||
GameRoundRegNr = 0,
|
||||
GameRoundRegNr = -1,
|
||||
GameRegPoints = 0,
|
||||
PointStatus = GamePointStatus.New
|
||||
};
|
||||
@ -187,11 +187,22 @@ public class RoundStartingViewModel : ViewModelBase
|
||||
if (tmp)
|
||||
{
|
||||
GameRoundObject = new GameRound();
|
||||
RoundElements.Clear();
|
||||
this.Get();
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public void Rensa()
|
||||
{
|
||||
foreach (var element in RoundElements)
|
||||
{
|
||||
_pointsRepo.DeleteById(element.GamePointId);
|
||||
}
|
||||
_Repository?.DeleteById(GameRoundObject?.GameRoundId ?? 0);
|
||||
RoundElements.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
|
||||
#region Commands
|
||||
public ICommand SaveCommand { get; private set; }
|
||||
public ICommand EditCommand { get; private set; }
|
||||
public ICommand RensaCommand { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Init Method
|
||||
@ -43,6 +44,13 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
|
||||
base.Init();
|
||||
SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled);
|
||||
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
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ public static class MauiProgram
|
||||
public static MauiApp CreateMauiApp()
|
||||
{
|
||||
var builder = MauiApp.CreateBuilder();
|
||||
|
||||
builder
|
||||
.UseMauiApp<App>()
|
||||
.ConfigureFonts(fonts =>
|
||||
@ -23,6 +24,8 @@ public static class MauiProgram
|
||||
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
|
||||
});
|
||||
|
||||
|
||||
|
||||
builder.Services.AddDbContext<DataContext>(options =>
|
||||
{
|
||||
var MauiDataPath = FileSystem.Current.AppDataDirectory;
|
||||
@ -34,8 +37,6 @@ public static class MauiProgram
|
||||
options.UseSqlite($"Data Source={dbPath}");
|
||||
});
|
||||
|
||||
|
||||
|
||||
builder.Services.AddScoped<IRepository<Participant>, ParticipantRepository>();
|
||||
builder.Services.AddScoped<ParticipantViewModelCommands>();
|
||||
builder.Services.AddScoped<ParticipantListView>();
|
||||
@ -49,6 +50,8 @@ public static class MauiProgram
|
||||
|
||||
builder.Services.AddScoped<IMethodSharingService<Participant>, MethodSharingService>();
|
||||
|
||||
builder.Services.AddScoped<ICombinedRepository, CombinedRepository>();
|
||||
|
||||
#if DEBUG
|
||||
builder.Logging.AddDebug();
|
||||
#endif
|
||||
|
||||
@ -72,8 +72,8 @@
|
||||
Text="{Binding LastNameFirstName}" />
|
||||
</HorizontalStackLayout>
|
||||
<HorizontalStackLayout>
|
||||
<Button Text="Edit" Style="{StaticResource HoverButtonBlueStyle}" CommandParameter="{Binding EditCommand}"/>
|
||||
<Button Style="{StaticResource HoverButtonRedStyle}" Text="Delete" />
|
||||
<Button Text="Edit" Style="{StaticResource HoverButtonBlueStyle}" CommandParameter="{Binding EditCommand}"/>
|
||||
<Button Style="{StaticResource HoverButtonRedStyle}" Text="Delete" />
|
||||
</HorizontalStackLayout>
|
||||
</VerticalStackLayout>
|
||||
</Border>
|
||||
|
||||
@ -33,17 +33,17 @@
|
||||
<Picker ItemsSource="{Binding ParticipantList}"
|
||||
ItemDisplayBinding="{Binding LastNameFirstName}"
|
||||
SelectedItem="{Binding SelectedItem}"
|
||||
Title="Välj deltagare"/>
|
||||
Title="Välj deltagare"/>
|
||||
</Border>
|
||||
<Border Stroke="Gold" StrokeThickness="2" BackgroundColor="LightCyan" >
|
||||
<CollectionView
|
||||
<CollectionView
|
||||
ItemsSource="{Binding RoundElements}"
|
||||
ItemsLayout="HorizontalList"
|
||||
SelectionMode="None">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate x:DataType="model:RoundBuilderElement">
|
||||
<Border
|
||||
Padding="10"
|
||||
Padding="2"
|
||||
Margin="5"
|
||||
WidthRequest="150"
|
||||
HeightRequest="100"
|
||||
@ -71,25 +71,88 @@
|
||||
<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 Margin="1" Padding="2" StrokeThickness="3" >
|
||||
<VerticalStackLayout>
|
||||
<Label Text="{Binding ParticipantName}" FontAttributes="Bold" FontSize="14" TextColor="Black"/>
|
||||
<Label Text="{Binding GameRoundStartDateString}" FontAttributes="Bold" FontSize="14" TextColor="Black"/>
|
||||
<Label Text="{Binding StatusString}" FontSize="14" TextColor="White" />
|
||||
</VerticalStackLayout>
|
||||
</Border>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
</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>
|
||||
</Border>
|
||||
<Border Grid.Row="2" Stroke="Gold" BackgroundColor="Ivory" StrokeThickness="2" Padding="5">
|
||||
<Label Text="Här kommer en lista på alla spelrundor att visas"
|
||||
FontAttributes="Bold"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Center"/>
|
||||
<CollectionView
|
||||
ItemsSource="{Binding GameRoundList}"
|
||||
ItemsLayout="VerticalList"
|
||||
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>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
Reference in New Issue
Block a user