Exemplo n.º 1
0
        /// <summary>
        /// Insert a path in cSiteMapNode (Insert RoleIds with AddRoleId)
        /// </summary>
        /// <param name="path">Insert URL (Ex. ~/default.aspx)</param>
        /// <param name="userId">Insert UserId</param>
        /// <param name="showSiteMapNode">Show URL in menu or not? (true)Show - (false)Dont show in menu</param>
        /// <param name="siteMapNodeSubId">If you want this URL like a sub for a URL, then insert ID of the URL</param>
        /// <param name="title">Inser title of URL</param>
        /// <param name="langaugeId">Insert ID of that langauge it write in</param>
        /// <param name="metatagsObject">to add metatags to sitemap (just left it null if you dont want metatags with)</param>
        protected void CreateSiteMapNode_Single(string path,
                                                Guid userId,
                                                bool showSiteMapNode,
                                                int?siteMapNodeSubId,
                                                string title,
                                                int langaugeId,
                                                int sort,
                                                SiteMapNodeMetatagsObject m)
        {
            DateTime dateTimeNow = TimeZoneManager.DateTimeNow;

            // using statement free the memory after metode is done
            using (Searchwar_netEntities db = new Searchwar_netEntities())
            {
                SW_SiteMapNode createSiteMapNode = new SW_SiteMapNode
                {
                    SiteMapNodePath        = path,
                    SiteMapNodeAddedUserId = userId,
                    SiteMapNodeEditUserId  = userId,
                    SiteMapNodeShow        = showSiteMapNode,
                    SiteMapNodeEditDate    = dateTimeNow,
                    SiteMapNodeAddedDate   = dateTimeNow,
                    SiteMapNodeSort        = sort
                };

                SW_SiteMapNodeData createSiteMapNodeData = new SW_SiteMapNodeData
                {
                    LangId = langaugeId
                };


                // Check title for empty
                if (!string.IsNullOrEmpty(title))
                {
                    createSiteMapNodeData.SiteMapNodeTitle = title;
                }


                // Check SubId for empty
                if (siteMapNodeSubId.HasValue)
                {
                    SW_SiteMapNode siteMapNodeSub = (from s in db.SW_SiteMapNode
                                                     where s.SiteMapNodeId.Equals(siteMapNodeSubId)
                                                     select s).SingleOrDefault();

                    // Check path is in database
                    if (siteMapNodeSub != null)
                    {
                        createSiteMapNode.SiteMapNodeSubId = siteMapNodeSubId;
                    }
                    else
                    {
                        throw (new ArgumentNullException("siteMapNodeSubId", "Cant find SiteMapId '" + siteMapNodeSubId + "' in database"));
                    }
                }

                db.SW_SiteMapNode.AddObject(createSiteMapNode);
                db.SaveChanges();

                // Insert SiteMapId
                createSiteMapNodeData.SiteMapNodeId = createSiteMapNode.SiteMapNodeId;

                db.SW_SiteMapNodeData.AddObject(createSiteMapNodeData);
                db.SaveChanges();


                if (m != null)
                {
                    new SearchWar.SiteMap.MetaTags.SiteMapNodeMetaTags().CreateMetaTags(createSiteMapNode.SiteMapNodeId,
                                                                                        m.MetaTagTitle,
                                                                                        m.MetaTagDescription,
                                                                                        m.MetaTagKeywords,
                                                                                        m.MetaTagLanguage,
                                                                                        m.MetaTagAuthor,
                                                                                        m.MetaTagPublisher,
                                                                                        m.MetaTagCopyright,
                                                                                        m.MetaTagRevisitAfter,
                                                                                        m.MetaTagRobots,
                                                                                        m.MetaTagCache,
                                                                                        m.MetaTagCacheControl,
                                                                                        userId,
                                                                                        langaugeId);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update a path in cSiteMapNode
        /// (Insert RoleIds with AddRoleId and Remove RoleIds with RemoveRoleId)
        /// </summary>
        /// <param name="siteMapNodeId">Insert SiteMapId</param>
        /// <param name="path">Insert URL (Ex. ~/default.aspx)</param>
        /// <param name="userId">Insert UserId</param>
        /// <param name="showSiteMapNode">Show URL in menu or not? (true)Show - (false)Dont show in menu</param>
        /// <param name="siteMapNodeSubId">If you want this URL like a sub for a URL, then insert ID of the URL</param>
        /// <param name="title">Inser title of URL</param>
        /// <param name="langaugeId">Insert ID of that langauge it write in</param>
        /// <param name="newLangId">Insert newLangId</param>
        protected void UpdateSiteMap(int siteMapNodeId,
                                     int langaugeId,
                                     string path,
                                     Guid userId,
                                     bool showSiteMapNode,
                                     int?siteMapNodeSubId,
                                     string title,
                                     int?newLangId,
                                     int sort,
                                     SiteMapNodeMetatagsObject m)
        {
            DateTime dateTimeNow = TimeZoneManager.DateTimeNow;

            // using statement free the memory after metode is done
            using (Searchwar_netEntities db = new Searchwar_netEntities())
            {
                SW_SiteMapNode siteMapNode = (from s in db.SW_SiteMapNode
                                              where s.SiteMapNodeId.Equals(siteMapNodeId)
                                              select s).SingleOrDefault();

                // Check SiteMapId in database
                if (siteMapNode != null)
                {
                    siteMapNode.SiteMapNodePath       = path;
                    siteMapNode.SiteMapNodeShow       = showSiteMapNode;
                    siteMapNode.SiteMapNodeSubId      = siteMapNodeSubId;
                    siteMapNode.SiteMapNodeEditUserId = userId;
                    siteMapNode.SiteMapNodeEditDate   = dateTimeNow;
                    siteMapNode.SiteMapNodeSort       = sort;

                    SW_SiteMapNodeData siteMapNodeData = siteMapNode.SW_SiteMapNodeData.Single <SW_SiteMapNodeData>(d => d.SiteMapNodeId.Equals(siteMapNodeId) && d.LangId.Equals(langaugeId));
                    siteMapNodeData.SiteMapNodeTitle = title;
                    if (newLangId.HasValue)
                    {
                        siteMapNodeData.LangId = newLangId.Value;
                    }

                    db.SaveChanges();

                    object checkMetaTags =
                        db.SW_SiteMapNodeMetaTags.Where(mt => mt.MetaTagsId == siteMapNodeId).SingleOrDefault();

                    if (m != null && checkMetaTags != null)
                    {
                        new SearchWar.SiteMap.MetaTags.SiteMapNodeMetaTags().UpdateMetaTags(siteMapNodeId,
                                                                                            langaugeId,
                                                                                            m.MetaTagTitle,
                                                                                            m.MetaTagDescription,
                                                                                            m.MetaTagKeywords,
                                                                                            m.MetaTagLanguage,
                                                                                            m.MetaTagAuthor,
                                                                                            m.MetaTagPublisher,
                                                                                            m.MetaTagCopyright,
                                                                                            m.MetaTagRevisitAfter,
                                                                                            m.MetaTagRobots,
                                                                                            m.MetaTagCache,
                                                                                            m.MetaTagCacheControl,
                                                                                            null,
                                                                                            userId);
                    }
                }
                else
                {
                    throw (new ArgumentNullException("siteMapNodeId", "Cant find SiteMap '" + siteMapNodeId + "' in database"));
                }
            }
        }