Esempio n. 1
0
        /// <summary>
        /// Saveses this instance.
        /// </summary>
        public void Save()
        {
            // get the data
            Document document = new Document(NodeId.Value);
            Property editProperty  = document.getProperty(Field);

            IDataType editDataType = null;
            if (editProperty != null)
            {
                // save the property
                PropertyType editPropertyType = editProperty.PropertyType;
                editDataType = editPropertyType.DataTypeDefinition.DataType;
                editDataType.Data.PropertyId = editProperty.Id;
                editDataType.Data.Value = Data;
            }
            else
            {
                if (Field == "pageName")
                {
                    document.Text = Data.ToString();
                }
            }

            document.Save();
        }
        void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
        {
            if (sender.ContentType.Alias == "Project")
            {
                //ensure that packages have a guid
                if (sender.getProperty("packageGuid") != null && String.IsNullOrEmpty(sender.getProperty("packageGuid").Value.ToString()))
                {
                    sender.getProperty("packageGuid").Value = Guid.NewGuid().ToString();
                    sender.Save();
                }

                //if the score is above the minimum, set the approved variable
                int score = Xslt.Score(sender.Id, "powersProject");
                if (score >= 15)
                {
                    sender.getProperty("approved").Value = true;
                    sender.Save();
                }

                //this ensures the package stores it's compatible versions on the node itself, so we save a ton of sql calls
                if (sender.getProperty("compatibleVersions") != null)
                {
                    List<string> compatibleVersions = new List<string>();
                    foreach (WikiFile wf in WikiFile.CurrentFiles(sender.Id))
                    {
                        if (wf.FileType == "package")
                        {
                            foreach (var ver in wf.Versions)
                            {
                                if (!compatibleVersions.Contains(ver.Version))
                                {
                                    compatibleVersions.Add(ver.Version);
                                }
                            }
                        }
                    }

                    string _compatibleVersions = string.Join(",", compatibleVersions.ToArray());
                    sender.getProperty("compatibleVersions").Value = "saved," + _compatibleVersions;
                }

            }
        }
Esempio n. 3
0
        void Action_AfterPerform(object sender, ActionEventArgs e)
        {
            uPowers.BusinessLogic.Action a = (uPowers.BusinessLogic.Action)sender;

            if (a.Alias == "ProjectUp")
            {
                Document d = new Document(e.ItemId);

                if (d.getProperty("approved").Value != null &&
                     d.getProperty("approved").Value.ToString() != "1" &&
                     uPowers.Library.Xslt.Score(d.Id, "powersProject") >= 15)
                {
                    //set approved flag
                    d.getProperty("approved").Value = true;

                    d.Save();
                    d.Publish(new umbraco.BusinessLogic.User(0));

                    umbraco.library.UpdateDocumentCache(d.Id);
                    umbraco.library.RefreshContent();
                }
            }
        }
Esempio n. 4
0
        public string Move(int wikiId, int target)
        {
            var currentMemberId = Members.GetCurrentMember().Id;
            if (Xslt.IsMemberInGroup("admin", currentMemberId) || Xslt.IsMemberInGroup("wiki editor", currentMemberId))
            {
                Document document = new Document(wikiId);
                Document documentTarget = new Document(target);

                if (documentTarget.ContentType.Alias == "WikiPage")
                {

                    Document o = new Document(document.Parent.Id);

                    document.Move(documentTarget.Id);
                    document.Save();

                    document.Publish(new umbraco.BusinessLogic.User(0));
                    documentTarget.Publish(new umbraco.BusinessLogic.User(0));
                    o.Publish(new umbraco.BusinessLogic.User(0));

                    umbraco.library.UpdateDocumentCache(document.Id);
                    umbraco.library.UpdateDocumentCache(documentTarget.Id);
                    umbraco.library.UpdateDocumentCache(o.Id);

                    umbraco.library.RefreshContent();

                    return umbraco.library.NiceUrl(document.Id);
                }

            }

            return "";
        }
Esempio n. 5
0
		/// <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);
		}
