本文整理汇总了C#中Moo.DB.MooDB.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# MooDB.SaveChanges方法的具体用法?C# MooDB.SaveChanges怎么用?C# MooDB.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Moo.DB.MooDB
的用法示例。
在下文中一共展示了MooDB.SaveChanges方法的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);
}
示例2: 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");
}
示例3: grid_RowDeleting
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;
}
示例4: Page_Load
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();
}
}
}
示例5: 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);
}
示例6: 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);
}
示例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);
}
示例8: MainLoop
static int MainLoop()
{
using (MooDB db = new MooDB())
{
db.ExecuteStoreCommand("DELETE FROM [dbo].[Logs] WHERE [CreateTime] < @minTime", new SqlParameter("minTime", DateTimeOffset.Now.AddMonths(-1)));
db.SaveChanges();
}
return 5 * 60 * 1000;
}
示例9: Fatal
public static void Fatal(MooDB db, string info)
{
db.Logs.AddObject(new Log()
{
CreateTime = DateTimeOffset.Now,
Level = (byte)LogLevel.Fatal,
User = GetCurrentUser(db),
Info = info,
RemoteAddress = GetRemoteAddress()
});
db.SaveChanges();
}
示例10: MainLoop
static int MainLoop()
{
using (MooDB db = new MooDB())
{
Contest contest = (from c in db.Contests
where c.Status == "Before" && c.StartTime <= DateTimeOffset.Now
select c).FirstOrDefault<Contest>();
if (contest != null)
{
contest.Status = "During";
foreach (Problem problem in contest.Problem)
{
problem.AllowTesting = contest.AllowTestingOnStart;
problem.TestCaseHidden = contest.HideTestCaseOnStart;
problem.LockPost = contest.LockPostOnStart;
problem.LockTestCase = contest.LockTestCaseOnStart;
problem.LockSolution = contest.LockSolutionOnStart;
problem.Lock = contest.LockProblemOnStart;
problem.Hidden = contest.HideProblemOnStart;
problem.LockRecord = contest.LockRecordOnStart;
}
db.SaveChanges();
Logger.Info(db, "开始比赛#" + contest.ID);
return 0;
}
contest = (from c in db.Contests
where c.Status == "During" && c.EndTime <= DateTimeOffset.Now
select c).FirstOrDefault<Contest>();
if (contest != null)
{
contest.Status = "After";
foreach (Problem problem in contest.Problem)
{
problem.AllowTesting = contest.AllowTestingOnEnd;
problem.TestCaseHidden = contest.HideTestCaseOnEnd;
problem.LockPost = contest.LockPostOnEnd;
problem.LockTestCase = contest.LockTestCaseOnEnd;
problem.LockSolution = contest.LockSolutionOnEnd;
problem.Lock = contest.LockProblemOnEnd;
problem.Hidden = contest.HideProblemOnEnd;
problem.LockRecord = contest.LockRecordOnEnd;
}
db.SaveChanges();
Logger.Info(db, "结束比赛#" + contest.ID);
return 0;
}
return 60 * 1000;
}
}
示例11: btnSubmit_Click
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (!Page.IsValid) return;
int postID = (int)ViewState["postID"];
using (MooDB db = new MooDB())
{
Post post = (from p in db.Posts
where p.ID == postID
select p).Single<Post>();
if (post.Lock || post.Problem != null && post.Problem.LockPost)
{
if (!Permission.Check("post.locked.reply", false)) return;
}
else
{
if (!Permission.Check("post.reply", false)) return;
}
User currentUser = ((SiteUser)User.Identity).GetDBUser(db);
//Send Mails
SortedSet<User> userBeAt;
string parsed = WikiParser.ParseAt(db, txtContent.Text, out userBeAt);
foreach (User user in userBeAt)
{
db.Mails.AddObject(new Mail()
{
Title = "我@了您哦~",
Content = "我在帖子[url:" + post.Name + "|../Post/?id=" + post.ID + "]中*@*了您哦~快去看看!\r\n\r\n*原文如下*:\r\n" + parsed,
From = currentUser,
To = user,
IsRead = false
});
}
PostItem postItem = new PostItem()
{
Post = post,
Content = txtContent.Text,
CreatedBy = currentUser
};
db.PostItems.AddObject(postItem);
db.SaveChanges();
Logger.Info(db, string.Format("创建帖子#{0}的新项#{1}", post.ID, postItem.ID));
}
PageUtil.Redirect("回复成功", "~/Post/?id=" + postID);
}
示例12: btnAdd_Click
protected void btnAdd_Click(object sender, EventArgs e)
{
if (!Page.IsValid) return;
if (!Permission.Check("contest.modify", false)) return;
int contestID = (int)ViewState["contestID"];
int problemID = int.Parse(txtProblemID.Text);
using (MooDB db = new MooDB())
{
Problem problem = (from p in db.Problems
where p.ID == problemID
select p).Single<Problem>();
contest = (from c in db.Contests
where c.ID == contestID
select c).Single<Contest>();
contest.Problem.Add(problem);
db.SaveChanges();
Logger.Info(db, string.Format("向比赛#{0}加入题目#{1}", contest.ID, problem.ID));
}
Response.Redirect("~/Contest/?id=" + contestID);
}
示例13: grid_RowDeleting
protected void grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
if (!Permission.Check("contest.modify", false)) return;
int problemID = (int)e.Keys[0];
int contestID = (int)ViewState["contestID"];
using (MooDB db = new MooDB())
{
contest = (from c in db.Contests
where c.ID == contestID
select c).Single<Contest>();
Problem problem = (from p in db.Problems
where p.ID == problemID
select p).Single<Problem>();
contest.Problem.Remove(problem);
db.SaveChanges();
Logger.Warning(db, string.Format("删除比赛#{0}的题目#{1}", contest.ID, problem.ID));
}
Response.Redirect("~/Contest/?id=" + contestID);
}
示例14: CreateTranditionalTestCase
public int CreateTranditionalTestCase(string sToken, int problemID, byte[] input, byte[] answer, int timeLimit, int memoryLimit, int score)
{
Authenticate(sToken);
using (MooDB db = new MooDB())
{
Problem problem = (from p in db.Problems
where p.ID == problemID
select p).SingleOrDefault<Problem>();
if (problem == null) throw new ArgumentException("无此题目");
if (problem.Type != "Tranditional") throw new ArgumentException("不是传统题");
if (problem.LockTestCase)
{
Authorize("testcase.locked.create");
}
else
{
Authorize("testcase.create");
}
User currentUser = CurrentUser.GetDBUser(db);
TestCase testCase = new TranditionalTestCase()
{
Answer = answer,
CreatedBy = currentUser,
Input = input,
MemoryLimit = memoryLimit,
TimeLimit = timeLimit,
Problem = problem,
Score = score
};
db.TestCases.AddObject(testCase);
db.SaveChanges();
return testCase.ID;
}
}
示例15: CreateProblem
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;
}
}