示例#1
0
 void CollectEntityByRevision(MooDB db, int id)
 {
     revision = (from r in db.SolutionRevisions
                 where r.ID == id
                 select r).SingleOrDefault<SolutionRevision>();
     problem = revision == null ? null : revision.Problem;
 }
示例#2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid) return;
        int problemID = (int)ViewState["problemID"];
        using (MooDB db = new MooDB())
        {
            Problem problem = (from p in db.Problems
                               where p.ID == problemID
                               select p).Single<Problem>();
            if (problem.LockSolution)
            {
                if (!Permission.Check("solution.locked.update", false)) return;
            }
            else
            {
                if (!Permission.Check("solution.update", false)) return;
            }
            User user = ((SiteUser)User.Identity).GetDBUser(db);
            SolutionRevision revision = new SolutionRevision()
            {
                Content = txtContent.Text,
                Problem = problem,
                Reason = txtReason.Text,
                CreatedBy = user
            };
            db.SolutionRevisions.AddObject(revision);
            problem.LatestSolution = revision;
            db.SaveChanges();

            Logger.Info(db, string.Format("更新题目#{0}的题解,新版本为#{1}", ViewState["problemID"], revision.ID));
        }
        PageUtil.Redirect("更新成功", "~/Solution/?id=" + problemID);
    }
示例#3
0
 void CollectEntityByID(MooDB db, int id)
 {
     problem = (from p in db.Problems
                where p.ID == id
                select p).SingleOrDefault<Problem>();
     revision = problem == null ? null : problem.LatestSolution;
 }
示例#4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Permission.Check("solution.history.read", true)) return;
        if (!Page.IsPostBack)
        {
            using (MooDB db = new MooDB())
            {
                if (Request["revisionOld"] != null && Request["revisionNew"] != null)
                {
                    CollectEntity(db, int.Parse(Request["revisionOld"]), int.Parse(Request["revisionNew"]));
                }

                if (revisionOld == null || revisionNew == null)
                {
                    PageUtil.Redirect(Resources.Moo.FoundNothing, "~/");
                    return;
                }

                if (revisionOld.ID > revisionNew.ID)
                {
                    SolutionRevision tmp = revisionNew;
                    revisionNew = revisionOld;
                    revisionOld = tmp;
                }

                if (revisionOld.Problem.ID != revisionNew.Problem.ID)
                {
                    throw new Exception("试图比较不同题目之间的版本");
                }

                problem = revisionNew.Problem;

                revisionOldPrev = (from r in db.SolutionRevisions
                                   where r.Problem.ID == problem.ID && r.ID < revisionOld.ID
                                   orderby r.ID descending
                                   select r).FirstOrDefault<SolutionRevision>();
                revisionNewPrev = (from r in db.SolutionRevisions
                                   where r.Problem.ID == problem.ID && r.ID < revisionNew.ID
                                   orderby r.ID descending
                                   select r).FirstOrDefault<SolutionRevision>();
                revisionOldNext = (from r in db.SolutionRevisions
                                   where r.Problem.ID == problem.ID && r.ID > revisionOld.ID
                                   orderby r.ID
                                   select r).FirstOrDefault<SolutionRevision>();
                revisionNewNext = (from r in db.SolutionRevisions
                                   where r.Problem.ID == problem.ID && r.ID > revisionNew.ID
                                   orderby r.ID
                                   select r).FirstOrDefault<SolutionRevision>();

                Page.DataBind();
            }
        }
    }
