本文整理汇总了C#中DataConnection.CreateNew方法的典型用法代码示例。如果您正苦于以下问题:C# DataConnection.CreateNew方法的具体用法?C# DataConnection.CreateNew怎么用?C# DataConnection.CreateNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataConnection
的用法示例。
在下文中一共展示了DataConnection.CreateNew方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Rate
public string Rate(string score, string ratyId)
{
Guid ratyGuid = Guid.Parse(ratyId);
using (DataConnection conn = new DataConnection())
{
var ratyItem = conn.Get<Results>().Where(r => r.RatyId == ratyGuid).SingleOrDefault();
if (ratyItem != null)
{
ratyItem.Count += 1;
ratyItem.TotalValue = ratyItem.TotalValue + decimal.Parse(score, System.Globalization.CultureInfo.InvariantCulture);
conn.Update<Results>(ratyItem);
}
else
{
ratyItem = conn.CreateNew<Results>();
ratyItem.RatyId = ratyGuid;
ratyItem.Count = 1;
ratyItem.TotalValue = decimal.Parse(score, System.Globalization.CultureInfo.InvariantCulture);
conn.Add<Results>(ratyItem);
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
var data = new { TotalValue = ratyItem.TotalValue, Count = ratyItem.Count };
SetCookie(ratyId);
return serializer.Serialize(data);
}
}
示例2: SaveBrokenLink
public static XhtmlDocument SaveBrokenLink()
{
var request = HttpContext.Current.Request;
// ignore if referer is empty
if (request.UrlReferrer == null
|| request.RawUrl.StartsWith("/Composite/content/flow/FlowUi.aspx", StringComparison.InvariantCultureIgnoreCase)
|| request.UrlReferrer.ToString().IndexOf("/Composite/content/views/browser/browser.aspx", StringComparison.InvariantCultureIgnoreCase) > 0)
{
return null;
}
var url = "http://" + request.Url.Host + request.RawUrl;
using (var dataConnection = new DataConnection())
{
var sitemapNavigator = new SitemapNavigator(dataConnection);
if (sitemapNavigator.CurrentPageNode != null && request.RawUrl.Equals(sitemapNavigator.CurrentPageNode.Url))
return null;
}
var referer = (request.UrlReferrer == null) ? "" : request.UrlReferrer.ToString();
var userAgent = request.UserAgent ?? string.Empty;
var ipAddress = GetIPAddress(request);
if (!UserAgentIsTrusted(userAgent)
|| !RefererIsTrusted(referer)
|| IPAddressIsInBlackList(ipAddress))
{
return null;
}
using (var conn = new DataConnection())
{
var item = conn.Get<BrokenLink>().FirstOrDefault(el => el.BadURL == url);
if (item == null)
{
var newItem = conn.CreateNew<BrokenLink>();
newItem.Id = Guid.NewGuid();
newItem.BadURL = url;
newItem.Referer = referer;
newItem.UserAgent = userAgent;
newItem.IP = ipAddress;
newItem.Date = DateTime.Now;
conn.Add<BrokenLink>(newItem);
}
}
return null;
}
示例3: SavePageContent
public string SavePageContent(string pageId, string placeholderId, string content)
{
Guid pageGuid = Guid.Parse(pageId);
string contentHtml = HttpUtility.UrlDecode(content);
contentHtml = HttpUtility.HtmlDecode(contentHtml.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;"));
string xhtmlDocumentWrapper = string.Format("<html xmlns='http://www.w3.org/1999/xhtml'><head></head><body>{0}</body></html>", contentHtml);
XElement xElement = XElement.Parse(xhtmlDocumentWrapper);
RemoveInvalidElements(xElement);
contentHtml = string.Concat((xElement.Elements().Select(b => b.ToString())).ToArray());
foreach (PublicationScope scope in Enum.GetValues(typeof(PublicationScope)))
{
using (DataConnection connection = new DataConnection(scope))
{
var phHolder = Composite.Data.PageManager.GetPlaceholderContent(pageGuid).Where(ph => ph.PlaceHolderId == placeholderId).SingleOrDefault();
if (phHolder != null)
{
phHolder.Content = contentHtml;
connection.Update<IPagePlaceholderContent>(phHolder);
}
else
{
var page = connection.Get<IPage>().Where(p => p.Id == pageGuid).SingleOrDefault();
var templateInfo = TemplateInfo.GetRenderingPlaceHolders(page.TemplateId);
foreach (var ph in templateInfo.Placeholders)
{
if (ph.Key == placeholderId)
{
IPagePlaceholderContent newPh = connection.CreateNew<IPagePlaceholderContent>();
newPh.PageId = pageGuid;
newPh.PlaceHolderId = placeholderId;
newPh.Content = contentHtml;
connection.Add<IPagePlaceholderContent>(newPh);
}
}
}
}
}
return "Success";
}
示例4: Send
public static IEnumerable<XElement> Send(string fromName, string fromEmail, string toEmail, string messageSubject, string message, string company, string website, string address, string phonenumber, string captcha, string captchaEncryptedValue, bool useCaptcha, Guid emailTemplateId)
{
var catpchaIsValid = useCaptcha ? Captcha.IsValid(captcha, captchaEncryptedValue) : true;
#region SubmittedData
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "fromName"),
new XAttribute("Value", fromName));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "fromEmail"),
new XAttribute("Value", fromEmail));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "toEmail"),
new XAttribute("Value", toEmail));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "messageSubject"),
new XAttribute("Value", messageSubject));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "message"),
new XAttribute("Value", message));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "company"),
new XAttribute("Value", company));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "website"),
new XAttribute("Value", website));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "address"),
new XAttribute("Value", address));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "phonenumber"),
new XAttribute("Value", phonenumber));
#endregion
#region Check Errors
if (!catpchaIsValid || string.IsNullOrEmpty(fromName) || string.IsNullOrEmpty(message) || !Regex.IsMatch(fromEmail, EmailPattern, RegexOptions.IgnoreCase))
{
var errorText = new Hashtable();
if (string.IsNullOrEmpty(fromName))
{
errorText.Add("fromName", GetLocalized("ContactForm", "emptyFromNameError"));
}
if (string.IsNullOrEmpty(message))
{
errorText.Add("message", GetLocalized("ContactForm", "emptyMessageError"));
}
if (!Regex.IsMatch(fromEmail, EmailPattern, RegexOptions.IgnoreCase))
{
errorText.Add("fromEmail", GetLocalized("ContactForm", "incorrectEmailError"));
}
if (!catpchaIsValid)
{
errorText.Add("captcha", GetLocalized("ContactForm", "incorrectCaptchaError"));
}
foreach (string key in errorText.Keys)
{
yield return new XElement("Error",
new XAttribute("Fieldname", key),
new XAttribute("ErrorDescription", errorText[key].ToString()));
}
}
#endregion
#region Save data and send Email
else
{
using (DataConnection con = new DataConnection())
{
var newContactFormData = con.CreateNew<ContactFormData>();
newContactFormData.Id = Guid.NewGuid();
newContactFormData.PageId = SitemapNavigator.CurrentPageId;
newContactFormData.Name = fromName;
newContactFormData.Email = fromEmail;
newContactFormData.Subject = messageSubject;
newContactFormData.Message = message;
newContactFormData.IP = HttpContext.Current.Request.UserHostName;
newContactFormData.Date = DateTime.Now;
newContactFormData.Company = company;
newContactFormData.Website = website;
newContactFormData.Address = address;
newContactFormData.PhoneNumber = phonenumber;
con.Add<ContactFormData>(newContactFormData);
#region Send Email
// Get Email template and fill it with item fields values.
var emailTemplate = con.Get<EmailTemplate>().Where(e => e.Id == emailTemplateId).SingleOrDefault();
if (emailTemplate != null)
{
try
{
XDocument document = ResolveFields(newContactFormData, emailTemplate);
var subject = string.Format("{0}: {1}", emailTemplate.Subject, (messageSubject != string.Empty ? messageSubject : fromName));
SendEmail(fromName, fromEmail, "", toEmail, subject, document.ToString());
}
catch (Exception ex)
//.........这里部分代码省略.........
示例5: SaveComment
public static IEnumerable<XElement> SaveComment(string name, string email, string commentTitle, string commentText, string Captcha)
{
var currentPageId = SitemapNavigator.CurrentPageId;
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "Name"),
new XAttribute("Value", name));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "Email"),
new XAttribute("Value", email));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "CommentTitle"),
new XAttribute("Value", commentTitle));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "CommentText"),
new XAttribute("Value", commentText));
yield return new XElement("SubmittedData",
new XAttribute("Fieldname", "Captcha"),
new XAttribute("Value", Captcha));
// Input error ?
if (Captcha != "true" || string.IsNullOrEmpty(name) || !Validate(RegExpLib.Email, email, true) || string.IsNullOrEmpty(commentTitle) || string.IsNullOrEmpty(commentText))
{
var errorText = new Hashtable();
if (Captcha != "true")
{
errorText.Add("Captcha", "Incorrect Captcha value");
}
if (string.IsNullOrEmpty(name))
{
errorText.Add("Name", "Incorrect Name value");
}
if (!Validate(RegExpLib.Email, email, true))
{
errorText.Add("Email", "Incorrect E-mail value");
}
if (string.IsNullOrEmpty(commentTitle))
{
errorText.Add("Title", "Incorrect Title value");
}
if (string.IsNullOrEmpty(commentText))
{
errorText.Add("Comment", "Incorrect Comment value");
}
foreach (string key in errorText.Keys)
{
yield return new XElement("Error",
new XAttribute("Fieldname", key),
new XAttribute("ErrorDescription", errorText[key].ToString()));
}
}
else
{
using (DataConnection conn = new DataConnection())
{
var currentPage = conn.Get<IPage>().Where(p => p.Id == currentPageId).SingleOrDefault();
if (!currentPage.GetDefinedFolderTypes().Contains(typeof(Item)))
{
currentPage.AddFolderDefinition(typeof(Item).GetImmutableTypeId());
}
//add data
var commentItem = conn.CreateNew<Item>();
commentItem.Name = name;
commentItem.Email = email;
commentItem.Title = commentTitle;
commentItem.Date = DateTime.Now;
commentItem.Comment = commentText;
PageFolderFacade.AssignFolderDataSpecificValues(commentItem, currentPage);
conn.Add<Item>(commentItem);
// Redirect to view newly added comment
string pageUrl;
var found = PageStructureInfo.TryGetPageUrl(currentPageId, out pageUrl);
if (found)
{
PrepareMail(currentPageId, pageUrl, name, email, commentTitle, commentText, DateTime.Now.ToString());
HttpContext.Current.Response.Redirect(pageUrl, false);
}
}
}
}