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


C# Document.GetAncestorDocuments方法代码示例

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


在下文中一共展示了Document.GetAncestorDocuments方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DocumentAfterPublish

		protected void DocumentAfterPublish(Document sender, PublishEventArgs e)
		{
			// when thinking about adding something here, consider ContentOnAfterUpdateDocumentCache!

			if (sender.Level > 2)
			{
				if (sender.ContentType.Alias == Order.NodeAlias || sender.Parent != null && (OrderedProduct.IsAlias(sender.ContentType.Alias) || sender.Parent.Parent != null && OrderedProductVariant.IsAlias(sender.ContentType.Alias)))
				{
					var orderDoc = sender.ContentType.Alias == Order.NodeAlias ? sender : (OrderedProduct.IsAlias(sender.ContentType.Alias) && !OrderedProductVariant.IsAlias(sender.ContentType.Alias) ? new Document(sender.Parent.Id) : new Document(sender.Parent.Parent.Id));

					if (orderDoc.ContentType.Alias != Order.NodeAlias)
						throw new Exception("There was an error in the structure of the order documents");

					// load existing orderInfo (why..? => possibly to preserve information not represented in the umbraco documents)

					if (string.IsNullOrEmpty(orderDoc.getProperty("orderGuid").Value.ToString()))
					{
						Store store = null;
						var storeDoc = sender.GetAncestorDocuments().FirstOrDefault(x => x.ContentType.Alias == OrderStoreFolder.NodeAlias);

						if (storeDoc != null)
						{
							store = StoreHelper.GetAllStores().FirstOrDefault(x => x.Name == storeDoc.Text);
						}

						if (store == null)
						{
							store = StoreHelper.GetAllStores().FirstOrDefault();
						}

						var orderInfo = OrderHelper.CreateOrder(store);
						IO.Container.Resolve<IOrderNumberService>().GenerateAndPersistOrderNumber(orderInfo);
						orderInfo.Status = OrderStatus.Confirmed;
						orderInfo.Save();

						sender.SetProperty("orderGuid", orderInfo.UniqueOrderId.ToString());
						sender.Save();
					}
					else
					{
						var orderGuid = Guid.Parse(orderDoc.getProperty("orderGuid").Value.ToString());

						var orderInfo = OrderHelper.GetOrderInfo(orderGuid);

						var order = new Order(orderDoc.Id);
						orderInfo.CustomerEmail = order.CustomerEmail;
						orderInfo.CustomerFirstName = order.CustomerFirstName;
						orderInfo.CustomerLastName = order.CustomerLastName;

						var dictionaryCustomer = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("customer")).ToDictionary(customerProperty => customerProperty.PropertyType.Alias, customerProperty => customerProperty.Value.ToString());
						orderInfo.AddCustomerFields(dictionaryCustomer, CustomerDatatypes.Customer);

						var dictionaryShipping = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("shipping")).ToDictionary(property => property.PropertyType.Alias, property => property.Value.ToString());
						orderInfo.AddCustomerFields(dictionaryShipping, CustomerDatatypes.Shipping);

						var dictionarExtra = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("extra")).ToDictionary(property => property.PropertyType.Alias, property => property.Value.ToString());
						orderInfo.AddCustomerFields(dictionarExtra, CustomerDatatypes.Extra);

						//orderInfo.SetVATNumber(order.CustomerVATNumber); happens in AddCustomerFields
						var orderPaidProperty = order.Document.getProperty("orderPaid");
						if (orderPaidProperty != null && orderPaidProperty.Value != null)
							orderInfo.Paid = orderPaidProperty.Value == "1";

						// load data recursively from umbraco documents into order tree
						orderInfo.OrderLines = orderDoc.Children.Select(d =>
							{
								var fields = d.GenericProperties.Where(x => !OrderedProduct.DefaultProperties.Contains(x.PropertyType.Alias)).ToDictionary(s => s.PropertyType.Alias, s => d.GetProperty<string>(s.PropertyType.Alias));

								var xDoc = new XDocument(new XElement("Fields"));

								OrderUpdatingService.AddFieldsToXDocumentBasedOnCMSDocumentType(xDoc, fields, d.ContentType.Alias);

								var orderedProduct = new OrderedProduct(d.Id);

								var productInfo = new ProductInfo(orderedProduct, orderInfo);
								productInfo.ProductVariants = d.Children.Select(cd => new ProductVariantInfo(new OrderedProductVariant(cd.Id), productInfo, productInfo.Vat)).ToList();
								return new OrderLine(productInfo, orderInfo) {_customData = xDoc};
							}).ToList();

						// store order
						IO.Container.Resolve<IOrderRepository>().SaveOrderInfo(orderInfo);
					}
					// cancel does give a warning message balloon in Umbraco.
					//e.Cancel = true;

					//if (sender.ContentType.Alias != Order.NodeAlias)
					//{
					//	orderDoc.Publish(new User(0));
					//}

					//if (orderDoc.ParentId != 0)
					//{
					BasePage.Current.ClientTools.SyncTree(sender.Parent.Path, false);
					BasePage.Current.ClientTools.ChangeContentFrameUrl(string.Concat("editContent.aspx?id=", sender.Id));
					//}
					//orderDoc.delete();
					BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.success, "Order Updated!", "This order has been updated!");
				}
			}
		}
开发者ID:Chuhukon,项目名称:uWebshop-Releases,代码行数:100,代码来源:ApplicationEventHandler.cs


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