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 })); }
public ActionResult CreateClarification(int id, string subject, string text) { var contest = session.Get <Contest>(id); var clarification = new Clarification { SentAt = clock.CurrentTime, Author = userSession.CurrentUser, Contest = contest, Text = text, Subject = subject }; session.Save(clarification); return(MessageSentSuccessfully()); }
public virtual async Task <Clarification> ClarifyAsync(Clarification clar, Clarification?replyTo) { var cl = Db.Clarifications.Add(clar); if (replyTo != null) { replyTo.Answered = true; Db.Clarifications.Update(replyTo); } await Db.SaveChangesAsync(); await Mediator.Publish(new Events.ClarificationCreateEvent(this, clar)); return(cl.Entity); }
public int SendClarification(Clarification clar) { var entity = DbContext.Clarifications.Add(clar); DbContext.SaveChanges(); DbContext.AuditLogs.Add(new AuditLog { ContestId = ContestId, Resolved = true, Time = clar.SubmitTime, UserName = GetUserName(), Comment = "added", EntityId = entity.Entity.ClarificationId, }); DbContext.SaveChanges(); return(entity.Entity.ClarificationId); }
public ActionResult Edit(int id, FormCollection collection) { try { string name = collection.Get("Name"); Clarification clarification = new Clarification() { ID = id, Name = name }; IRepository <Clarification> repo = new ClarificationRepository(); repo.Update(clarification); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here string name = collection.Get("Name"); Clarification clarification = new Clarification() { Name = name }; IRepository <Clarification> repo = new ClarificationRepository(); repo.Save(clarification); return(RedirectToAction("Index")); } catch { return(View()); } }
public MessagesQueriesTests() { factory = new TestDatabaseConfiguration().DatabaseConfiguration.BuildSessionFactory(); isenbaev = new User { UserName = "******" }; contest = new Contest { Beginning = new DateTime(1990, 7, 7), Ending = new DateTime(1990, 7, 8) }; var kapun = new User { UserName = "******", }; var announcement = new Announcement { SentAt = new DateTime(1990, 7, 7), Contest = contest }; var clarification = new Clarification { SentAt = new DateTime(1990, 7, 7), Contest = contest }; var myQuestion = new Question { Author = isenbaev, SentAt = new DateTime(1990, 7, 7), Contest = contest }; var myAnswer = new Answer { Recipient = isenbaev, SentAt = new DateTime(1990, 7, 7), Contest = contest }; var hisQuestion = new Question { Author = kapun, SentAt = new DateTime(1990, 7, 7), Contest = contest }; var hisAnswer = new Answer { Recipient = kapun, SentAt = new DateTime(1990, 7, 7), Contest = contest }; using (var scope = new SessionScope(factory)) { scope.Session.Save(isenbaev); scope.Session.Save(kapun); scope.Session.Save(contest); scope.Session.Save(announcement); scope.Session.Save(clarification); scope.Session.Save(myQuestion); scope.Session.Save(hisQuestion); scope.Session.Save(myAnswer); scope.Session.Save(hisAnswer); } }
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 })); }
public ClarificationCreateEvent(IContestContext contest, Clarification entity) { Clarification = entity; Context = contest; }
public void UpdateClarificationBeforeInsertOne(Clarification clar) { DbContext.Clarifications.Update(clar); }
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 })); }
public static async Task <IActionResult> ClarificationReply <T>( this ContestControllerBase <T> that, int?clarid, Models.AddClarificationModel model, string HomePage) where T : class, ICompeteContext { var(cid, teamid) = (that.Contest.Id, that.Contest.Team.TeamId); Clarification replit = null; if (clarid.HasValue) { replit = await that.Context.FindClarificationAsync(clarid.Value); if (replit == null) { that.ModelState.AddModelError( "xys::replyto", "The clarification replied to is not found."); } } if (string.IsNullOrWhiteSpace(model.Body)) { that.ModelState.AddModelError( "xys::empty", "No empty clarification"); } var probs = await that.Context.ListProblemsAsync(); var usage = probs.ClarificationCategories.SingleOrDefault(cp => model.Type == cp.Item1); if (usage.Item1 == null) { that.ModelState.AddModelError( "xys::error_cate", "The category specified is wrong."); } if (!that.ModelState.IsValid) { that.StatusMessage = string.Join('\n', that.ModelState.Values .SelectMany(m => m.Errors) .Select(e => e.ErrorMessage)); } else { var clar = await that.Context.ClarifyAsync( new Clarification { Body = model.Body, SubmitTime = DateTimeOffset.Now, ContestId = cid, Sender = teamid, ResponseToId = model.ReplyTo, ProblemId = usage.Item3, Category = usage.Item2, }); await that.HttpContext.AuditAsync("added", $"{clar.Id}"); that.StatusMessage = "Clarification sent to the jury."; } return(that.RedirectToAction(HomePage)); }