/// <summary>
        /// Handles the Click event of the SaveAndPublishButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void SaveAndPublishButton_Click(object sender, ImageClickEventArgs e)
        {
            //This is the real publication in Triphulcas:
            var currentPage = new Document(NodeFactory.Node.getCurrentNodeId());
            if (currentPage.getProperty("public") != null)
                currentPage.SetProperty("public", 1);

            // save and publish
            m_Manager.LiveEditingContext.Updates.SaveAll();
            m_Manager.LiveEditingContext.Updates.PublishAll();

            // disable Live Editing
            m_Manager.LiveEditingContext.Enabled = false;

            // show message to user
            m_Manager.DisplayUserMessage("Publicado!", "Tu basura ya es pública.", "info");

            // redirect to page (updates everything, and is necessary if the page name was changed)
            RefreshPage();
        }
        /// <summary>
        /// Handles the Click event of the SaveButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void SaveButton_Click(object sender, ImageClickEventArgs e)
        {
            //Standard:
            //m_Manager.LiveEditingContext.Updates.SaveAll();
            //m_Manager.DisplayUserMessage("Page saved", "The page was saved successfully. Remember to publish your changes.", "info");

            //This marks as "unpublished" in Triphulcas:
            var currentPage = new Document(NodeFactory.Node.getCurrentNodeId());
            if (currentPage.getProperty("public") != null)
            {
                currentPage.SetProperty("public", 0);

                //disable "unpublish" option:
                if (m_unpublishedButton != null)
                    m_Manager.LiveEditingContext.Menu.Remove(m_unpublishedButton);
            }

            //Save&Publish code:
            // save and publish
            m_Manager.LiveEditingContext.Updates.SaveAll();
            m_Manager.LiveEditingContext.Updates.PublishAll();

            // show message to user
            m_Manager.DisplayUserMessage("Artículo guardado", "Hemos guardado tu basura. Publícala para que se vea.", "info");

            // redirect to page (updates everything, and is necessary if the page name was changed)
            //RefreshPage();

        }
Exemple #3
0
        /// <summary>
        /// Handles the <c>MessageReceived</c> event of the Live Editing manager.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        protected override void Manager_MessageReceived(object sender, MesssageReceivedArgs e)
        {
            switch (e.Type)
            {
                case "unpublishcontent":
                    Document currentPage = new Document(int.Parse(UmbracoContext.Current.PageId.ToString()));
                    //library.UnPublishSingleNode(currentPage.Id);
                    //currentPage.UnPublish();

                    //Unpublish (triphulcas way)
                    currentPage.SetProperty("public", 0);

                    string redirectUrl = "/";
                    try
                    {
                        redirectUrl = library.NiceUrl(currentPage.Parent.Id);
                    }
                    catch
                    {
                    }

                    //disable live editing:
                    UmbracoContext.Current.LiveEditingContext.Enabled = false;

                    Page.Response.Redirect(redirectUrl);
                    break;
            }
        }
		/// <summary>
		///     Install a new uWebshop store
		/// </summary>
		/// <param name="storeAlias">the store alias to use</param>
		/// <param name="storeDocument">the document of the store</param>
		/// <param name="cultureCode"> </param>
		/// <param name="preFillRequiredItems"></param>
		internal static void InstallStore(string storeAlias, Document storeDocument, string cultureCode = null, bool preFillRequiredItems = false)
		{
			var reg = new Regex(@"\s*");
			storeAlias = reg.Replace(storeAlias, "");

			if (cultureCode == null)
			{
				var languages = Language.GetAllAsList();

				var firstOrDefaultlanguage = languages.FirstOrDefault();
				if (firstOrDefaultlanguage == null)
					return;
				cultureCode = firstOrDefaultlanguage.CultureAlias;
			}

			var installStoreSpecificPropertiesOnDocumentTypes = WebConfigurationManager.AppSettings["InstallStoreDocumentTypes"];

			if (installStoreSpecificPropertiesOnDocumentTypes == null || installStoreSpecificPropertiesOnDocumentTypes != "false")
			{
				if (DocumentType.GetAllAsList().Where(x => x.Alias.StartsWith(Store.NodeAlias)).All(x => x.Text.ToLower() != storeAlias.ToLower()))
				{
					IO.Container.Resolve<IUmbracoDocumentTypeInstaller>().InstallStore(storeAlias);
				}
				else
				{
					// todo: return message that store already existed?
					return;
				}
			}

			var admin = new User(0);

			var uwbsStoreDt = DocumentType.GetByAlias(Store.NodeAlias);
			var uwbsStoreRepositoryDt = DocumentType.GetByAlias(Store.StoreRepositoryNodeAlias);
			var uwbsStoreRepository = Document.GetDocumentsOfDocumentType(uwbsStoreRepositoryDt.Id).FirstOrDefault(x => !x.IsTrashed);

			if (storeDocument == null)
			{
				if (uwbsStoreRepository != null)
					if (uwbsStoreDt != null)
					{
						storeDocument = Document.MakeNew(storeAlias, uwbsStoreDt, admin, uwbsStoreRepository.Id);
						if (storeDocument != null && preFillRequiredItems)
						{
							storeDocument.SetProperty("orderNumberPrefix", storeAlias);
							storeDocument.SetProperty("globalVat", "0");
							storeDocument.SetProperty("countryCode", "DK");
							storeDocument.SetProperty("storeEmailFrom", string.Format("info@{0}.com", storeAlias));
							storeDocument.SetProperty("storeEmailTo", string.Format("info@{0}.com", storeAlias));
							storeDocument.SetProperty("storeEmailFromName", storeAlias);

							storeDocument.Save();
							storeDocument.Publish(new User(0));
						}
					}
			}

			var language = Language.GetByCultureCode(cultureCode);

			if (storeDocument == null)
			{
				return;
			}
			if (language != null) storeDocument.SetProperty("currencyCulture", language.id.ToString());
			storeDocument.Save();

			//InstallProductUrlRewritingRules(storeAlias);
		}
		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!");
				}
			}
		}
		private static void FixRootCategoryUrlName(Document sender, Document[] docs, string propertyName)
		{
			var urlName = sender.getProperty(propertyName).Value.ToString();
			if (docs.Any(x => urlName == x.Text))
			{
				int count = 1;
				var existingRenames = docs.Where(x => x.Text.StartsWith(urlName)).Select(x => x.Text).Select(x => Regex.Match(x, urlName + @" [(](\d)[)]").Groups[1].Value).Select(x =>
					{
						int i;
						int.TryParse(x, out i);
						return i;
					});
				if (existingRenames.Any())
				{
					count = existingRenames.Max() + 1;
				}
				sender.SetProperty(propertyName, urlName + " (" + count + ")");
			}
		}