示例#5
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid) return;
        if (!Permission.Check("problem.create", false)) return;

        int problemID;
        using (MooDB db = new MooDB())
        {
            User currentUser = ((SiteUser)User.Identity).GetDBUser(db);
            Problem problem = new Problem()
            {
                Name = txtName.Text,
                Type = ddlType.SelectedValue,
                AllowTesting = true,
                Lock = false,
                LockPost = false,
                LockRecord = false,
                LockSolution = false,
                LockTestCase = false,
                Hidden = false,
                TestCaseHidden = false,
            };
            ProblemRevision revision = new ProblemRevision()
            {
                Problem = problem,
                Content = txtContent.Text,
                Reason = "创建题目",
                CreatedBy = currentUser
            };
            SolutionRevision solution = new SolutionRevision()
            {
                Problem = problem,
                Content = "暂无题解",
                Reason = "创建题解",
                CreatedBy = currentUser
            };
            problem.LatestRevision = revision;
            problem.LatestSolution = solution;

            db.ProblemRevisions.AddObject(revision);
            db.SaveChanges();

            problemID = revision.Problem.ID;

            Logger.Info(db, "创建题目#" + problemID);
        }
        PageUtil.Redirect("创建成功", "~/Problem/?id=" + problemID);
    }
示例#6
0
 /// <summary>
 /// 用于向 SolutionRevisions EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToSolutionRevisions(SolutionRevision solutionRevision)
 {
     base.AddObject("SolutionRevisions", solutionRevision);
 }
示例#7
0
 /// <summary>
 /// 创建新的 SolutionRevision 对象。
 /// </summary>
 /// <param name="id">ID 属性的初始值。</param>
 /// <param name="content">Content 属性的初始值。</param>
 /// <param name="reason">Reason 属性的初始值。</param>
 public static SolutionRevision CreateSolutionRevision(global::System.Int32 id, global::System.String content, global::System.String reason)
 {
     SolutionRevision solutionRevision = new SolutionRevision();
     solutionRevision.ID = id;
     solutionRevision.Content = content;
     solutionRevision.Reason = reason;
     return solutionRevision;
 }
示例#8
0
 void CollectEntity(MooDB db, int oldID, int newID)
 {
     revisionOld = (from r in db.SolutionRevisions
                    where r.ID == oldID
                    select r).SingleOrDefault<SolutionRevision>();
     revisionNew = (from r in db.SolutionRevisions
                    where r.ID == newID
                    select r).SingleOrDefault<SolutionRevision>();
 }
示例#9
0
 protected void validateSameProblem_ServerValidate(object source, ServerValidateEventArgs args)
 {
     int revisionOldID = int.Parse(txtRevisionOld.Text), revisionNewID = int.Parse(txtRevisionNew.Text);
     using (MooDB db = new MooDB())
     {
         revisionOld = (from r in db.SolutionRevisions
                        where r.ID == revisionOldID
                        select r).SingleOrDefault<SolutionRevision>();
         revisionNew = (from r in db.SolutionRevisions
                        where r.ID == revisionNewID
                        select r).SingleOrDefault<SolutionRevision>();
         args.IsValid = revisionOld == null || revisionNew == null || revisionOld.Problem.ID == revisionNew.Problem.ID;
     }
 }
示例#10
0
文件: API.cs 项目: MooDevTeam/MooOJ
        public int CreateProblem(string sToken, string name, string type, string content)
        {
            Authenticate(sToken);
            Authorize("problem.create");
            using (MooDB db = new MooDB())
            {
                User currentUser = CurrentUser.GetDBUser(db);

                Problem problem = new Problem()
                {
                    Name = name,
                    Type = type,
                    AllowTesting = true,
                    Hidden = false,
                    Lock = false,
                    LockPost = false,
                    LockRecord = false,
                    LockSolution = false,
                    LockTestCase = false,
                    MaximumScore = null,
                    ScoreSum = 0,
                    SubmissionCount = 0,
                    SubmissionUser = 0,
                    TestCaseHidden = false
                };

                ProblemRevision revision = new ProblemRevision()
                {
                    Content = content,
                    CreatedBy = currentUser,
                    Reason = "创建题目",
                    Problem = problem
                };

                SolutionRevision solution = new SolutionRevision()
                {
                    Content = "暂无题解",
                    CreatedBy = currentUser,
                    Reason = "创建题解",
                    Problem = problem
                };

                problem.LatestRevision = revision;
                problem.LatestSolution = solution;
                db.SaveChanges();

                return problem.ID;
            }
        }