Esempio n. 6
0
        public static Document MakeNew(string Name, DocumentType dct, User u, int ParentId)
        {
            //allows you to cancel a document before anything goes to the DB
            var newingArgs = new DocumentNewingEventArgs()
                                 {
                                     Text = Name,
                                     DocumentType = dct,
                                     User = u,
                                     ParentId = ParentId
                                 };
            Document.OnNewing(newingArgs);
            if (newingArgs.Cancel)
            {
                return null;
            }

            //Create a new IContent object based on the passed in DocumentType's alias, set the name and save it
            IContent content = ApplicationContext.Current.Services.ContentService.CreateContentWithIdentity(Name, ParentId, dct.Alias, u.Id);
            //The content object will only have the 'WasCancelled' flag set to 'True' if the 'Creating' event has been cancelled, so we return null.
            if (((Entity)content).WasCancelled)
                return null;

            //read the whole object from the db
            Document d = new Document(content);

            //event
            NewEventArgs e = new NewEventArgs();
            d.OnNew(e);

            // Log
            LogHelper.Info<Document>(string.Format("New document {0}", d.Id));

            // Run Handler				
            BusinessLogic.Actions.Action.RunActionHandlers(d, ActionNew.Instance);

            // Save doc
            d.Save();

            return d;
        }
Esempio n. 7
0
        public Document Copy(int CopyTo, User u, bool RelateToOrignal)
        {
            var e = new CopyEventArgs();
            e.CopyTo = CopyTo;
            FireBeforeCopy(e);
            Document newDoc = null;

            if (!e.Cancel)
            {
                // Make the new document
                var content = ApplicationContext.Current.Services.ContentService.Copy(Content, CopyTo, RelateToOrignal, u.Id);
                newDoc = new Document(content);
                
                // Have to run the ActionNew handler to do umbEnsureUniqueName (for example)
                BusinessLogic.Actions.Action.RunActionHandlers(newDoc, ActionNew.Instance);
                // Then save to preserve any changes made by action handlers
                newDoc.Save();

                e.NewDocument = newDoc;
                FireAfterCopy(e);
            }

            return newDoc;
        }
Esempio n. 8
0
        public Document Copy(int CopyTo, User u, bool RelateToOrignal)
        {
            var e = new CopyEventArgs();
            e.CopyTo = CopyTo;
            FireBeforeCopy(e);
            Document newDoc = null;

            if (!e.Cancel)
            {
                // Make the new document
                var content = ApplicationContext.Current.Services.ContentService.Copy(Content, CopyTo, RelateToOrignal, u.Id);
                newDoc = new Document(content);
                
                // Then save to preserve any changes made by action handlers
                newDoc.Save();

                e.NewDocument = newDoc;
                FireAfterCopy(e);
            }

            return newDoc;
        }
		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!");
				}
			}
		}
Esempio n. 10
0
        public static string Move(int ID, int target)
        {
            int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0;

            if (Xslt.IsMemberInGroup("admin", _currentMember) || Xslt.IsMemberInGroup("wiki editor", _currentMember))
            {
                Document d = new Document(ID);
                Document t = new Document(target);

                if(t.ContentType.Alias == "WikiPage"){

                    Document o = new Document(d.Parent.Id);

                    d.Move(t.Id);
                    d.Save();

                    d.Publish(new umbraco.BusinessLogic.User(0));
                    t.Publish(new umbraco.BusinessLogic.User(0));
                    o.Publish(new umbraco.BusinessLogic.User(0));

                    umbraco.library.UpdateDocumentCache(d.Id);
                    umbraco.library.UpdateDocumentCache(t.Id);
                    umbraco.library.UpdateDocumentCache(o.Id);

                    umbraco.library.RefreshContent();

                    return umbraco.library.NiceUrl(d.Id);
                }

            }

            return "";
        }
 private void SaveDoc(Document doc)
 {
     doc.Save();
     doc.Publish(User.GetCurrent());
     umbraco.library.UpdateDocumentCache(doc.Id);
 }
