mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
restart matches on certain score
This commit is contained in:
@@ -35,8 +35,14 @@ namespace LiveGameFeed.Controllers
|
|||||||
public async void Put(int id, [FromBody]MatchScore score)
|
public async void Put(int id, [FromBody]MatchScore score)
|
||||||
{
|
{
|
||||||
Match _match = _matchRepository.GetSingle(id);
|
Match _match = _matchRepository.GetSingle(id);
|
||||||
|
if (score.HostScore == 0 && score.GuestScore == 0)
|
||||||
|
{
|
||||||
|
_match.Feeds.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
_match.HostScore = score.HostScore;
|
_match.HostScore = score.HostScore;
|
||||||
_match.GuestScore = score.GuestScore;
|
_match.GuestScore = score.GuestScore;
|
||||||
|
|
||||||
_matchRepository.Commit();
|
_matchRepository.Commit();
|
||||||
|
|
||||||
MatchViewModel _matchVM = Mapper.Map<Match, MatchViewModel>(_match);
|
MatchViewModel _matchVM = Mapper.Map<Match, MatchViewModel>(_match);
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace LiveGameFeed.Core
|
|||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
bool updateHost = r.Next(0, 2) == 1;
|
bool updateHost = r.Next(0, 2) == 1;
|
||||||
int points = r.Next(2, 4);
|
int points = r.Next(2, 4);
|
||||||
|
bool _matchEnded = false;
|
||||||
|
|
||||||
if (updateHost)
|
if (updateHost)
|
||||||
match.HostScore += points;
|
match.HostScore += points;
|
||||||
@@ -46,6 +47,12 @@ namespace LiveGameFeed.Core
|
|||||||
GuestScore = match.GuestScore
|
GuestScore = match.GuestScore
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (score.HostScore > 80 || score.GuestScore > 76)
|
||||||
|
{
|
||||||
|
score.HostScore = 0;
|
||||||
|
score.GuestScore = 0;
|
||||||
|
_matchEnded = true;
|
||||||
|
}
|
||||||
// Update Score for all clients
|
// Update Score for all clients
|
||||||
using (var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
@@ -54,10 +61,13 @@ namespace LiveGameFeed.Core
|
|||||||
|
|
||||||
// Update Feed for subscribed only clients
|
// Update Feed for subscribed only clients
|
||||||
|
|
||||||
|
|
||||||
FeedViewModel _feed = new FeedViewModel()
|
FeedViewModel _feed = new FeedViewModel()
|
||||||
{
|
{
|
||||||
MatchId = match.Id,
|
MatchId = match.Id,
|
||||||
Description = points + " points for " + (updateHost == true ? match.Host : match.Guest) + "!",
|
Description = _matchEnded == false ?
|
||||||
|
(points + " points for " + (updateHost == true ? match.Host : match.Guest) + "!") :
|
||||||
|
"Match started",
|
||||||
CreatedAt = DateTime.Now
|
CreatedAt = DateTime.Now
|
||||||
};
|
};
|
||||||
using (var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ export class HomeComponent implements OnInit {
|
|||||||
if (self.matches[i].Id === match.Id) {
|
if (self.matches[i].Id === match.Id) {
|
||||||
self.matches[i].HostScore = match.HostScore;
|
self.matches[i].HostScore = match.HostScore;
|
||||||
self.matches[i].GuestScore = match.GuestScore;
|
self.matches[i].GuestScore = match.GuestScore;
|
||||||
|
|
||||||
|
if(match.HostScore === 0 && match.GuestScore === 0)
|
||||||
|
self.matches[i].Feeds = new Array<Feed>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user