本文整理汇总了C#中DataConnection.Update方法的典型用法代码示例。如果您正苦于以下问题:C# DataConnection.Update方法的具体用法?C# DataConnection.Update怎么用?C# DataConnection.Update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataConnection
的用法示例。
在下文中一共展示了DataConnection.Update方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: httpApplication_BeginRequest
static void httpApplication_BeginRequest(object sender, EventArgs e)
{
var httpApplication = (HttpApplication)sender;
var incomingUrlPath = HttpUtility.UrlDecode(httpApplication.Context.Request.Url.PathAndQuery.TrimEnd(new[] { '/' }));
try
{
if (httpApplication.Request.Url.AbsolutePath.StartsWith("/Composite",
StringComparison.InvariantCultureIgnoreCase))
{
// Let's leave Composite alone so the user aren't able to lock themselves out of the console.
return;
}
else if (httpApplication.Request.Url.AbsolutePath == "/UrlAlias/Preview")
{
var location = HttpUtility.UrlDecode(httpApplication.Request["p"]);
httpApplication.Response.Redirect(location, false);
}
else
{
using (var conn = new DataConnection())
{
var matchingUrlAlias =
conn.Get<IUrlAlias>()
.SingleOrDefault(x => x.UrlAlias.ToLower() == incomingUrlPath.ToLower());
if (matchingUrlAlias != null
&& matchingUrlAlias.Enabled
&& (matchingUrlAlias.Hostname == Guid.Empty || conn.Get<IHostnameBinding>()
.Single(x => x.Id == matchingUrlAlias.Hostname).Hostname == httpApplication.Request.Url.Host))
{
matchingUrlAlias.LastUse = DateTime.Now;
matchingUrlAlias.UseCount++;
conn.Update(matchingUrlAlias);
httpApplication.Response.Clear();
httpApplication.Response.StatusCode = matchingUrlAlias.HttpStatusCode;
httpApplication.Response.RedirectLocation = matchingUrlAlias.RedirectLocation;
httpApplication.Response.End();
}
}
}
}
catch (ThreadAbortException ex)
{
// Do nothing, this is expected
}
catch (Exception ex)
{
LoggingService.LogError("Url Aliases", ex);
}
}
示例3: PutProduct
// Updating an existing Product
public void PutProduct(Guid id, Product productJson)
{
using (var c = new DataConnection())
{
var product = c.Get<Product>().FirstOrDefault(p => p.Id == id);
if (product == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
product.Title = productJson.Title;
product.Price = productJson.Price;
c.Update(product);
}
}
示例4: Install
public override IEnumerable<XElement> Install()
{
var usersNames = new[] { "developer", "advuser", "enduser" };
using (var conn = new DataConnection())
{
var userSettings = conn.Get<IUserSettings>().Where(us => usersNames.Contains(us.Username));
var culture = DataConnection.AllLocales.First();
foreach (var setting in userSettings)
{
setting.CultureName = culture.Name;
setting.C1ConsoleUiLanguage = culture.Name;
setting.CurrentActiveLocaleCultureName = culture.Name;
setting.ForeignLocaleCultureName = culture.Name;
}
conn.Update<IUserSettings>(userSettings);
}
yield return new XElement("FixUserSettings", usersNames);
}
示例5: 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";
}
示例6: Execute
//.........这里部分代码省略.........
}
case "DataConnectionFact":
{
var fact = currentFact as DataConnectionFact;
var conn = new SqlConnection(fact.ConnectionString);
conn.Open();
var dc = new DataConnection(fact.Dataset, fact.TableName, conn);
facts[i] = dc;
break;
}
case "dataTable":
case "dataRow":
{
var fact = currentFact as DataTableFact;
var dAdapt = new SqlDataAdapter();
dAdapt.TableMappings.Add("Table", fact.TableName);
var conn = new SqlConnection(fact.ConnectionString);
conn.Open();
var myCommand = new SqlCommand(fact.Command, conn) {CommandType = CommandType.Text};
dAdapt.SelectCommand = myCommand;
var ds = new DataSet(fact.Dataset);
dAdapt.Fill(ds);
var tdt = new TypedDataTable(ds.Tables[fact.TableName]);
if (fact.Type == "dataRow")
{
var tdr = new TypedDataRow(ds.Tables[fact.TableName].Rows[0], tdt);
facts[i] = tdr;
}
else
{
facts[i] = tdt;
}
break;
}
}
i++;
}
// Execute Policy Tester
try
{
policyTester.Execute(facts, dti);
}
catch (Exception e)
{
context.LogException(e);
throw;
}
finally
{
dti.CloseTraceFile();
}
// write out all document instances passed in
foreach (object fact in facts)
{
switch (fact.GetType().Name)
{
case "TypedXmlDocument":
{
var txd = (TypedXmlDocument)fact;
context.LogData("TypedXmlDocument result: ", txd.Document.OuterXml);
Stream data = StreamHelper.LoadMemoryStream(txd.Document.OuterXml);
// Validate if configured...
// HACK: We need to prevent ExecuteValidator for /each/ TypedXmlDocument
if (txd.DocumentType == "UBS.CLAS.PoC.Schemas.INSERTS")
{
foreach (var subStep in SubSteps)
{
data = subStep.Execute(data, context);
}
}
break;
}
case "DataConnection":
{
var dc = (DataConnection)fact;
dc.Update(); // persist any changes
break;
}
case "TypedDataTable":
{
var tdt = (TypedDataTable)fact;
tdt.DataTable.AcceptChanges();
break;
}
case "TypedDataRow":
{
var tdr = (TypedDataRow)fact;
tdr.DataRow.AcceptChanges();
break;
}
}
}
}
示例7: MoveDataFromIUserToIUserFormLogin
private static void MoveDataFromIUserToIUserFormLogin()
{
using (var conn = new DataConnection())
{
var users = conn.Get<IUser>().ToList();
var existingUserLogins = new HashSet<Guid>(conn.Get<IUserFormLogin>().Select(l => l.UserId));
foreach (var user in users.Where(u => !existingUserLogins.Contains(u.Id)))
{
if (string.IsNullOrEmpty(user.PasswordHashSalt) && !string.IsNullOrEmpty(user.EncryptedPassword))
{
throw new InvalidOperationException("User password stored in old format");
}
var userFormLogin = DataConnection.New<IUserFormLogin>();
userFormLogin.UserId = user.Id;
userFormLogin.Folder = user.Group;
userFormLogin.IsLocked = user.IsLocked;
userFormLogin.LockoutReason = user.LockoutReason;
userFormLogin.PasswordHash = user.EncryptedPassword;
userFormLogin.PasswordHashSalt = user.PasswordHashSalt;
conn.Add(userFormLogin);
// Clear out old data
user.IsLocked = false;
user.LockoutReason = 0;
user.Group = null;
user.EncryptedPassword = null;
user.PasswordHashSalt = null;
conn.Update(user);
}
}
}
示例8: Send404MailReport
public static void Send404MailReport()
{
//var request = HttpContext.Current.Request;
using (var conn = new DataConnection())
{
var brokenLinks =
conn.Get<BrokenLink>().Where(link => link.IsNotified == false).ToList();
var brokenLinksIPs = brokenLinks.Select(bl => bl.IP).Distinct().ToList();
if (!brokenLinksIPs.Any()) return;
if (!Config.RecipientEmails.Any())
{
Log.LogInformation("Composite.Tools.LegacyUrlHandler.Send404Mails", "There are no recipients. Check out Config.xml file.");
return;
}
var emailBody = new StringBuilder();
var siteHostName = new System.Uri(brokenLinks.First().BadURL).Host;
var emailSubject = string.Format("Broken links report at {0}", siteHostName);
var emailRecipients = Config.RecipientEmails.Aggregate((i, j) => i + "; " + j);
emailBody.AppendFormat(@"<h2>{0}</h2> <h3>BAD URLs grouped by IP:</h3>", emailSubject);
brokenLinksIPs.ForEach(ip =>
{
emailBody.AppendFormat("<ul><li><b>{0}</b>", ip);
emailBody.Append("<ol>");
brokenLinks.Where(el => el.IP == ip).ToList().ForEach(link =>
{
emailBody.Append("<li>");
emailBody.AppendFormat("BAD URL: {0}<br/>", link.BadURL);
emailBody.AppendFormat("REFERER: {0}<br/>", link.Referer);
emailBody.AppendFormat("USER AGENT: {0}<br/>", link.UserAgent);
emailBody.AppendFormat("<a href='http://{0}/FixBrokenLink.aspx?badURL={1}'>FIX THIS URL >></a>", siteHostName, link.BadURL);
emailBody.Append("<br/><br/></li>");
link.IsNotified = true;
});
emailBody.Append("</ol>");
emailBody.Append("</li></ul>");
});
emailBody.AppendFormat(@"<p style='font-size: 12px; color: silver;'>Email was sent to: {0}</p>", emailRecipients);
Config.RecipientEmails.ForEach(recipient =>
{
SendMail(recipient, Config.FromEmail, emailSubject, emailBody.ToString());
});
conn.Update<BrokenLink>(brokenLinks);
Log.LogInformation("Composite.Tools.LegacyUrlHandler", "Broken URLs report was sent to " + emailRecipients);
}
}