protected void btnSubmit_Click(object sender, EventArgs e) { if (!Page.IsValid) return; if (!Permission.Check("file.create", false)) return; string fileName = Resources.Moo.File_UploadPath + Path.GetRandomFileName() + "." + fileUpload.FileName.Split('.').Last(); fileUpload.SaveAs(fileName); int fileID; using (MooDB db = new MooDB()) { User currentUser = ((SiteUser)User.Identity).GetDBUser(db); UploadedFile file = new UploadedFile() { Name = txtName.Text, Description = txtDescription.Text, Path = fileName, CreatedBy=currentUser }; db.UploadedFiles.AddObject(file); db.SaveChanges(); fileID = file.ID; Logger.Info(db, "创建文件#" + fileID); } PageUtil.Redirect("创建成功", "~/File/?id=" + fileID); }
public static void AddTestData() { using (MooDB db = new MooDB()) { AddTestData(db); } }
static int MainLoop() { using (MooDB db = new MooDB()) { Record record = (from r in db.Records where r.JudgeInfo == null && r.Problem.AllowTesting select r).FirstOrDefault<Record>(); var a = (from r in db.Records where r.JudgeInfo == null select r); if (record == null) { return 5 * 1000; } else { record.JudgeInfo = new JudgeInfo() { Record = record, Score = -1, Info = "<color:blue>*正在评测*</color>" }; db.SaveChanges(); Logger.Info(db, "开始评测记录#" + record.ID); Test(db, record); db.SaveChanges(); Logger.Info(db, "记录#" + record.ID + "评测完成"); return 0; } } }
protected void Page_Load(object sender, EventArgs e) { if (!Permission.Check("file.read", true)) return; if (!Page.IsPostBack) { using (MooDB db = new MooDB()) { if (Request["id"] != null) { int fileID = int.Parse(Request["id"]); file = (from f in db.UploadedFiles where f.ID == fileID select f).SingleOrDefault<UploadedFile>(); } if (file == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } Page.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { using (MooDB db = new MooDB()) { if (Request["id"] != null) { int recordID = int.Parse(Request["id"]); record = (from r in db.Records where r.ID == recordID select r).SingleOrDefault<Record>(); } if (record == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } canModify = Permission.Check("record.modify", false, false) || User.Identity.IsAuthenticated && record.User.ID == ((SiteUser)User.Identity).ID; ViewState["recordID"] = record.ID; Page.DataBind(); } } }
protected void grid_RowDeleted(object sender, GridViewDeletedEventArgs e) { using (MooDB db = new MooDB()) { Logger.Warning(db, string.Format("删除帖子#{0}的项#{1}", ViewState["postID"], e.Keys[0])); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { using (MooDB db = new MooDB()) { if (Request["id"] != null) { int problemID = int.Parse(Request["id"]); problem = (from p in db.Problems where p.ID == problemID select p).SingleOrDefault<Problem>(); } if (problem == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } ViewState["problemID"] = problem.ID; Page.DataBind(); ddlType.SelectedIndex = ddlType.Items.IndexOf(ddlType.Items.FindByValue(problem.Type)); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (!Page.IsValid) return; if (!Permission.Check("problem.modify", false)) return; int problemID = (int)ViewState["problemID"]; using (MooDB db = new MooDB()) { problem = (from p in db.Problems where p.ID == problemID select p).Single<Problem>(); problem.Name = txtName.Text; problem.Type = ddlType.SelectedValue; problem.Hidden = chkHidden.Checked; problem.TestCaseHidden = chkTestCaseHidden.Checked; problem.AllowTesting = chkAllowTesting.Checked; problem.Lock = chkLock.Checked; problem.LockPost = chkLockPost.Checked; problem.LockRecord = chkLockRecord.Checked; problem.LockSolution = chkLockSolution.Checked; problem.LockTestCase = chkLockTestCase.Checked; db.SaveChanges(); Logger.Info(db, "修改题目#" + problem.ID); } PageUtil.Redirect("修改成功", "~/Problem/?id=" + problemID); }
void CollectEntityByID(MooDB db, int id) { testCase = (from t in db.TestCases where t.ID == id select t).SingleOrDefault<TestCase>(); problem = testCase.Problem; }
protected void btnSubmit_Click(object sender, EventArgs e) { if (!Page.IsValid) return; if (!Permission.Check("user.create", true)) return; using (MooDB db = new MooDB()) { User user = new User() { Name = txtUserName.Text, Password = Converter.ToSHA256Hash(txtPassword.Text), Role = SiteRoles.ByType[RoleType.NormalUser].GetDBRole(db), BriefDescription = "我很懒,什么都没留下~", Description = "我懒到头了,*真的*啥都没写", Email = "", Score = 0, PreferredLanguage = "c++" }; db.Users.AddObject(user); db.SaveChanges(); Logger.Info(db, "创建用户#" + user.ID); } PageUtil.Redirect("注册成功,请登录", "~/Special/Login.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (!Permission.Check("record.read", true)) return; if (!Page.IsPostBack) { using (MooDB db = new MooDB()) { if (Request["id"] != null) { CollectEntityByID(db, int.Parse(Request["id"])); } if (record == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } trCode.Visible = User.Identity.IsAuthenticated && ((SiteUser)User.Identity).ID == record.User.ID || Permission.Check("record.code.read", false, false) || record.PublicCode; Page.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Permission.Check("user.read", true)) return; if (!Page.IsPostBack) { using (MooDB db = new MooDB()) { int userAID = int.Parse(Request["userA"]); int userBID = int.Parse(Request["userB"]); userA = (from u in db.Users where u.ID == userAID select u).SingleOrDefault<User>(); userB = (from u in db.Users where u.ID == userBID select u).SingleOrDefault<User>(); if (userA == null || userB == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } BindDatas(db); Page.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Permission.Check("mail.read", false)) return; if (!Page.IsPostBack) { using (MooDB db = new MooDB()) { if (Request["id"] != null) { CollectEntityByID(db, int.Parse(Request["id"])); } if (mail == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } int myUserID = ((SiteUser)User.Identity).ID; if (myUserID != mail.From.ID && myUserID != mail.To.ID) { Permission.Check("i'm superman", false); return; } if (mail.To.ID == myUserID) { mail.IsRead = true; Logger.Info(db, "阅读邮件#" + mail.ID); } db.SaveChanges(); Page.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Permission.Check("post.read", true)) return; if (!Page.IsPostBack) { using (MooDB db = new MooDB()) { if (Request["id"] != null) { int postID = int.Parse(Request["id"]); post = (from p in db.Posts where p.ID == postID select p).SingleOrDefault<Post>(); } if (post == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } ViewState["postID"] = post.ID; Page.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { using (MooDB db = new MooDB()) { if (Request["replyTo"] != null) { CollectEntityByReplyTo(db, int.Parse(Request["replyTo"])); } else if (Request["id"] != null) { CollectEntityByID(db, int.Parse(Request["id"])); } if (post == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } if (post.Lock || post.Problem != null && post.Problem.LockPost) { canReply = Permission.Check("post.locked.reply", false, false); } else { canReply = Permission.Check("post.reply", false, false); } ViewState["postID"] = post.ID; Page.DataBind(); } } }
protected void btnAttend_Click(object sender, EventArgs e) { if (!Permission.Check("contest.attend", false)) return; int contestID = (int)ViewState["contestID"]; using (MooDB db = new MooDB()) { contest = (from c in db.Contests where c.ID == contestID select c).Single<Contest>(); if (DateTimeOffset.Now > contest.EndTime) { return; } User currentUser = ((SiteUser)User.Identity).GetDBUser(db); if (contest.User.Contains(currentUser)) { return; } contest.User.Add(currentUser); db.SaveChanges(); Logger.Info(db, "报名比赛#" + contest.ID); } Response.Redirect("~/Contest/?id=" + contestID, true); }
protected void grid_RowDeleted(object sender, GridViewDeletedEventArgs e) { using (MooDB db = new MooDB()) { Logger.Warning(db, "删除邮件#" + e.Keys[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.Lock) { if (!Permission.Check("problem.locked.update", false)) return; } else { if (!Permission.Check("problem.update", false)) return; } User user = ((SiteUser)User.Identity).GetDBUser(db); ProblemRevision revision = new ProblemRevision() { Content = txtContent.Text, Problem = problem, Reason = txtReason.Text, CreatedBy = user }; db.ProblemRevisions.AddObject(revision); problem.LatestRevision = revision; db.SaveChanges(); Logger.Info(db, string.Format("更新题目#{0},新版本为#{1}", problem.ID, revision.ID)); } PageUtil.Redirect("更新成功", "~/Problem/?id=" + problemID); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { using (MooDB db = new MooDB()) { if (Request["revision"] != null) { CollectEntityByRevision(db, int.Parse(Request["revision"])); } else if (Request["id"] != null) { CollectEntityById(db, int.Parse(Request["id"])); } if (problem == null || revision == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } if (problem.LatestRevision.ID != revision.ID) { if (!Permission.Check("problem.history.read", true)) return; } canRead = problem.Hidden ? Permission.Check("problem.hidden.read", false,false) : Permission.Check("problem.read", true,false); canUpdate = problem.Lock ? Permission.Check("problem.locked.update", false, false) : Permission.Check("problem.update", false, false); ViewState["problemID"] = problem.ID; Page.DataBind(); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (!Page.IsValid) return; int receiverID=(int)ViewState["receiverID"]; using (MooDB db = new MooDB()) { Mail mail=new Mail() { From = ((SiteUser)User.Identity).GetDBUser(db), To = (from u in db.Users where u.ID == receiverID select u).Single<User>(), Title = txtTitle.Text, Content = txtContent.Text, IsRead = false, }; db.Mails.AddObject(mail); db.SaveChanges(); Logger.Info(db,string.Format("向用户#{0}发送邮件#{1}",receiverID,mail.ID)); } PageUtil.Redirect("创建成功", "~/Mail/List.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (!Permission.Check("user.read", true)) return; using (MooDB db = new MooDB()) { if (Request["id"] != null) { int id = int.Parse(Request["id"]); user = (from u in db.Users where u.ID == id select u).SingleOrDefault<User>(); } if (user == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } ViewState["userID"] = user.ID; grid.DataSource = GetDataToBind(db); Page.DataBind(); } }
protected void grid_RowDeleting(object sender, GridViewDeleteEventArgs e) { e.Cancel = true; int testCaseID = (int)e.Keys[0]; using (MooDB db = new MooDB()) { TestCase testCase = (from t in db.TestCases where t.ID == testCaseID select t).Single<TestCase>(); bool allowed = Permission.Check("testcase.delete", false, false) || User.Identity.IsAuthenticated && ((SiteUser)User.Identity).ID == testCase.CreatedBy.ID; if (!allowed) { Permission.Check("i'm superman.", false); return; } db.TestCases.DeleteObject(testCase); db.SaveChanges(); Logger.Warning(db, "删除测试数据#" + testCase.ID); } grid.Rows[e.RowIndex].Visible = false; }
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; }
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; }
protected void Page_Load(object sender, EventArgs e) { if (!Permission.Check("solution.read", true)) return; using (MooDB db = new MooDB()) { if (Request["revision"] != null) { CollectEntityByRevision(db,int.Parse(Request["revision"])); } else if (Request["id"] != null) { CollectEntityByID(db,int.Parse(Request["id"])); } if (problem == null || revision==null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } if (problem.LatestSolution.ID != revision.ID) { if (!Permission.Check("solution.history.read", true)) return; } Page.DataBind(); } }
void CollectEntityByID(MooDB db, int id) { record = (from r in db.Records where r.ID == id select r).SingleOrDefault<Record>(); info = record == null ? null : record.JudgeInfo; }
protected void ValidateUserName(object sender, ServerValidateEventArgs e) { using (MooDB db = new MooDB()) { e.IsValid = (from u in db.Users where u.Name == txtUserName.Text select u).SingleOrDefault<User>() == null; } }
protected void validateOtherName_ServerValidate(object source, ServerValidateEventArgs args) { using (MooDB db = new MooDB()) { args.IsValid = (from u in db.Users where u.Name == txtOtherName.Text select u).Any(); } }
protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e) { using (MooDB db = new MooDB()) { grid.PageIndex = e.NewPageIndex; grid.DataSource = GetDataToBind(db); grid.DataBind(); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (!Page.IsValid) return; if (!User.Identity.IsAuthenticated) { Permission.Check("i'm super man.", false); return; } int userID = (int)ViewState["userID"]; using (MooDB db = new MooDB()) { user = (from u in db.Users where u.ID == userID select u).Single<User>(); SiteUser siteUser = (SiteUser)User.Identity; canModify = siteUser.ID == user.ID || Permission.Check("user.modify", false, false) && siteUser.Role.Type < SiteRoles.ByID[user.Role.ID].Type; if (!canModify) { Permission.Check("i'm super man.", false); return; } if (Permission.Check("user.name.modify", false, false)) { user.Name = txtName.Text; } if (txtPassword.Text.Length > 0) { user.Password = Converter.ToSHA256Hash(txtPassword.Text); } user.Role = SiteRoles.ByID[int.Parse(ddlRole.SelectedValue)].GetDBRole(db); user.Email = txtEmail.Text; user.BriefDescription = txtBriefDescription.Text; user.Description = txtDescription.Text; db.SaveChanges(); //Refresh SiteUser if (SiteUsers.ByID.ContainsKey(user.ID)) { siteUser = SiteUsers.ByID[user.ID]; siteUser.Role = SiteRoles.ByID[user.Role.ID]; siteUser.Name = user.Name; } Logger.Info(db, "修改用户#" + user.ID); } PageUtil.Redirect("修改成功", "~/User/?id=" + userID); }