private void UpdateDuelsStatistics() { var category = "Wednesday prize"; var applicantsForPrize = 3; var participants = _duels.Where(d => d.StartTime.Date == DateTime.Today).GroupBy(d => d.Winner) .OrderByDescending(d => d.Count()).Select(d => new ParticipantDto { Email = d.First().Winner, Name = _users.FirstOrDefault(u => u.Email.Equals(d.First().Winner))?.FullName, Picture = _users.FirstOrDefault(u => u.Email.Equals(d.First().Winner))?.Picture, TodaysBalance = d.Count() }).ToList(); var participantsNeeded = applicantsForPrize + _prizes.Count(p => p.Category.Equals(category)); participants = participants.Take(participantsNeeded).ToList(); if (participantsNeeded > participants.Count) { while (participantsNeeded > participants.Count) { participants.Add(new ParticipantDto()); } } var i = 0; var prize = _prizes.FirstOrDefault(p => p.Category.Equals(category)); if (prize == null) { _duelsStatistics = new PrizeAndApplicantDto(); } _duelsStatistics = new PrizeAndApplicantDto { Id = prize.Id, Name = prize.Name, Picture = prize.Picture, Price = prize.Price, Quantity = prize.Quantity - _purchases.Count(np => np.PrizeId == prize.Id), Category = prize.Category, Applicants = participants.Skip(i++).Take(applicantsForPrize) }; }
private void UpdateWeekPrizes() { _weeksPrize = UpdatePrizesByCategory("Week prize"); }
private void UpdateTodayPrizes() { var weekday = DateTime.Today.ToString("dddd"); _todaysPrize = UpdatePrizesByCategory($"{weekday} prize"); }