本文整理汇总了C#中DBContext.SubmitChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DBContext.SubmitChanges方法的具体用法?C# DBContext.SubmitChanges怎么用?C# DBContext.SubmitChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBContext
的用法示例。
在下文中一共展示了DBContext.SubmitChanges方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBulletin
public ActionResult AddBulletin(string packageid, FormCollection form)
{
SetMenuSelection("Apps");
if (Session["UserID"] == null)
return RedirectToAction("Login", "Home");
DBContext db = new DBContext();
ViewData["PackageID"] = packageid;
if (form.Count > 0)
{
//create
if (form["txtCreateTitle"] == string.Empty)
{
ViewData["CreateStatus"] = "Title is required";
return View();
}
MetrixBulletinBoardAnnouncement mbba = new MetrixBulletinBoardAnnouncement();
mbba.Message = form["editorCreate"];
mbba.PackageID = packageid;
mbba.Title = form["txtCreateTitle"];
db.MetrixBulletinBoardAnnouncements.InsertOnSubmit(mbba);
db.SubmitChanges();
Response.Redirect("/Apps/Bulletin/" + packageid);
}
return View();
}
示例2: Retire
/// <summary>
/// Retires a car, removing it from the database.
/// </summary>
public static bool Retire(string registrationNo)
{
using (DBContext dbContext = new DBContext())
{
Car car = dbContext.Cars.Where(c => c.RegistrationNumber == registrationNo).SingleOrDefault();
if (car == null)
return false;
dbContext.Cars.DeleteOnSubmit(car);
dbContext.SubmitChanges();
return true;
}
}
示例3: License
//
// GET: /Library/
public ActionResult License(FormCollection form)
{
SetMenuSelection("Download");
if (Session["UserID"] == null)
return RedirectToAction("Login", "Home");
if (form.Count > 0)
{
DBContext db = new DBContext();
User u = (from t in db.Users
where t.ID.ToString() == Session["UserID"].ToString()
select t).FirstOrDefault();
u.SignedLicense = true;
db.SubmitChanges();
Session["License"] = true.ToString();
return RedirectToAction("Download", "Library");
}
return View();
}
示例4: Signup
public ActionResult Signup(FormCollection form)
{
SetMenuSelection("Signup");
DBContext db = new DBContext();
#region Add User
if (form.Count > 0)
{
string name = form["txtName"];
string first = form["txtFirst"];
string last = form["txtLast"];
string company = form["txtCompany"];
string email = form["txtEmail"];
string password = form["txtPassword"];
string confirm = form["txtConfirm"];
ViewData["Name"] = name;
ViewData["First"] = first;
ViewData["Last"] = last;
ViewData["Company"] = company;
ViewData["Email"] = email;
#region Validation
if (name == string.Empty || first == string.Empty || last == string.Empty || email == string.Empty ||
password == string.Empty || confirm == string.Empty || company == string.Empty)
{
ViewData["Status"] = "All fields are required...";
return View();
}
if (!Regex.IsMatch(email, @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"))
{
ViewData["Status"] = "Come on...email needs to be real otherwise we can't send you your authorization key.";
return View();
}
if (password != confirm)
{
ViewData["Status"] = "Passwords don't match...";
return View();
}
//dup name check
var check = db.Users.SingleOrDefault(i => i.Login == name);
if (check != null)
{
ViewData["Status"] = "Sorry, that user name is taken.";
return View();
}
#endregion
User u = new User();
u.ID = Guid.NewGuid();
u.Login = name;
u.FirstName = first;
u.LastName = last;
u.CompanyName = company;
u.Email = email;
u.Password = UtilCommand.GetMD5(password);
u.AuthKey = Guid.NewGuid();
db.Users.InsertOnSubmit(u);
UserUserType uut = new UserUserType();
uut.ID = Guid.NewGuid();
uut.UserID = u.ID;
uut.UserTypeID = new Guid("4cbef1c1-c2fa-4ce6-9bc1-6cada43ad0d4"); //developer
db.UserUserTypes.InsertOnSubmit(uut);
db.SubmitChanges();
#region Send Email
StringBuilder sb = new StringBuilder();
sb.Append("<h2>Welcome to Metrix!</h2>");
sb.Append("<p>Thank you for signing up to Metrix. The last step to completing your profile is copying the code below and pasting it into your profile page at http://metrix.webosroundup.com.</p>");
sb.Append("<p>If you have logged out of metrix, simply log back in and paste in the code.</p>");
sb.Append("<p><strong>Authorization Key:</strong> ");
sb.Append(u.AuthKey.ToString());
sb.Append("</p><p>Thank you again for your interest in Metrix. If you have any questions, please feel free to email us at [email protected] and we will get back to you as soon as possible.");
sb.Append("<br/><p>-- The webOSroundup and Syntactix teams</p>");
UtilCommand.SendEmail(email, "Metrix Authorization Key", sb.ToString());
#endregion
Session["UserID"] = u.ID;
Session["UserTypes"] = u.UserUserTypes.ToList();
return RedirectToAction("Authentication", "Profile");
}
#endregion
return View();
}
示例5: Update
//
// GET: /Profile/
public ActionResult Update(FormCollection form)
{
if (Session["UserID"] == null)
return RedirectToAction("Login", "Home");
if (((List<UserUserType>)Session["UserTypes"]).Where(i => i.UserType.Name == Constants.UserTypes.Admin).Count() > 0)
SetMenuSelection("AdminProfile");
else
SetMenuSelection("Profile");
DBContext db = new DBContext();
User u = (from t in db.Users
where t.ID.ToString() == Session["UserID"].ToString()
select t).FirstOrDefault();
ViewData["User"] = u;
if (form.Count > 0)
{
string first = form["txtName"];
string last = form["txtLast"];
string company = form["txtCompany"];
string email = form["txtEmail"];
string password = form["txtPassword"];
string confirm = form["txtConfirm"];
if (company == string.Empty || first == string.Empty || last == string.Empty || email == string.Empty)
{
ViewData["Status"] = "All of the fields are required";
return View();
}
if (password != string.Empty && password != confirm)
{
ViewData["Status"] = "Passwords don't match";
return View();
}
Regex r = new Regex(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
if (!r.IsMatch(email))
{
ViewData["Status"] = "We need a valid email address so we can send fun messages!";
return View();
}
u.FirstName = first;
u.LastName = last;
u.CompanyName = company;
u.Email = email;
if (password != string.Empty)
u.Password = UtilCommand.GetMD5(password);
db.SubmitChanges();
ViewData["Status"] = "Good to go chief";
}
return View();
}
示例6: Authentication
public ActionResult Authentication(FormCollection form)
{
if (Session["UserID"] == null)
return RedirectToAction("Login", "Home");
DBContext db = new DBContext();
User u = db.Users.SingleOrDefault(i => i.ID.ToString() == Session["UserID"].ToString());
ViewData["Email"] = u.Email;
if (form["txtKey"] != null)
{
if (form["txtKey"].Trim() != u.AuthKey.ToString())
{
ViewData["Status"] = "Sorry chief, that key didn't work...please try again, and if this continues to be a problem email us at [email protected]";
return View();
}
u.AuthKey = null;
db.SubmitChanges();
#region Send email to admins
StringBuilder sb = new StringBuilder();
sb.Append("<strong>NEW DEV!!</strong><br/>A new dev has just completed the signup process to use Metrix.");
sb.Append("<p>");
sb.Append("<b>Company Name</b>: ");
sb.Append(u.CompanyName);
sb.Append("</p><p>");
sb.Append("<b>Person's Name</b>: ");
sb.Append(u.FirstName);
sb.Append(" ");
sb.Append(u.LastName);
sb.Append("</p><p>");
sb.Append("<b>Email:</b><a href='mailto:");
sb.Append(u.Email);
sb.Append("'>");
sb.Append(u.Email);
sb.Append("</a></p>");
//create the mail message
UtilCommand.SendEmail("[email protected]", "Metrix New Dev Signup", sb.ToString());
#endregion
return RedirectToAction("List", "Apps");
}
else if (form["txtEmail"] != null)
{
Regex r = new Regex(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
if (!r.IsMatch(form["txtEmail"]))
{
ViewData["Status"] = "We need a valid email address so we can send fun messages!";
return View();
}
u.Email = form["txtEmail"];
db.SubmitChanges();
SendEmail(u);
ViewData["Status"] = "Email changed and we resent your authentication key!";
}
else if (form["hdnResend"] != null)
{
SendEmail(u);
ViewData["Status"] = "Authentication key resent!";
}
return View();
}
示例7: MaintainBulletin
public ActionResult MaintainBulletin(string packageid, FormCollection form)
{
//it's not really the package id...just being lazy for now
SetMenuSelection("Apps");
if (Session["UserID"] == null)
return RedirectToAction("Login", "Home");
DBContext db = new DBContext();
ViewData["Title"] = "Update Bulletin";
MetrixBulletinBoardAnnouncement mbba = db.MetrixBulletinBoardAnnouncements.SingleOrDefault(i => i.ID.ToString() == packageid);
if (mbba == null)
return RedirectToAction("Login", "Home");
ViewData["Bulletin"] = mbba;
ViewData["PackageID"] = mbba.PackageID;
if (form.Count > 0)
{
mbba.Title = form["txtTitle"];
mbba.Message = form["editorUpdate"];
db.SubmitChanges();
Response.Redirect("/Apps/Bulletin/" + mbba.PackageID);
}
return View();
}
示例8: List
//
// GET: /Apps/
public ActionResult List(FormCollection form)
{
if (Session["UserID"] == null)
return RedirectToAction("Login", "Home");
SetMenuSelection("Apps");
DBContext db = new DBContext();
if (form.Count > 0)
{
string pid = form[0];
//make sure it hasn't been claimed before
var test = from t in db.AppUsers
where t.PackageID == pid
select t;
if (test.Count() > 0)
ViewData["Status"] = "Hey! That app is already taken!!";
else
{
AppUser au = new AppUser();
au.ID = Guid.NewGuid();
au.PackageID = pid;
au.UserID = new Guid(Session["UserID"].ToString());
db.AppUsers.InsertOnSubmit(au);
db.SubmitChanges();
}
}
var list = from t in db.AppUsers
where t.UserID.ToString() == Session["UserID"].ToString()
select t;
List<string> apps = new List<string>();
foreach (var item in list)
{
apps.Add(item.PackageID);
}
ViewData["Apps"] = apps;
return View();
}
示例9: DeleteBulletin
public ActionResult DeleteBulletin(string packageid)
{
//it's not really the package id...just being lazy for now
SetMenuSelection("Apps");
if (Session["UserID"] == null)
return RedirectToAction("Login", "Home");
DBContext db = new DBContext();
MetrixBulletinBoardAnnouncement a = db.MetrixBulletinBoardAnnouncements.SingleOrDefault(i => i.ID.ToString() == packageid);
db.MetrixBulletinBoardAnnouncements.DeleteOnSubmit(a);
db.SubmitChanges();
return RedirectToAction("Bulletin", "Apps", new { packageid = a.PackageID});
}
示例10: Delete
public ActionResult Delete(string packageid, FormCollection form)
{
SetMenuSelection("Apps");
if (Session["UserID"] == null)
return RedirectToAction("Login", "Home");
using (IMongo mongo = MDB.Instance().GetMongo())
{
ViewData["PID"] = packageid;
if (form["hdnDelete"] != null)
{
DBContext db = new DBContext();
var list = db.AppUsers.Where(i => i.PackageID == packageid);
db.AppUsers.DeleteAllOnSubmit(list);
db.SubmitChanges();
return RedirectToAction("List", "Apps");
}
return View();
}
}
示例11: Bulletin
public ActionResult Bulletin(string packageid, FormCollection form)
{
SetMenuSelection("Apps");
if (Session["UserID"] == null)
return RedirectToAction("Login", "Home");
DBContext db = new DBContext();
var list = from t in db.MetrixBulletinBoards
where t.PackageID == packageid
select t;
//see if the version already exists
MetrixBulletinBoard version = db.MetrixBulletinBoards.SingleOrDefault(i => i.PackageID == packageid);
if (version == null)
{
version = new MetrixBulletinBoard();
version.PackageID = packageid;
version.BulletinBoardVersion = 1;
db.MetrixBulletinBoards.InsertOnSubmit(version);
db.SubmitChanges();
}
ViewData["Version"] = version;
ViewData["Bulletins"] = list.ToList();
ViewData["PID"] = packageid;
if (form.Count > 0)
{
#region Validate
int versionNumber;
try
{
versionNumber = int.Parse(form["txtUpdateVersion"]);
}
catch
{
ViewData["VersionStatus"] = "Version needs to be a number";
return View();
}
#endregion
version.BulletinBoardVersion = versionNumber;
db.SubmitChanges();
ViewData["VersionStatus"] = "Got it!";
}
return View();
}