Esempio n. 12
0
        /// <summary>
        /// Creates a new document
        /// </summary>
        /// <param name="Name">The name (.Text property) of the document</param>
        /// <param name="dct">The documenttype</param>
        /// <param name="u">The usercontext under which the action are performed</param>
        /// <param name="ParentId">The id of the parent to the document</param>
        /// <returns>The newly created document</returns>
        public static Document MakeNew(string Name, DocumentType dct, User u, int ParentId)
        {
            //allows you to cancel a document before anything goes to the DB
            var newingArgs = new DocumentNewingEventArgs()
            {
                Text = Name,
                DocumentType = dct,
                User = u,
                ParentId = ParentId
            };
            Document.OnNewing(newingArgs);
            if (newingArgs.Cancel)
            {
                return null;
            }

            Guid newId = Guid.NewGuid();

            // Updated to match level from base node
            CMSNode n = new CMSNode(ParentId);
            int newLevel = n.Level;
            newLevel++;

            //create the cms node first
            CMSNode newNode = MakeNew(ParentId, _objectType, u.Id, newLevel, Name, newId);

            //we need to create an empty document and set the underlying text property
            Document tmp = new Document(newId, true);
            tmp.SetText(Name);

            //create the content data for the new document
            tmp.CreateContent(dct);

            //now create the document data
            SqlHelper.ExecuteNonQuery("insert into cmsDocument (newest, nodeId, published, documentUser, versionId, Text) values (1, " +
                                      tmp.Id + ", 0, " +
                                      u.Id + ", @versionId, @text)",
                                      SqlHelper.CreateParameter("@versionId", tmp.Version),
                                      SqlHelper.CreateParameter("@text", tmp.Text));

            // Update the sortOrder if the parent was the root!
            if (ParentId == -1)
            {
                newNode.sortOrder = CountLeafNodes(-1, Document._objectType) + 1;
            }

            //read the whole object from the db
            Document d = new Document(newId);

            //event
            NewEventArgs e = new NewEventArgs();
            d.OnNew(e);

            // Log
            Log.Add(LogTypes.New, u, d.Id, "");

            // Run Handler
            umbraco.BusinessLogic.Actions.Action.RunActionHandlers(d, ActionNew.Instance);

            // Save doc
            d.Save();

            return d;
        }
Esempio n. 13
0
        protected void createEvent(object sender, EventArgs e)
        {
            var hasAnchors = false;
            var hasLowKarma = false;
            var documentId = 0;

            var karma = int.Parse(_member.getProperty("reputationTotal").Value.ToString());
            if (karma < 50)
            {
                hasLowKarma = true;
            }

            //edit?
            if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
            {
                var document = new Document(int.Parse(Request.QueryString["id"]));
                documentId = document.Id;

                //allowed?
                if (document.ContentType.Alias == "Event" && int.Parse(document.getProperty("owner").Value.ToString()) == _member.Id)
                {
                    SetDescription(document, hasLowKarma, ref hasAnchors);

                    document.Text = tb_name.Text;

                    document.getProperty("venue").Value = tb_venue.Text;
                    document.getProperty("latitude").Value = tb_lat.Value;
                    document.getProperty("longitude").Value = tb_lng.Value;

                    var sync = tb_capacity.Text != document.getProperty("capacity").Value.ToString();

                    document.getProperty("capacity").Value = tb_capacity.Text;

                    document.getProperty("start").Value = DateTime.Parse(dp_startdate.Text);
                    document.getProperty("end").Value = DateTime.Parse(dp_enddate.Text);

                    document.Save();
                    document.Publish(new User(0));

                    umbraco.library.UpdateDocumentCache(document.Id);

                    if (sync)
                    {
                        var ev = new uEvents.Event(document);
                        ev.syncCapacity();
                    }
                }
            }
            else
            {
                Document document = Document.MakeNew(tb_name.Text, DocumentType.GetByAlias("Event"), new User(0), EventsRoot);
                documentId = document.Id;

                SetDescription(document, hasLowKarma, ref hasAnchors);

                document.getProperty("venue").Value = tb_venue.Text;
                document.getProperty("latitude").Value = tb_lat.Value;
                document.getProperty("longitude").Value = tb_lng.Value;

                document.getProperty("capacity").Value = tb_capacity.Text;
                document.getProperty("signedup").Value = 0;

                document.getProperty("start").Value = DateTime.Parse(dp_startdate.Text);
                document.getProperty("end").Value = DateTime.Parse(dp_enddate.Text);

                document.getProperty("owner").Value = _member.Id;

                document.Save();
                document.Publish(new User(0));
                umbraco.library.UpdateDocumentCache(document.Id);
            }

            var redirectUrl = umbraco.library.NiceUrl(documentId);

            if (hasLowKarma && hasAnchors)
                SendPotentialSpamNotification(tb_name.Text, redirectUrl, _member.Id);

            Response.Redirect(redirectUrl);
        }
