/// <summary> /// Merges the specified event summary /// </summary> /// <param name="eventSummary">The event summary</param> /// <param name="culture">The culture</param> private void ActualMerge(DrawDTO eventSummary, CultureInfo culture) { base.Merge(eventSummary, culture, false); if (eventSummary.Lottery != null) { _lotteryId = eventSummary.Lottery.Id; } _drawStatus = eventSummary.Status; _resultsChronological = eventSummary.ResultsChronological; if (eventSummary.Results != null && eventSummary.Results.Any()) { if (_results == null) { _results = new List <DrawResultCI>(eventSummary.Results.Select(s => new DrawResultCI(s, culture))); } else { MergeDrawResults(eventSummary.Results, culture); } } if (eventSummary.DisplayId != null) { _displayId = eventSummary.DisplayId; } }
public IActionResult Put(DrawDTO dto) { var input = _mapper.FromDTO(dto); var result = _drawService.Update(input); return(Ok(result)); }
public IActionResult Post(DrawDTO dto) { var input = _mapper.FromDTO(dto); var result = _drawService.Create(input); return(Ok(_mapper.ToDTO(result))); }
private async Task <bool> CheckForDuplicateNumbersAsync(DrawDTO drawing) { var numbers = await Task.Run(() => drawing.DrawnNumbers.Split(',').Select(Int32.Parse).ToList()); if (numbers.Count != numbers.Distinct().Count()) { return(false); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="DrawCI"/> class /// </summary> /// <param name="eventSummary">The event summary</param> /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to obtain summary and fixture</param> /// <param name="semaphorePool">The semaphore pool</param> /// <param name="currentCulture">The current culture</param> /// <param name="defaultCulture">The default culture</param> /// <param name="fixtureTimestampCache">A <see cref="MemoryCache"/> used to cache the sport events fixture timestamps</param> public DrawCI(DrawDTO eventSummary, IDataRouterManager dataRouterManager, ISemaphorePool semaphorePool, CultureInfo currentCulture, CultureInfo defaultCulture, MemoryCache fixtureTimestampCache) : base(eventSummary, dataRouterManager, semaphorePool, currentCulture, defaultCulture, fixtureTimestampCache) { Guard.Argument(eventSummary, nameof(eventSummary)).NotNull(); Guard.Argument(currentCulture, nameof(currentCulture)).NotNull(); Merge(eventSummary, currentCulture, true); }
/// <summary> /// Initializes a new instance of the <see cref="DrawCI"/> class /// </summary> /// <param name="eventSummary">The event summary</param> /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to obtain summary and fixture</param> /// <param name="semaphorePool">The semaphore pool</param> /// <param name="currentCulture">The current culture</param> /// <param name="defaultCulture">The default culture</param> /// <param name="fixtureTimestampCache">A <see cref="ObjectCache"/> used to cache the sport events fixture timestamps</param> public DrawCI(DrawDTO eventSummary, IDataRouterManager dataRouterManager, ISemaphorePool semaphorePool, CultureInfo currentCulture, CultureInfo defaultCulture, ObjectCache fixtureTimestampCache) : base(eventSummary, dataRouterManager, semaphorePool, currentCulture, defaultCulture, fixtureTimestampCache) { Contract.Requires(eventSummary != null); Contract.Requires(currentCulture != null); Merge(eventSummary, currentCulture, true); }
/// <summary> /// Merges the specified event summary /// </summary> /// <param name="eventSummary">The event summary</param> /// <param name="culture">The culture</param> /// <param name="useLock">Should the lock mechanism be used during merge</param> public void Merge(DrawDTO eventSummary, CultureInfo culture, bool useLock) { if (useLock) { lock (MergeLock) { ActualMerge(eventSummary, culture); } } else { ActualMerge(eventSummary, culture); } }
public async Task <ActionResult> Draw([FromBody] DrawDTO draw) { if (ModelState.IsValid) { bool result = await _drawService.CreateDrawAsync(draw); if (result) { return(Ok("Drawn lotto numbers has been published.")); } } return(BadRequest("Either the numbers are already drawn, or something went wrong along the way.")); }
public Draw FromDTO(DrawDTO dto) { var draw = new Draw() { Name = dto.Name, Id = dto.Id, TournamentId = dto.TournamentId, DrawType = DrawTypeFromDTO(dto.DrawTypeDTO), Points = dto.Points, Games = dto.Games, TieBreaks = dto.TieBreaks }; return(draw); }
private async Task <bool> RegisterDrawCheckForWinnersAsync(DrawDTO drawing, Session activeSession) { drawing.SessionId = activeSession.SessionId; Draw draw = _mapper.Map <Draw>(drawing); activeSession.DrawId = draw.DrawId; int result1 = await Task.Run(() => _sessionRepository.Update(activeSession)); int result2 = await Task.Run(() => _drawRepository.Add(draw)); if (result1 != -1 && result2 != -1) { await _winnerService.CheckForWinnersAsync(); return(true); } return(false); }
public async Task <bool> CreateDrawAsync(DrawDTO drawing) { Session activeSession = await ActiveSessionAsync(); if (activeSession != null) { bool check = await CheckForDuplicateNumbersAsync(drawing); if (check == true) { bool result = await RegisterDrawCheckForWinnersAsync(drawing, activeSession); if (result) { return(true); } } } return(false); }
public DrawDTO ToDTO(Draw draw) { var dto = new DrawDTO() { Name = draw.Name, Id = draw.Id, TournamentId = draw.TournamentId, DrawTypeDTO = DrawTypeToDTO(draw.DrawType), Points = draw.Points, Games = draw.Games, TieBreaks = draw.TieBreaks, MatchIds = new List <int>() }; if (draw.Matches != null && draw.Matches.ToArray().Length > 0) { foreach (var match in draw.Matches) { dto.MatchIds.Add(match.Id); } } return(dto); }
public async Task <DrawDTO> CreateOrUpdateMatchesForTournament(DrawSize drawSize, int tournamentId, List <MatchDTO> matchDTOs = null) { var matches = await _dbContext.Matches.Where(m => m.TournamentId == tournamentId).ToListAsync(); var drawDto = new DrawDTO(); if (matches == null || matches.Count == 0) { var startingRound = TournamentRound.round1; var matchesCount = 0; var draw = InitializeDraw(drawSize, startingRound, matchesCount); matches = GetMatchesForNewDraw(draw.InitialRound, draw.MatchesCount, tournamentId); //// reverse matches because when not In DB, stored first match is final(round6), then round5, round4.. //matches.Reverse(); var matchesEntries = new List <MatchEntry>(); using (var transaction = _dbContext.Database.BeginTransaction()) { var bulkConfig = new BulkConfig { PreserveInsertOrder = true, SetOutputIdentity = true }; InsertOrdered(matches, m => m.Id); //_dbContext.BulkInsert(matches, bulkConfig); int matchIndex = 0, round2index = 0; //// checkin matches id //matches.Reverse(); foreach (var match in matches) { if (match.Round != draw.InitialRound) { foreach (var entry in match.MatchEntries) { entry.MatchId = match.Id; entry.ParentMatchId = matches[round2index].Id; round2index++; } } else { foreach (var entry in match.MatchEntries) { entry.MatchId = match.Id; } } matchesEntries.AddRange(match.MatchEntries); matchIndex++; } _dbContext.BulkInsert(matchesEntries, bulkConfig); transaction.Commit(); } } else { // update list MatchDTO, implementovat FE a tak vyskusat // TODO - nejaky check na parent a winner var matchesDB = Mapper.Map <List <MatchDTO>, List <Match> >(matchDTOs); var matchesEntries = matchesDB.SelectMany(m => m.MatchEntries).ToList(); CheckMatches(matchesDB); await _dbContext.BulkUpdateAsync(matchesDB); await _dbContext.BulkUpdateAsync(matchesEntries); } await _dbContext.SaveChangesAsync(); //// BUG on bulk - need to reverse inserted data //ReverseMatchesIds(matches); matchDTOs = Mapper.Map <List <Match>, List <MatchDTO> >(matches); var roundMatches = matchDTOs.GroupBy(m => m.Round).Select(g => new RoundMatchDTO { Round = (int)g.Key, Matches = g.ToList() }); drawDto.RoundMatches = roundMatches.ToList(); return(drawDto); }