当前位置: 首页>>代码示例>>C#>>正文


C# DB.MooDB类代码示例

本文整理汇总了C#中Moo.DB.MooDB的典型用法代码示例。如果您正苦于以下问题:C# MooDB类的具体用法?C# MooDB怎么用?C# MooDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MooDB类属于Moo.DB命名空间,在下文中一共展示了MooDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnSubmit_Click

    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);
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:27,代码来源:Create.aspx.cs

示例2: AddTestData

 public static void AddTestData()
 {
     using (MooDB db = new MooDB())
     {
         AddTestData(db);
     }
 }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:7,代码来源:MooTestData.cs

示例3: MainLoop

        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;
                }
            }
        }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:35,代码来源:TesterManager.cs

示例4: Page_Load

    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();
            }
        }
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:26,代码来源:Default.aspx.cs

示例5: Page_Load

    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();
            }
        }
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:28,代码来源:Modify.aspx.cs

示例6: grid_RowDeleted

 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]));
     }
 }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:7,代码来源:Default.aspx.cs

示例7: btnSubmit_Click

    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);
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:28,代码来源:Modify.aspx.cs

示例8: CollectEntityByID

 void CollectEntityByID(MooDB db, int id)
 {
     testCase = (from t in db.TestCases
                 where t.ID == id
                 select t).SingleOrDefault<TestCase>();
     problem = testCase.Problem;
 }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:7,代码来源:Default.aspx.cs

示例9: btnSubmit_Click

    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");
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:25,代码来源:Register.aspx.cs

示例10: Page_Load

    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();
            }
        }
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:28,代码来源:Compare.aspx.cs

示例11: Page_Load

    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();
            }
        }
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:35,代码来源:Reply.aspx.cs

示例12: btnAttend_Click

    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);
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:30,代码来源:Default.aspx.cs

示例13: grid_RowDeleted

 protected void grid_RowDeleted(object sender, GridViewDeletedEventArgs e)
 {
     using (MooDB db = new MooDB())
     {
         Logger.Warning(db, "删除邮件#" + e.Keys[0]);
     }
 }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:7,代码来源:List.aspx.cs

示例14: btnSubmit_Click

    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);
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:35,代码来源:Update.aspx.cs

示例15: Page_Load

    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();
            }
        }
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:35,代码来源:Update.aspx.cs


注:本文中的Moo.DB.MooDB类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。