Exemple #1
0
        public async Task <IActionResult> Clarification(
            string op, AddClarificationModel model,
            [FromServices] IClarificationStore clars)
        {
            var(cid, teamid) = (Contest.ContestId, Team.TeamId);
            int repl = 0;

            if (op != "add" && !int.TryParse(op, out repl))
            {
                return(NotFound());
            }

            var replit = await clars.FindAsync(cid, repl);

            if (repl != 0 && replit == null)
            {
                ModelState.AddModelError("xys::replyto", "The clarification replied to is not found.");
            }

            if (string.IsNullOrWhiteSpace(model.Body))
            {
                ModelState.AddModelError("xys::empty", "No empty clarification");
            }

            var usage = ClarCategories.SingleOrDefault(cp => model.Type == cp.Item1);

            if (usage.Item1 == null)
            {
                ModelState.AddModelError("xys::error_cate", "The category specified is wrong.");
            }

            if (!ModelState.IsValid)
            {
                StatusMessage = string.Join('\n', ModelState.Values
                                            .SelectMany(m => m.Errors)
                                            .Select(e => e.ErrorMessage));
            }
            else
            {
                int id = await clars.SendAsync(
                    new Clarification
                {
                    Body         = model.Body,
                    SubmitTime   = DateTimeOffset.Now,
                    ContestId    = cid,
                    Sender       = teamid,
                    ResponseToId = model.ReplyTo,
                    ProblemId    = usage.Item3,
                    Category     = usage.Item2,
                });

                await HttpContext.AuditAsync("added", $"{id}");

                StatusMessage = "Clarification sent to the jury.";
            }

            return(RedirectToAction(nameof(Home)));
        }
        public async Task <IActionResult> Send(AddClarificationModel model)
        {
            // validate the model
            if (string.IsNullOrWhiteSpace(model.Body))
            {
                ModelState.AddModelError("xys::clar_empty", "Clarification body cannot be empty.");
            }

            // reply clar
            Clarification replyTo = null;

            if (model.ReplyTo.HasValue)
            {
                replyTo = await Context.FindClarificationAsync(model.ReplyTo.Value);

                if (replyTo == null)
                {
                    ModelState.AddModelError("xys::clar_not_found", "The clarification replied to not found.");
                }
            }

            // determine category
            var probs = await Context.ListProblemsAsync();

            var usage = probs.ClarificationCategories.FirstOrDefault(cp => model.Type == cp.Item1);

            if (usage.Item1 == null)
            {
                ModelState.AddModelError("xys::error_cate", "The category specified is wrong.");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var clar = await Context.ClarifyAsync(
                replyTo : replyTo,
                clar : new Clarification
            {
                Body         = model.Body,
                SubmitTime   = DateTimeOffset.Now,
                ContestId    = Contest.Id,
                JuryMember   = User.GetUserName(),
                Sender       = null,
                ResponseToId = model.ReplyTo,
                Recipient    = model.TeamTo == 0 ? default(int?) : model.TeamTo,
                ProblemId    = usage.Item3,
                Answered     = true,
                Category     = usage.Item2,
            });

            await HttpContext.AuditAsync("added", $"{clar.Id}");

            StatusMessage = $"Clarification {clar.Id} has been sent.";
            return(RedirectToAction(nameof(Detail), new { clarid = clar.Id }));
        }
Exemple #3
0
        public IActionResult Clarification(string op, AddClarificationModel model)
        {
            var(cid, teamid) = (Contest.ContestId, Team.TeamId);
            var probs = Service.Problems;
            int repl  = 0;

            if (op != "add" && !int.TryParse(op, out repl))
            {
                return(BadRequest());
            }
            if (Service.GetClarification(repl, false) == null)
            {
                return(NotFound());
            }

            string SolveAndAdd()
            {
                if (string.IsNullOrWhiteSpace(model.Body))
                {
                    return("Error sending empty clarification.");
                }

                var newClar = new Clarification
                {
                    Body         = model.Body,
                    SubmitTime   = DateTimeOffset.Now,
                    ContestId    = cid,
                    JuryMember   = null,
                    Sender       = teamid,
                    ResponseToId = op == "add" ? default(int?) : repl,
                    Recipient    = null,
                    ProblemId    = null,
                };

                if (model.Type == "general")
                {
                    newClar.Category = ClarificationCategory.General;
                }
                else if (model.Type == "tech")
                {
                    newClar.Category = ClarificationCategory.Technical;
                }
                else if (!model.Type.StartsWith("prob-"))
                {
                    return("Error detecting category.");
                }
                else
                {
                    var prob = probs.FirstOrDefault(p => "prob-" + p.ShortName == model.Type);
                    if (prob is null)
                    {
                        return("Error detecting problem.");
                    }
                    newClar.ProblemId = prob.ProblemId;
                    newClar.Category  = ClarificationCategory.Problem;
                }

                Service.SendClarification(newClar);
                return("Clarification sent to the jury");
            }

            DisplayMessage = SolveAndAdd();
            return(RedirectToAction(nameof(Home), new { cid }));
        }
Exemple #4
0
 public Task <IActionResult> ClarificationReply(int?clarid, AddClarificationModel model)
 => CommonActions.ClarificationReply(this, clarid, model, nameof(Home));
Exemple #5
0
        public IActionResult Send(AddClarificationModel model)
        {
            var cid   = Contest.ContestId;
            var probs = Service.Problems;

            string SolveAndAdd()
            {
                if (string.IsNullOrWhiteSpace(model.Body))
                {
                    return("Error sending empty clarification.");
                }

                var newClar = new Clarification
                {
                    Body         = model.Body,
                    SubmitTime   = DateTimeOffset.Now,
                    ContestId    = cid,
                    JuryMember   = UserManager.GetUserName(User),
                    Sender       = null,
                    ResponseToId = model.ReplyTo,
                    Recipient    = model.TeamTo == 0 ? default(int?) : model.TeamTo,
                    ProblemId    = null,
                    Answered     = true
                };

                if (model.ReplyTo.HasValue)
                {
                    var respTo = Service.GetClarification(model.ReplyTo.Value, true);
                    if (respTo == null)
                    {
                        return("Error finding clarification replying to");
                    }
                    respTo.Answered = true;
                    Service.UpdateClarificationBeforeInsertOne(respTo);
                }

                if (model.Type == "general")
                {
                    newClar.Category = ClarificationCategory.General;
                }
                else if (model.Type == "tech")
                {
                    newClar.Category = ClarificationCategory.Technical;
                }
                else if (!model.Type.StartsWith("prob-"))
                {
                    return("Error detecting category.");
                }
                else
                {
                    var prob = probs.FirstOrDefault(p => "prob-" + p.ShortName == model.Type);
                    if (prob is null)
                    {
                        return("Error detecting problem.");
                    }
                    newClar.ProblemId = prob.ProblemId;
                    newClar.Category  = ClarificationCategory.Problem;
                }

                Service.SendClarification(newClar);
                return("Clarification sent to common");
            }

            DisplayMessage = SolveAndAdd();
            return(RedirectToAction(nameof(Clarifications), new { cid }));
        }