Example #1
0
        private IEnumerable <StatusButtonViewModel> CreateStatusButtons(ContestState contestStatus)
        {
            switch (contestStatus)
            {
            case ContestState.NotStarted:
                return(new[]
                {
                    new StatusButtonViewModel {
                        Label = "Start", NewState = ContestState.InProgress
                    }
                });

            case ContestState.InProgress:
                return(new[]
                {
                    new StatusButtonViewModel {
                        Label = "Complete", NewState = ContestState.Completed
                    },
                    new StatusButtonViewModel {
                        Label = "Cancel", NewState = ContestState.NotStarted
                    }
                });

            case ContestState.Completed:
                return(new[]
                {
                    new StatusButtonViewModel {
                        Label = "Restart", NewState = ContestState.InProgress
                    }
                });

            default: throw new InvalidEnumArgumentException(contestStatus.ToString());
            }
        }
Example #2
0
        public async Task <IActionResult> OnPostChangeStatusAsync(ContestState newStatus)
        {
            var contest = await _context.Contests.FindAsync(ContestId);

            contest.Status = newStatus;
            await _context.SaveChangesAsync();

            if (newStatus == ContestState.Completed)
            {
                var contestEndCommand = ContestEndCommand.Create(contest.Id);
                await _contestEndCommandHandler.HandleAsync(contestEndCommand);
            }

            return(RedirectToPage(ContestId));
        }
        public Task <IdentityResult> CreateContestAsync(Contest contest)
        {
            return(Task <IdentityResult> .Factory.StartNew(() =>
            {
                var state = new ContestState {
                    ContestStateId = 1, ContestStateName = ContestStates.Awaiting
                };
                var listLangs = new List <ProgrammingLanguage>();

                foreach (ContestTask contestTask in contest.Tasks)
                {
                    foreach (ProgrammingLanguage language in contestTask.Languages)
                    {
                        if (listLangs.Find(x => x.LanguageId == language.LanguageId) == null)
                        {
                            listLangs.Add(language);
                        }
                    }
                }

                using (PortalContext context = _getContext())
                {
                    context.Set <ContestState>().Attach(state);
                    contest.ContestState = state;

                    foreach (ContestTask contestTask in contest.Tasks)
                    {
                        contestTask.Contest = contest;
                        for (int index = 0; index < contestTask.Languages.Count; index++)
                        {
                            contestTask.Languages[index] =
                                listLangs.Find(x => x.LanguageId.Equals(contestTask.Languages[index].LanguageId));
                            context.Entry(contestTask.Languages[index]).State = EntityState.Unchanged;
                        }
                    }
                    context.Contests.Add(contest);
                    try
                    {
                        context.SaveChanges();
                        return IdentityResult.Success;
                    }
                    catch (Exception e)
                    {
                        return IdentityResult.Failed(new[] { e.ToString() });
                    }
                }
            }));
        }
Example #4
0
 public static string ToString(this ContestState state, DateTimeOffset?start, TimeSpan?end)
 {
     if (state == ContestState.Frozen)
     {
         state = ContestState.Started;
     }
     return(state switch
     {
         ContestState.NotScheduled => "scheduling",
         ContestState.Finalized => "final standings",
         ContestState.Ended => "contest over, waiting for results",
         ContestState.Started when(end?.TotalDays ?? 0) < 1 => $"starts: {start:HH:mm} - ends: {start + end:HH:mm}",
         ContestState.Started => $"{end?.Days} days, {end?.TotalHours - (end?.Days * 24)} hours",
         ContestState.ScheduledToStart when start !.Value.Date < DateTimeOffset.Now => $"scheduled to start on {start:HH:mm}",
         ContestState.ScheduledToStart => string.Format(EnglishCulture, "scheduled to start on {0:ddd, dd MMM yyyy HH:mm:ss} CST", start),
         _ => "unknown",
     });
Example #5
0
        protected override async Task WriteLastStateAsync(ContestState now, ContestState lastState)
        {
            await base.WriteLastStateAsync(now, lastState);

            Expire("State");
        }
Example #6
0
 public virtual Task Update(int cid, Contest contest, ContestState state) => Task.CompletedTask;