Esempio n. 14
0
        public void UpdateSortOrder(int ParentId, string SortOrder)
        {
            //TODO: The amount of processing this method takes is HUGE. We should look at 
            // refactoring this to use purely the new APIs and see how much faster we can make it!

            try
            {
                if (AuthorizeRequest() == false) return;
                if (SortOrder.Trim().Length <= 0) return;
                var ids = SortOrder.Split(',');

                var isContent = helper.Request("app") == "content" | helper.Request("app") == "";
                var isMedia = helper.Request("app") == "media";
                //ensure user is authorized for the app requested
                if (isContent && AuthorizeRequest(DefaultApps.content.ToString()) == false) return;
                if (isMedia && AuthorizeRequest(DefaultApps.media.ToString()) == false) return;

                for (var i = 0; i < ids.Length; i++)
                {
                    if (ids[i] == "" || ids[i].Trim() == "") continue;

                    if (isContent)
                    {
                        var document = new Document(int.Parse(ids[i]))
                            {
                                sortOrder = i
                            };

                        if (document.Published)
                        {
                            document.Publish(BusinessLogic.User.GetCurrent());

                            //TODO: WE don't want to have to republish the entire document !!!!
                            library.UpdateDocumentCache(document);
                        }
                        else
                        {
                            //we need to save it if it is not published to persist the sort order value
                            document.Save();
                        }
                    }
                        // to update the sortorder of the media node in the XML, re-save the node....
                    else if (isMedia)
                    {
                        var media = new cms.businesslogic.media.Media(int.Parse(ids[i]))
                            {
                                sortOrder = i
                            };
                        media.Save();                        
                    }

                    // Refresh sort order on cached xml
                    if (isContent)
                    {
                        XmlNode parentNode = ParentId == -1
                                                 ? content.Instance.XmlContent.DocumentElement
                                                 : content.Instance.XmlContent.GetElementById(ParentId.ToString());

                        //only try to do the content sort if the the parent node is available... 
                        if (parentNode != null)
                            content.SortNodes(ref parentNode);

                        // Load balancing - then refresh entire cache
                        if (UmbracoSettings.UseDistributedCalls)
                            library.RefreshContent();

                        // fire actionhandler, check for content
                        BusinessLogic.Actions.Action.RunActionHandlers(new Document(ParentId), ActionSort.Instance);
                    }
                }                
            }
            catch (Exception ex)
            {
                LogHelper.Error<nodeSorter>("Could not update sort order", ex);
            }
        }
Esempio n. 15
0
 private INode SaveDoc(Document doc)
 {
     doc.Save();
     doc.Publish(User.GetAllByLoginName("visitor", false).FirstOrDefault());
     umbraco.library.UpdateDocumentCache(doc.Id);
     return new Node(doc.Id);
 }
