예제 #1
0
파일: Clar.cs 프로젝트: yukozh/CodeComb-Old
 public Clar(Entity.Clarification clar)
 {
     ID = clar.ID;
     NoProblemRelation = false;
     if (clar.ProblemID == null)
     {
         ProblemRelation   = "General";
         NoProblemRelation = true;
     }
     else
     {
         ProblemRelation = HttpUtility.HtmlEncode(clar.Problem.Title);
     }
     Question = HttpUtility.HtmlEncode(clar.Question);
     Answer   = HttpUtility.HtmlEncode(clar.Answer);
     Time     = clar.Time.ToString("yyyy-MM-dd HH:mm:ss");
 }
예제 #2
0
        public ActionResult Clar(int id, int?problem_id, string question)
        {
            //合法性验证
            var contest = DbContext.Contests.Find(id);

            if (!Helpers.PrivateContest.IsUserInPrivateContest(ViewBag.CurrentUser == null ? null : (Entity.User)ViewBag.CurrentUser, contest))
            {
                return(RedirectToAction("Private", "Contest", new { id = id }));
            }
            if (!contest.AllowClarification)
            {
                return(RedirectToAction("Message", "Shared", new { msg = "本场比赛没有开启答疑平台!" }));
            }
            var problem = DbContext.Problems.Find(problem_id);

            if (problem != null && problem.ContestID != contest.ID)
            {
                return(RedirectToAction("Message", "Shared", new { msg = "没有找到该题!" }));
            }

            var clar = new Entity.Clarification
            {
                ContestID = id,
                ProblemID = problem_id,
                Status    = Entity.ClarificationStatus.Pending,
                Question  = question,
                Answer    = "",
                Time      = DateTime.Now,
                UserID    = ViewBag.CurrentUser.ID
            };

            DbContext.Clarifications.Add(clar);
            DbContext.SaveChanges();
            var masters = (from u in DbContext.Users
                           let master_ids = (from m in DbContext.ContestManagers
                                             where m.ContestID == contest.ID
                                             select m.UserID).ToList()
                                            where u.RoleAsInt >= (int)Entity.UserRole.Master ||
                                            master_ids.Contains(u.ID)
                                            select u).Distinct().ToList();

            foreach (var master in masters)
            {
                SignalR.CodeCombHub.context.Clients.Group(master.Username).onClarificationsRequested(clar.ID);
                SignalR.MobileHub.PushTo(master.ID, (clar.ProblemID == null ? "General" : clar.Problem.Title) + ":" + clar.Question);
                SignalR.MobileHub.context.Clients.Group(master.Username).onClarificationsRequested(new CodeComb.Models.WebAPI.Clarification
                {
                    ClarID      = clar.ID,
                    Question    = clar.Question,
                    Answer      = clar.Answer,
                    Category    = clar.ProblemID == null?"General":clar.Problem.Title,
                    Status      = clar.Status.ToString(),
                    StatusAsInt = clar.StatusAsInt,
                    ContestID   = clar.ContestID,
                    Time        = clar.Time
                });
            }

            //重新载入Model
            var clarifications = (from c in DbContext.Clarifications
                                  where c.ContestID == id &&
                                  c.StatusAsInt == (int)Entity.ClarificationStatus.BroadCast
                                  select c).ToList();

            ViewBag.CurrentContest = DbContext.Contests.Find(id);
            if (User.Identity.IsAuthenticated)
            {
                var _problems = (from p in DbContext.Problems
                                 where p.ContestID == id
                                 orderby p.Credit descending
                                 select p).ToList();
                var problems = new List <Models.View.ClarProblem>();
                foreach (var p in _problems)
                {
                    problems.Add(new Models.View.ClarProblem(p));
                }
                ViewBag.Problems = problems;
                var uid = (int)ViewBag.CurrentUser.ID;
                clarifications = clarifications.Union((from c in DbContext.Clarifications
                                                       where c.ContestID == id &&
                                                       c.UserID == uid
                                                       select c).ToList()).ToList();
            }
            clarifications = clarifications.OrderByDescending(x => x.Time).ToList();
            return(View(clarifications));
        }
예제 #3
0
        public ActionResult Clar(int id,int? problem_id, string question)
        {
            //合法性验证
            var contest = DbContext.Contests.Find(id);
            if (!Helpers.PrivateContest.IsUserInPrivateContest(ViewBag.CurrentUser == null ? null : (Entity.User)ViewBag.CurrentUser, contest))
                return RedirectToAction("Private", "Contest", new { id = id });
            if (!contest.AllowClarification)
                return RedirectToAction("Message", "Shared", new { msg = "本场比赛没有开启答疑平台!" });
            var problem = DbContext.Problems.Find(problem_id);
            if (problem != null && problem.ContestID != contest.ID)
                return RedirectToAction("Message", "Shared", new { msg = "没有找到该题!" });

            var clar = new Entity.Clarification
            {
                ContestID = id,
                ProblemID = problem_id,
                Status = Entity.ClarificationStatus.Pending,
                Question = question,
                Answer = "",
                Time = DateTime.Now,
                UserID = ViewBag.CurrentUser.ID
            };
            DbContext.Clarifications.Add(clar);
            DbContext.SaveChanges();
            var masters = (from u in DbContext.Users
                           let master_ids = (from m in DbContext.ContestManagers
                                             where m.ContestID == contest.ID
                                             select m.UserID).ToList()
                           where u.RoleAsInt >= (int)Entity.UserRole.Master
                           || master_ids.Contains(u.ID)
                           select u).Distinct().ToList();
            foreach (var master in masters)
            {
                SignalR.CodeCombHub.context.Clients.Group(master.Username).onClarificationsRequested(clar.ID);
                SignalR.MobileHub.PushTo(master.ID, (clar.ProblemID == null ? "General" : clar.Problem.Title) + ":" + clar.Question);
                SignalR.MobileHub.context.Clients.Group(master.Username).onClarificationsRequested(new CodeComb.Models.WebAPI.Clarification
                {
                    ClarID = clar.ID,
                    Question = clar.Question,
                    Answer = clar.Answer,
                    Category = clar.ProblemID == null?"General":clar.Problem.Title,
                    Status = clar.Status.ToString(),
                    StatusAsInt = clar.StatusAsInt,
                    ContestID = clar.ContestID,
                    Time = clar.Time
                });
            }

            //重新载入Model
            var clarifications = (from c in DbContext.Clarifications
                                  where c.ContestID == id
                                  && c.StatusAsInt == (int)Entity.ClarificationStatus.BroadCast
                                  select c).ToList();
            ViewBag.CurrentContest = DbContext.Contests.Find(id);
            if (User.Identity.IsAuthenticated)
            {
                var _problems = (from p in DbContext.Problems
                                    where p.ContestID == id
                                    orderby p.Credit descending
                                    select p).ToList();
                var problems = new List<Models.View.ClarProblem>();
                foreach (var p in _problems)
                    problems.Add(new Models.View.ClarProblem(p));
                ViewBag.Problems = problems;
                var uid = (int)ViewBag.CurrentUser.ID;
                clarifications = clarifications.Union((from c in DbContext.Clarifications
                                                       where c.ContestID == id
                                                       && c.UserID == uid
                                                       select c).ToList()).ToList();
            }
            clarifications = clarifications.OrderByDescending(x => x.Time).ToList();
            return View(clarifications);
        }