Example #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)));
        }
Example #2
0
        public async Task <IActionResult> Send(
            int cid, 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 Store.FindAsync(cid, model.ReplyTo.Value);

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

            // determine category
            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)
            {
                return(View(model));
            }
            var clarId = await Store.SendAsync(
                replyTo : replyTo,
                clar : new Clarification
            {
                Body         = model.Body,
                SubmitTime   = DateTimeOffset.Now,
                ContestId    = cid,
                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", $"{clarId}");

            StatusMessage = $"Clarification {clarId} has been sent.";
            return(RedirectToAction(nameof(Detail), new { clarid = clarId }));
        }