public static async Task <IActionResult> ClarificationView <T>( this ContestControllerBase <T> that, int clarid, bool needMore = true) where T : class, ICompeteContext { var toSee = await that.Context.FindClarificationAsync(clarid); var clars = Enumerable.Empty <Clarification>(); if (toSee?.CheckPermission(that.Contest.Team.TeamId) ?? true) { clars = clars.Append(toSee); if (needMore && toSee.ResponseToId.HasValue) { int respid = toSee.ResponseToId.Value; var toSee2 = await that.Context.FindClarificationAsync(respid); if (toSee2 != null) { clars = clars.Prepend(toSee2); } } } if (!clars.Any()) { return(that.NotFound()); } that.ViewData["TeamName"] = that.Contest.Team.TeamName; return(that.Window(clars)); }
public static async Task <IActionResult> PostRegister <T>( this ContestControllerBase <T> that, IRegisterProvider provider, string homePage, string registerPage = "Register") where T : class, IContestContext { if (that.Contest.Team != null) { that.StatusMessage = "Already registered"; return(that.RedirectToAction(homePage)); } var context = that.CreateRegisterProviderContext(); if (provider == null || provider.JuryOrContestant || !await provider.IsAvailableAsync(context)) { return(that.NotFound()); } var model = await provider.CreateInputModelAsync(context); await provider.ReadAsync(model, that); await provider.ValidateAsync(context, model, that.ModelState); if (that.ModelState.IsValid) { var output = await provider.ExecuteAsync(context, model); if (output is StatusMessageModel status) { if (status.Succeeded) { await that.HttpContext.AuditAsync("created", status.TeamId?.ToString(), "via " + provider.Name); that.StatusMessage = status.Content; return(that.RedirectToAction(homePage)); } else { that.StatusMessage = "Error " + status.Content; return(that.RedirectToAction(registerPage)); } } else { throw new System.NotImplementedException(); } } that.StatusMessage = "Error " + that.ModelState.GetErrorStrings(); return(that.RedirectToAction(registerPage)); }
public static IActionResult GetPrint <T>( this ContestControllerBase <T> that) where T : class, IContestContext { if (!that.Contest.Settings.PrintingAvailable) { return(that.NotFound()); } return(that.View("Print", new Models.AddPrintModel())); }
public static async Task <IActionResult> PostPrint <T>( this ContestControllerBase <T> that, Models.AddPrintModel model) where T : class, IContestContext { if (!that.Contest.Settings.PrintingAvailable) { return(that.NotFound()); } using var stream = model.SourceFile.OpenReadStream(); var bytes = new byte[model.SourceFile.Length]; for (int i = 0; i < bytes.Length;) { i += await stream.ReadAsync(bytes, i, bytes.Length - i); } var Printings = that.HttpContext.RequestServices.GetRequiredService <IPrintingService>(); var p = await Printings.CreateAsync(new Printing { ContestId = that.Contest.Id, LanguageId = model.Language ?? "plain", FileName = System.IO.Path.GetFileName(model.SourceFile.FileName), Time = DateTimeOffset.Now, UserId = int.Parse(that.User.GetUserId()), SourceCode = bytes, }); await that.HttpContext.AuditAsync( AuditlogType.Printing, that.Contest.Id, that.User.GetUserName(), "added", $"{p.Id}", $"from {that.HttpContext.Connection.RemoteIpAddress}"); that.StatusMessage = "File has been printed. Please wait."; return(that.RedirectToAction("Home")); }