当前位置: 首页>>代码示例>>C#>>正文


C# DataConnection.Add方法代码示例

本文整理汇总了C#中DataConnection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# DataConnection.Add方法的具体用法?C# DataConnection.Add怎么用?C# DataConnection.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataConnection的用法示例。


在下文中一共展示了DataConnection.Add方法的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);
				}
			
		}
开发者ID:JustAndrei,项目名称:C1-Packages,代码行数:30,代码来源:Raty.cs

示例2: PostProduct

        // Adding a new product
        public Product PostProduct(Product product)
        {
            using (var c = new DataConnection())
            {
                product.Id = Guid.NewGuid();

                return c.Add(product);
            }
        }
开发者ID:portal7,项目名称:CompositeC1-WebAPI_Demo,代码行数:10,代码来源:ProductController.cs

示例3: CreateNewTemplate

 public static void CreateNewTemplate(Guid gTemplateGuid, string sTitle)
 {
     using (DataConnection connection = new DataConnection())
     {
         IXmlPageTemplate data = DataConnection.New<IXmlPageTemplate>();
         data.Id = gTemplateGuid;
         data.Title = sTitle;
         data.PageTemplateFilePath = String.Format("/{0}.xml", sTitle);
         connection.Add<IXmlPageTemplate>(data);
     }
 }
开发者ID:moljac,项目名称:HolisticWareFtCompositeC1,代码行数:11,代码来源:News.asmx.cs

示例4: 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;
		}
开发者ID:JustAndrei,项目名称:C1-Packages,代码行数:47,代码来源:Functions.cs

示例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;", "&amp;amp;").Replace("&lt;", "&amp;lt;").Replace("&gt;", "&amp;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";
		}
开发者ID:JustAndrei,项目名称:C1-Packages,代码行数:42,代码来源:SimpleWiki.cs

示例6: 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)
//.........这里部分代码省略.........
开发者ID:BeatriceCarrington,项目名称:Interior,代码行数:101,代码来源:Functions.cs

示例7: 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);
					}
				}
			}
		}
开发者ID:JustAndrei,项目名称:C1-Packages,代码行数:88,代码来源:Comments.cs

示例8: 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);
                }
            }
        }
开发者ID:DBailey635,项目名称:C1-CMS,代码行数:35,代码来源:DataBasedFormLoginProvider.cs


注:本文中的DataConnection.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。