Sparar poäng men visar inte
This commit is contained in:
@ -71,6 +71,33 @@ public class CombinedRepository : ICombinedRepository
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<RoundBuilderElement> roundBuilderElementsDbById(int GameId)
|
||||
{
|
||||
var result = _context.RoundBuilderElements
|
||||
.FromSqlRaw($@"
|
||||
SELECT
|
||||
gp.GamePointId,
|
||||
gp.GameRoundId,
|
||||
gp.GameRoundRegNr,
|
||||
gp.GameRegPoints,
|
||||
gr.GameRoundStartDate,
|
||||
gr.GameStatus AS Status,
|
||||
p.ParticipantId,
|
||||
(p.LastName || ' ' || p.FirstName) AS ParticipantName
|
||||
FROM GamePoints gp
|
||||
INNER JOIN (
|
||||
SELECT ParticipantId, GameRoundId, MAX(GamePointId) AS MaxGamePointId
|
||||
FROM GamePoints
|
||||
GROUP BY ParticipantId, GameRoundId
|
||||
) latest ON gp.GamePointId = latest.MaxGamePointId
|
||||
INNER JOIN GameRounds gr ON gp.GameRoundId = gr.GameRoundId
|
||||
INNER JOIN Participants p ON gp.ParticipantId = p.ParticipantId
|
||||
WHERE gp.GameRoundId = {GameId.ToString()}
|
||||
ORDER BY gr.GameRoundStartDate DESC, p.LastName, p.FirstName, gp.GameRoundRegNr
|
||||
")
|
||||
.ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<RoundBuilderElement> roundBuilderElementsTotal()
|
||||
{
|
||||
|
||||
@ -7,6 +7,7 @@ public interface ICombinedRepository
|
||||
{
|
||||
IEnumerable<RoundBuilderElement> roundBuilderElements();
|
||||
IEnumerable<RoundBuilderElement> roundBuilderElementsDb();
|
||||
IEnumerable<RoundBuilderElement> roundBuilderElementsDbById(int GameId);
|
||||
IEnumerable<RoundBuilderElement> roundBuilderElementsTotal();
|
||||
IEnumerable<RoundBuilderElement> roundBuilderElementsTotalById(int roundId);
|
||||
}
|
||||
@ -80,11 +80,11 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
|
||||
public ObservableCollection<RoundBuilderElement> Get()
|
||||
{
|
||||
BuilderObject.ParticipantName = _objectMessage.CurrentGroup.Elements[0].ParticipantName;
|
||||
BuilderObject.GameRoundId = _objectMessage.CurrentGroup.GameRoundId;
|
||||
|
||||
|
||||
if (_objectMessage.CurrentGroup != null)
|
||||
{
|
||||
//CurrentGroup är satt från RoundStarting ViewModel
|
||||
Debug.WriteLine($"Chosen round: {_objectMessage.CurrentGroup.GameRoundId}");
|
||||
if (RoundElements.Count > 0)
|
||||
{
|
||||
@ -94,12 +94,65 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
{
|
||||
_roundElements.Add(item);
|
||||
}
|
||||
|
||||
var nxt = nextPlayerElement();
|
||||
BuilderObject.ParticipantName = _objectMessage.CurrentGroup.Elements[nxt].ParticipantName;
|
||||
BuilderObject.GameRoundId = _objectMessage.CurrentGroup.GameRoundId;
|
||||
BuilderObject.ParticipantId = _objectMessage.CurrentGroup.Elements[nxt].ParticipantId;
|
||||
|
||||
var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId);
|
||||
FillupResultTable(localElements);
|
||||
}
|
||||
return RoundElements;
|
||||
}
|
||||
|
||||
|
||||
public void StoreAndHandlePoints()
|
||||
{
|
||||
var regNr = RoundElements.Count > 0 ? RoundElements.Max(e => e.GameRoundRegNr) + 1 : 1;
|
||||
var points = BuilderObject.GameRegPoints;
|
||||
var newPoint = new GamePoint
|
||||
{
|
||||
ParticipantId = BuilderObject.ParticipantId,
|
||||
GameRoundId = BuilderObject.GameRoundId,
|
||||
GameDate = DateTime.Now,
|
||||
GameRoundRegNr = regNr,
|
||||
GameRegPoints = points
|
||||
};
|
||||
var pointId = _pointsRepo?.Save(newPoint).GetAwaiter().GetResult();
|
||||
|
||||
// Uppdatera listan med element
|
||||
var tmpElements = _combined.roundBuilderElementsDbById(BuilderObject.GameRoundId);
|
||||
RoundElements.Clear();
|
||||
foreach (var item in tmpElements)
|
||||
{
|
||||
RoundElements.Add(item);
|
||||
}
|
||||
// Uppdatera spelaren som skall spela nästa
|
||||
var nxt = nextPlayerElement();
|
||||
BuilderObject.ParticipantName = RoundElements[nxt].ParticipantName;
|
||||
BuilderObject.ParticipantId = RoundElements[nxt].ParticipantId;
|
||||
BuilderObject.GameRoundId = RoundElements[0].GameRoundId;
|
||||
|
||||
var localElements = _combined.roundBuilderElementsTotalById(BuilderObject.GameRoundId);
|
||||
FillupResultTable(localElements);
|
||||
|
||||
}
|
||||
|
||||
private int nextPlayerElement()
|
||||
{
|
||||
for (int i = 0; i < RoundElements.Count; i++)
|
||||
{
|
||||
if (RoundElements[i].GameRoundRegNr == -1 ||
|
||||
(i > 0 && (RoundElements[i - 1].GameRoundRegNr > RoundElements[i].GameRoundRegNr)) ||
|
||||
(i == 0 && RoundElements[i].GameRoundRegNr < RoundElements[RoundElements.Count - 1].GameRoundRegNr))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void FillupResultTable(IEnumerable<RoundBuilderElement> elements)
|
||||
{
|
||||
if (_playerColumns != null)
|
||||
|
||||
@ -33,14 +33,14 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
|
||||
public ICommand RensaCommand { get; private set; }
|
||||
public ICommand ElementTappedCommand { get; private set; }
|
||||
public ICommand ParticipantTappedCommand { get; private set; }
|
||||
public ICommand StoreAndHandlePontsCommand { get; private set; }
|
||||
public ICommand StoreAndHandlePointsCommand { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
StoreAndHandlePontsCommand = new Command(async () => StoreAndHandle());
|
||||
StoreAndHandlePointsCommand = new Command(async () => StoreAndHandleAsync());
|
||||
//EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
|
||||
//RensaCommand = new Command(async () => RensaAsync());
|
||||
//ParticipantTappedCommand = new Command<RoundBuilderElement>(async (selectedParticipant) => SelectNewlyAddedParticipant(selectedParticipant));
|
||||
@ -48,8 +48,9 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
|
||||
|
||||
}
|
||||
|
||||
private void StoreAndHandle()
|
||||
private async Task StoreAndHandleAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
base.StoreAndHandlePoints();
|
||||
await Shell.Current.GoToAsync("..");
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +94,9 @@
|
||||
</Entry.Behaviors>
|
||||
</Entry>
|
||||
</Grid>
|
||||
<Button Text="Register Points" Style="{StaticResource HoverButtonRedStyle}" CommandParameter="{Binding StoreAndHandlePontsCommand}"/>
|
||||
<Button Text="Register Points"
|
||||
Style="{StaticResource HoverButtonRedStyle}"
|
||||
Command="{Binding StoreAndHandlePointsCommand}"/>
|
||||
</HorizontalStackLayout>
|
||||
</Border>
|
||||
<ScrollView Grid.Row="4">
|
||||
|
||||
Reference in New Issue
Block a user