本文整理汇总了C#中CurtDevDataContext.SubmitChanges方法的典型用法代码示例。如果您正苦于以下问题:C# CurtDevDataContext.SubmitChanges方法的具体用法?C# CurtDevDataContext.SubmitChanges怎么用?C# CurtDevDataContext.SubmitChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CurtDevDataContext
的用法示例。
在下文中一共展示了CurtDevDataContext.SubmitChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public static string Save(int pVideoID = 0, int partID = 0, int vTypeID = 0, string video = "", bool isPrimary = false)
{
CurtDevDataContext db = new CurtDevDataContext();
PartVideo v = new PartVideo();
try {
if(pVideoID > 0) {
v = db.PartVideos.Where(x => x.pVideoID == pVideoID).First<PartVideo>();
v.video = video;
v.isPrimary = isPrimary;
v.vTypeID = vTypeID;
v.partID = partID;
db.SubmitChanges();
} else {
v = new PartVideo {
isPrimary = isPrimary,
vTypeID = vTypeID,
video = video,
partID = partID
};
db.PartVideos.InsertOnSubmit(v);
db.SubmitChanges();
}
ProductModels.UpdatePart(partID);
} catch {
return "error";
}
return JsonConvert.SerializeObject(Get(v.pVideoID));
}
示例2: AddDiscussionAjax
public string AddDiscussionAjax(int topicid = 0, string addtitle = "", string post = "", string name = "", string email = "", string company = "", bool notify = false, string recaptcha_challenge_field = "", string recaptcha_response_field = "")
{
CurtDevDataContext db = new CurtDevDataContext();
JavaScriptSerializer js = new JavaScriptSerializer();
#region trycatch
try {
string remoteip = (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) ? Request.ServerVariables["HTTP_X_FORWARDED_FOR"] : Request.ServerVariables["REMOTE_ADDR"];
if (!(Models.ReCaptcha.ValidateCaptcha(recaptcha_challenge_field, recaptcha_response_field, remoteip))) {
throw new Exception("The Captcha was incorrect. Try again please!");
}
if (topicid == 0) { throw new Exception("The topic was invalid."); }
if (addtitle.Trim() == "") { throw new Exception("Title is required."); }
if (post.Trim() == "") { throw new Exception("Post is required"); }
if (email.Trim() != "" && (!IsValidEmail(email.Trim()))) { throw new Exception("Your email address was not a valid address."); }
if (notify == true && email.Trim() == "") { throw new Exception("You cannot be notified by email without an email address."); }
if(checkIPAddress(remoteip)) { throw new Exception("You cannot post because your IP Address is blocked by our server."); }
bool moderation = Convert.ToBoolean(ConfigurationManager.AppSettings["ForumModeration"]);
ForumThread t = new ForumThread {
topicID = topicid,
active = true,
closed = false,
createdDate = DateTime.Now,
};
db.ForumThreads.InsertOnSubmit(t);
db.SubmitChanges();
ForumPost p = new ForumPost {
threadID = t.threadID,
title = addtitle,
post = post,
name = name,
email = email,
notify = notify,
approved = !moderation,
company = company,
createdDate = DateTime.Now,
flag = false,
active = true,
IPAddress = remoteip,
parentID = 0,
sticky = false
};
db.ForumPosts.InsertOnSubmit(p);
db.SubmitChanges();
Post newpost = ForumModel.GetPost(p.postID);
return js.Serialize(newpost);
} catch (Exception e) {
return "{\"error\": \"" + e.Message + "\"}";
}
#endregion
}
示例3: DeleteType
public static void DeleteType(int id = 0)
{
CurtDevDataContext db = new CurtDevDataContext();
IEnumerable<ContactReceiver_ContactType> types = db.ContactReceiver_ContactTypes.Where(x => x.contactTypeID == id).ToList<ContactReceiver_ContactType>();
db.ContactReceiver_ContactTypes.DeleteAllOnSubmit(types);
db.SubmitChanges();
ContactType type = db.ContactTypes.Where(x => x.contactTypeID == id).Single<ContactType>();
db.ContactTypes.DeleteOnSubmit(type);
db.SubmitChanges();
}
示例4: AddReceiver
public ActionResult AddReceiver()
{
string error = "";
CurtDevDataContext db = new CurtDevDataContext();
#region Form Submission
try {
if (Request.Form.Count > 0) {
// Save form values
string first_name = (Request.Form["first_name"] != null) ? Request.Form["first_name"] : "";
string last_name = (Request.Form["last_name"] != null) ? Request.Form["last_name"] : "";
string email = (Request.Form["email"] != null) ? Request.Form["email"] : "";
List<string> types = (Request.Form["types"] != null) ? Request.Form["types"].Split(',').ToList<string>() : new List<string>();
// Validate the form fields
if (email.Length == 0) throw new Exception("Email is required.");
if (types.Count() == 0) throw new Exception("At least one Receiver Type is required.");
// Create the new customer and save
ContactReceiver new_receiver = new ContactReceiver {
first_name = first_name,
last_name = last_name,
email = email
};
db.ContactReceivers.InsertOnSubmit(new_receiver);
db.SubmitChanges();
if (types.Count() > 0) {
foreach (string type in types) {
if (type != "") {
try {
ContactReceiver_ContactType rectype = new ContactReceiver_ContactType {
contactReceiverID = new_receiver.contactReceiverID,
contactTypeID = Convert.ToInt32(type)
};
db.ContactReceiver_ContactTypes.InsertOnSubmit(rectype);
} catch { }
}
}
}
db.SubmitChanges();
return RedirectToAction("Receivers");
}
} catch (Exception e) {
error = e.Message;
}
#endregion
ViewBag.types = ContactModel.GetTypes();
ViewBag.error = error;
return View();
}
示例5: Add
public static string Add(int partID = 0, int rating = 0, string subject = "", string review_text = "", string name = "", string email = "", int reviewID = 0)
{
if (partID == 0 || review_text.Length == 0) {
return "{\"error\":\"Invalid data.\"}";
}
try {
CurtDevDataContext db = new CurtDevDataContext();
Review r = new Review();
if (reviewID == 0) {
// Create new review
r = new Review {
partID = partID,
rating = rating,
subject = subject,
review_text = review_text,
name = name,
email = email,
createdDate = DateTime.Now,
approved = false,
active = true,
cust_id = 1
};
db.Reviews.InsertOnSubmit(r);
db.SubmitChanges();
} else {
r = (from rev in db.Reviews
where rev.reviewID.Equals(reviewID)
select rev).FirstOrDefault<Review>();
r.name = name;
r.review_text = review_text;
r.rating = rating;
r.subject = subject;
r.email = email;
db.SubmitChanges();
}
r = Get(r.reviewID);
try {
ProductModels.UpdatePart((int)r.partID);
} catch { }
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize(r);
} catch (Exception e) {
return "{\"error\":\"" + e.Message + "\"}";
}
}
示例6: AddPost
public ActionResult AddPost(int id = 0, string titlestr = "", string post = "", bool sticky = false)
{
string remoteip = (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) ? Request.ServerVariables["HTTP_X_FORWARDED_FOR"] : Request.ServerVariables["REMOTE_ADDR"];
try {
if (id == 0) throw new Exception("Topic is required.");
if (titlestr.Trim().Length == 0) throw new Exception("Title is required.");
if (post.Trim().Length == 0) throw new Exception("Post content is required.");
CurtDevDataContext db = new CurtDevDataContext();
ForumThread t = new ForumThread {
topicID = id,
active = true,
closed = false,
createdDate = DateTime.Now
};
db.ForumThreads.InsertOnSubmit(t);
db.SubmitChanges();
user u = Users.GetUser(Convert.ToInt32(Session["userID"]));
ForumPost p = new ForumPost {
threadID = t.threadID,
title = titlestr,
post = post,
IPAddress = remoteip,
createdDate = DateTime.Now,
approved = true,
active = true,
flag = false,
notify = false,
parentID = 0,
name = u.fname + " " + u.lname,
company = "CURT Manufacturing",
email = u.email,
sticky = sticky
};
db.ForumPosts.InsertOnSubmit(p);
db.SubmitChanges();
return RedirectToAction("threads", new { id = id });
} catch (Exception e) {
FullTopic topic = ForumModel.GetTopic(id);
ViewBag.topic = topic;
ViewBag.error = e.Message;
ViewBag.titlestr = titlestr;
ViewBag.post = post;
ViewBag.sticky = sticky;
return View();
}
}
示例7: Save
public ActionResult Save(int id = 0, string question = "", string answer = "")
{
try {
if (question.Length == 0) { throw new Exception("You must enter a question"); }
if (answer.Length == 0) { throw new Exception("You must enter an answer"); }
CurtDevDataContext db = new CurtDevDataContext();
if (id == 0) {
FAQ faq = new FAQ {
answer = answer,
question = question
};
db.FAQs.InsertOnSubmit(faq);
} else {
FAQ faq = db.FAQs.Where(x => x.faqID == id).FirstOrDefault<FAQ>();
faq.question = question;
faq.answer = answer;
}
db.SubmitChanges();
return RedirectToAction("Index");
} catch (Exception e) {
if (id == 0) {
return RedirectToAction("Add", new { err = e.Message, q = question, a = answer });
} else {
return RedirectToAction("Edit", new { id = id, err = e.Message, q = question, a = answer });
}
}
}
示例8: AddImage
public static string AddImage(int partID = 0, int sizeid = 0, string webfile = "", string localfile = "")
{
try {
CurtDevDataContext db = new CurtDevDataContext();
JavaScriptSerializer js = new JavaScriptSerializer();
char sort = 'a';
try {
sort = db.PartImages.Where(x => x.partID.Equals(partID)).Where(x => x.sizeID.Equals(sizeid)).OrderByDescending(x => x.sort).Select(x => x.sort).First<char>();
sort = GetNextLetter(sort.ToString());
} catch {};
System.Drawing.Image img = System.Drawing.Image.FromFile(localfile);
PartImage image = new PartImage {
partID = partID,
sizeID = sizeid,
path = webfile,
height = img.Height,
width = img.Width,
sort = sort
};
img.Dispose();
db.PartImages.InsertOnSubmit(image);
db.SubmitChanges();
return js.Serialize(image);
} catch {
return "error";
}
}
示例9: Create
public static FullVideo Create(Google.YouTube.Video ytVideo = null)
{
if (ytVideo == null) {
throw new Exception("Invalid link");
}
CurtDevDataContext db = new CurtDevDataContext();
Video new_video = new Video {
embed_link = ytVideo.VideoId,
title = ytVideo.Title,
screenshot = (ytVideo.Thumbnails.Count > 0) ? ytVideo.Thumbnails[2].Url : "/Content/img/noimage.jpg",
description = ytVideo.Description,
watchpage = ytVideo.WatchPage.ToString(),
youtubeID = ytVideo.VideoId,
dateAdded = DateTime.Now,
sort = (db.Videos.Count() == 0) ? 1 : db.Videos.OrderByDescending(x => x.sort).Select(x => x.sort).First() + 1
};
db.Videos.InsertOnSubmit(new_video);
db.SubmitChanges();
FullVideo fullvideo = new FullVideo {
videoID = new_video.videoID,
embed_link = new_video.embed_link,
dateAdded = new_video.dateAdded,
sort = new_video.sort,
videoTitle = new_video.title,
thumb = (ytVideo.Thumbnails.Count > 0) ? ytVideo.Thumbnails[0].Url : "/Content/img/noimage.jpg"
};
return fullvideo;
}
示例10: AddCategoryToPart
public static string AddCategoryToPart(int catID = 0, int partID = 0)
{
if (catID == 0 || partID == 0) { return "Invalid parameters."; }
try {
CurtDevDataContext db = new CurtDevDataContext();
// Make sure this category isn't already tied to this product
int existing = (from cp in db.CatParts
where cp.catID.Equals(catID) && cp.partID.Equals(partID)
select cp).Count();
if (existing > 0) { return "The association exists."; }
CatParts cat_part = new CatParts {
catID = catID,
partID = partID
};
db.CatParts.InsertOnSubmit(cat_part);
db.SubmitChanges();
UpdatePart(partID);
} catch (Exception e) {
return e.Message;
}
return "";
}
示例11: AddNews
public ActionResult AddNews(int displayOrder = 0, string title = "", string pageContent = "", string subTitle = "", string isActive = "", string showDealers = "", string showPublic = "")
{
try {
TechNews item = new TechNews();
Boolean blnIsActive = false;
blnIsActive = (isActive == "on") ? true : false;
Boolean blnShowPublic = false;
blnShowPublic = (showPublic == "on") ? true : false;
Boolean blnShowDealers = false;
blnShowDealers = (showDealers == "on") ? true : false;
item.title = title;
item.pageContent = pageContent;
item.subTitle = subTitle;
item.displayOrder = displayOrder;
item.active = blnIsActive;
item.showDealers = blnShowDealers;
item.showPublic = blnShowPublic;
item.dateModified = DateTime.Now;
ViewBag.item = item;
CurtDevDataContext db = new CurtDevDataContext();
db.TechNews.InsertOnSubmit(item);
db.SubmitChanges();
return RedirectToAction("News", new { successMsg = "The news item was successfully added." });
}
catch (Exception e) {
ViewBag.error = "Could not add news item: " + e.Message;
}
return View();
}
示例12: AddType
public ActionResult AddType()
{
string error = "";
CurtDevDataContext db = new CurtDevDataContext();
#region Form Submission
try {
if (Request.Form.Count > 0) {
// Save form values
string fileType = (Request.Form["fileType"] != null) ? Request.Form["fileType"] : "";
// Validate the form fields
if (fileType.Length == 0) throw new Exception("Name is required.");
// Create the new customer and save
FileType new_type = new FileType {
fileType1 = fileType
};
db.FileTypes.InsertOnSubmit(new_type);
db.SubmitChanges();
return RedirectToAction("Types");
}
} catch (Exception e) {
error = e.Message;
}
#endregion
ViewBag.error = error;
return View();
}
示例13: DeleteCategory
/// <summary>
/// Delete the given category from the database and break relationship to any parts.
/// </summary>
/// <param name="catID">ID of the category</param>
/// <returns>Error message (string)</returns>
public static string DeleteCategory(int catID = 0)
{
if (catID == 0) { throw new Exception("There was error while processing. Category data is invalid."); }
try {
CurtDevDataContext db = new CurtDevDataContext();
Categories cat = (from c in db.Categories
where c.catID.Equals(catID)
select c).FirstOrDefault<Categories>();
db.Categories.DeleteOnSubmit(cat);
List<ContentBridge> bridges = db.ContentBridges.Where(x => x.catID.Equals(catID)).ToList<ContentBridge>();
List<int> contentids = bridges.Select(x => x.contentID).ToList();
List<Content> contents = db.Contents.Where(x => contentids.Contains(x.contentID)).ToList<Content>();
db.ContentBridges.DeleteAllOnSubmit(bridges);
db.Contents.DeleteAllOnSubmit(contents);
// Remove the CatPart relationships for this category
List<CatParts> cp = (from cat_parts in db.CatParts
where cat_parts.catID.Equals(catID)
select cat_parts).ToList<CatParts>();
db.CatParts.DeleteAllOnSubmit<CatParts>(cp);
db.SubmitChanges();
} catch (Exception e) {
return e.Message;
}
return "";
}
示例14: Send
public static bool Send(Contact contact)
{
try {
CurtDevDataContext db = new CurtDevDataContext();
SmtpClient SmtpServer = new SmtpClient();
List<ContactReceiver> receivers = (from cr in db.ContactReceivers
join crt in db.ContactReceiver_ContactTypes on cr.contactReceiverID equals crt.contactReceiverID
join ct in db.ContactTypes on crt.contactTypeID equals ct.contactTypeID
where ct.name.ToLower().Trim().Equals(contact.type.ToLower().Trim())
select cr).ToList<ContactReceiver>();
if (receivers.Count() == 0) {
receivers = db.ContactReceivers.ToList<ContactReceiver>();
}
db.Contacts.InsertOnSubmit(contact);
db.SubmitChanges();
foreach (ContactReceiver receiver in receivers) {
MailMessage mail = new MailMessage();
mail.To.Add(receiver.email);
mail.Subject = "New Website Contact: " + contact.subject;
mail.IsBodyHtml = true;
string mailhtml = contact.first_name + " " + contact.last_name + " said: " + contact.message;
string mailto = "mailto" + ":" + contact.email + "?subject=Re: " + contact.subject + "&body=" + mailhtml;
string htmlBody = "<p>Hi " + receiver.first_name + ",</p>";
htmlBody += "<p>We've received a new web contact.<br /><a style=\"border: 2px solid #e64d2d; text-transform: uppercase; color: #e64d2d; font-weight: bold; padding: 2px 6px; font-size: 14px; text-decoration: none;\" href=\"" + mailto + "\">Click to Reply</a></p>";
htmlBody += "<table><tr><td style=\"vertical-align: top;\"><strong>Name: </strong></td><td>" + contact.first_name + " " + contact.last_name + "</td></tr>";
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Reason: </strong></td><td>" + contact.type + "</td></tr>";
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Email: </strong></td><td>" + contact.email + "</td></tr>";
if (contact.phone != "") {
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Phone: </strong></td><td>" + contact.phone + "</td></tr>";
}
if (contact.address1 != "") {
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Address1: </strong></td><td>" + contact.address1 + "</td></tr>";
}
if (contact.address2 != "") {
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Address2: </strong></td><td>" + contact.address2 + "</td></tr>";
}
if (contact.city != "") {
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>City: </strong></td><td>" + contact.city + "</td></tr>";
}
if (contact.state != "") {
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>State / Province: </strong></td><td>" + contact.state + "</td></tr>";
}
if (contact.postalcode != "") {
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Postal Code: </strong></td><td>" + contact.postalcode + "</td></tr>";
}
if (contact.country != "") {
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Country: </strong></td><td>" + contact.country + "</td></tr>";
}
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Subject: </strong></td><td>" + contact.subject + "</td></tr>";
htmlBody += "<tr><td style=\"vertical-align: top;\"><strong>Message: </strong></td><td>" + contact.message + "</td></tr></table>";
mail.Body = htmlBody;
SmtpServer.Send(mail);
}
return true;
} catch { return false; }
}
示例15: Add
public ActionResult Add(int partID = 0, string shortDesc = "", int status = 0, string oldPartNumber = "", int priceCode = 0, int classID = 0, string btnSubmit = "", string btnContinue = "", string upc = "", bool featured = false, int? ACESPartTypeID = null)
{
CurtDevDataContext db = new CurtDevDataContext();
List<string> error_messages = new List<string>();
Part new_part = new Part{
partID = partID,
shortDesc = shortDesc,
status = status,
oldPartNumber = oldPartNumber,
priceCode = priceCode,
classID = classID,
dateAdded = DateTime.Now,
dateModified = DateTime.Now,
featured = featured,
ACESPartTypeID = ACESPartTypeID
};
// Validate the partID and shortDesc fields
if(partID == 0){ error_messages.Add("You must enter a part number."); }
if(shortDesc.Length == 0){ error_messages.Add("You must enter a short description."); }
if (upc.Trim().Length == 0) { error_messages.Add("You must enter a UPC."); }
int existing_part = 0;
// Make sure we don't have a product with this partID
existing_part = (from p in db.Parts
where p.partID.Equals(partID)
select p).Count();
if (existing_part != 0) { error_messages.Add("This part number exists."); }
if (error_messages.Count == 0) { // No errors, add the part
try {
db.Parts.InsertOnSubmit(new_part);
db.SubmitChanges();
ProductModels.SaveAttribute(0,new_part.partID, "UPC", upc);
db.indexPart(new_part.partID);
if (btnContinue != "") { // Redirect to add more part information
return RedirectToAction("edit", new { partID = new_part.partID });
} else { // Redirect to product index page
return RedirectToAction("index");
}
} catch (Exception e) {
error_messages.Add(e.Message);
}
}
ViewBag.error_messages = error_messages;
// Get all the parts in the database :: This will allow the user to create related parts
ViewBag.parts = ProductModels.GetAllParts();
// Get the product classes
ViewBag.classes = ProductModels.GetClasses();
return View();
}