Esempio n. 16
0
        protected void saveProject(object sender, CommandEventArgs e)
        {
            Member m = Member.GetCurrentMember();
            Document d;

            var memberHasEnoughReputation = MemberHasEnoughReputation(m);
            if (memberHasEnoughReputation == false)
            {
                holder.Visible = false;
                notallowed.Visible = true;
            }
            else
            {
                if (e.CommandName == "save")
                {

                    int pId = int.Parse(e.CommandArgument.ToString());

                    d = new Document(pId);

                    if ((int)d.getProperty("owner").Value == m.Id || Utils.IsProjectContributor(m.Id, d.Id))
                    {
                        d.Text = tb_name.Text;
                        d.getProperty("version").Value = tb_version.Text;
                        d.getProperty("description").Value = tb_desc.Text;

                        d.getProperty("stable").Value = cb_stable.Checked;
                        d.getProperty("status").Value = tb_status.Text;

                        d.getProperty("demoUrl").Value = tb_demoUrl.Text;
                        d.getProperty("sourceUrl").Value = tb_sourceUrl.Text;
                        d.getProperty("websiteUrl").Value = tb_websiteUrl.Text;

                        d.getProperty("vendorUrl").Value = tb_purchaseUrl.Text;

                        d.getProperty("licenseUrl").Value = tb_licenseUrl.Text;
                        d.getProperty("licenseName").Value = tb_license.Text;

                        d.getProperty("file").Value = dd_package.SelectedValue;
                        d.getProperty("defaultScreenshot").Value = dd_screenshot.SelectedValue;

                        if (dd_screenshot.SelectedIndex > -1)
                        {
                            d.getProperty("defaultScreenshotPath").Value =
                                new uWiki.Businesslogic.WikiFile(int.Parse(dd_screenshot.SelectedValue)).Path;
                        }
                        else
                        {
                            d.getProperty("defaultScreenshotPath").Value = "";
                        }

                        if (Request["projecttags[]"] != null)
                        {
                            Api.CommunityController.SetTags(d.Id.ToString(), "project",
                                Request["projecttags[]"].ToString());
                        }

                        Node category = new Node(int.Parse(dd_category.SelectedValue));

                        //if we have a proper category, move the package
                        if (category != null && category.NodeTypeAlias == "ProductGroup") ;
                        {
                            if (d.Parent.Id != category.Id)
                            {
                                d.Move(category.Id);
                            }
                        }

                        if (d.getProperty("packageGuid") == null ||
                            string.IsNullOrEmpty(d.getProperty("packageGuid").Value.ToString()))
                            d.getProperty("packageGuid").Value = Guid.NewGuid().ToString();

                        d.Save();
                        d.Publish(new umbraco.BusinessLogic.User(0));

                        umbraco.library.UpdateDocumentCache(d.Id);
                        umbraco.library.RefreshContent();
                    }

                }
                else
                {

                    d = Document.MakeNew(tb_name.Text, new DocumentType(TypeId), new umbraco.BusinessLogic.User(0),
                        RootId);

                    d.getProperty("version").Value = tb_version.Text;
                    d.getProperty("description").Value = tb_desc.Text;

                    d.getProperty("stable").Value = cb_stable.Checked;

                    d.getProperty("demoUrl").Value = tb_demoUrl.Text;
                    d.getProperty("sourceUrl").Value = tb_sourceUrl.Text;
                    d.getProperty("websiteUrl").Value = tb_websiteUrl.Text;

                    d.getProperty("licenseUrl").Value = tb_licenseUrl.Text;
                    d.getProperty("licenseName").Value = tb_license.Text;

                    d.getProperty("vendorUrl").Value = tb_purchaseUrl.Text;

                    //d.getProperty("file").Value = dd_package.SelectedValue;
                    d.getProperty("owner").Value = m.Id;
                    d.getProperty("packageGuid").Value = Guid.NewGuid().ToString();

                    if (Request["projecttags[]"] != null)
                    {
                        Api.CommunityController.SetTags(d.Id.ToString(), "project", Request["projecttags[]"].ToString());
                        d.getProperty("tags").Value = Request["projecttags[]"].ToString();
                    }

                    Node category = new Node(int.Parse(dd_category.SelectedValue));

                    //if we have a proper category, move the package
                    if (category != null && category.NodeTypeAlias == "ProductGroup") ;
                    {
                        if (d.Parent.Id != category.Id)
                        {
                            d.Move(category.Id);
                        }
                    }

                    d.Save();

                    d.Publish(new umbraco.BusinessLogic.User(0));
                    umbraco.library.UpdateDocumentCache(d.Id);

                    umbraco.library.RefreshContent();
                }
                Response.Redirect(umbraco.library.NiceUrl(GotoOnSave));
            }
        }
Esempio n. 17
0
 /// <summary>
 /// Saves and publishes a document
 /// Time: O(1), Space: O(1); where n - number of nodes on content tree.
 /// </summary>
 /// <param name="document">The document to save and publish</param>
 public static void SaveAndPublish(Document document)
 {
     if(document != null)
     {
         document.Save();
         document.Publish(document.User);
         umbraco.library.UpdateDocumentCache(document.Id);
     }
 }