public static void WriteSiteMapForListing15Am() { //Create the XmlDocument. var doc = new XmlDocument(); var xmltype = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; var sitemapHelper = new SiteMapHelper(); var getDate = DateTime.Now; var listSiteMapEntry = new List<SiteMapEntry>(); var siteMap = new XDocument(); #region listing follow sub-category // Get list sub category listing var listCategory = new SitemapData().GetCategoryListingList(); // Get 2000 newest by subcategory foreach (var category in listCategory) { var listingModel = new SitemapData().GetListingByCategory(category.CategoryId); listSiteMapEntry = new List<SiteMapEntry>(); listSiteMapEntry.AddRange(listingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Level2Category.UrlFriendly() + "-" + item.Category.UrlFriendly() + "-" + item.CategoryId + "/" + item.Title.UrlFriendly() + "-" + item.Id, Lastmod = getDate, Changefreq = "daily", Priority = 0.9m })); siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); //Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + category.Level2Category.UrlFriendly() + "-" + category.Category.UrlFriendly() + "-" + category.CategoryId + ConfigurationManager.AppSettings["extSitemap"]); } #endregion }
public static void WriteSiteMapDaily() { //Create the XmlDocument. var doc = new XmlDocument(); var xmltype = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; var sitemapHelper = new SiteMapHelper(); var getDate = DateTime.Now; var listSiteMap = new List<SiteMapEntry>(); var listSiteMapEntry = new List<SiteMapEntry>(); var siteMap = new XDocument(); #region LISTING var listingModel = new SitemapData().GetListings(); if (listingModel.Count > 0) { #region category-listing listSiteMapEntry = new List<SiteMapEntry>(); listSiteMapEntry.Add(new SiteMapEntry { Loc = "http://www.muabannhadat.vn/nha-dat-3490", Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }); foreach (var siteMapEntry in listingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Level2Category.UrlFriendly() + "-" + item.Level2CategoryId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); // Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["category-listing"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["category-listing"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region category-sub-category-listing listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in listingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Level2Category.UrlFriendly() + "-" + item.Category.UrlFriendly() + "-" + item.CategoryId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); //Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["category-sub-category-listing"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["category-sub-category-listing"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region category-city-listing listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in listingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/nha-dat-3490/" + item.State.UrlFriendly() + "-s" + item.StateId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } foreach (var siteMapEntry in listingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Level2Category.UrlFriendly() + "-" + item.Level2CategoryId + "/" + item.State.UrlFriendly() + "-s" + item.StateId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); //Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["category-city-listing"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["category-city-listing"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region subcategory-category-city-listing listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in listingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Level2Category.UrlFriendly() + "-" + item.Category.UrlFriendly() + "-" + item.CategoryId + "/" + item.State.UrlFriendly() + "-s" + item.StateId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); //Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["subcategory-category-city-listing"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["subcategory-category-city-listing"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region category-city-district-listing listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in listingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/nha-dat-3490/" + item.State.UrlFriendly() + "-" + item.District.UrlFriendly() + "-d" + item.DistrictId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } foreach (var siteMapEntry in listingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Level2Category.UrlFriendly() + "-" + item.Level2CategoryId + "/" + item.State.UrlFriendly() + "-" + item.District.UrlFriendly() + "-d" + item.DistrictId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); //Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["category-city-district-listing"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["category-city-district-listing"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region subcategory-category-city-district-listing listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in listingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Level2Category.UrlFriendly() + "-" + item.Category.UrlFriendly() + "-" + item.CategoryId + "/" + item.State.UrlFriendly() + "-" + item.District.UrlFriendly() + "-d" + item.DistrictId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); //Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["subcategory-category-city-district-listing"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["subcategory-category-city-district-listing"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region listing //var size = Convert.ToInt32(ConfigurationManager.AppSettings["sizeSitemap"]); //var countListingModel = listingModel.Count; //var totalPage = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(countListingModel) / size)); //for (var i = 1; i <= totalPage; i++) //{ // // Save to sitemap // listSiteMap.Add(new SiteMapEntry // { // Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["listing"] + i + ConfigurationManager.AppSettings["extSitemap"], // Lastmod = getDate // }); //} #endregion #region listing follow sub-category listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in listingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/sitemap/" + item.Level2Category.UrlFriendly() + "-" + item.Category.UrlFriendly() + "-" + item.CategoryId }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } listSiteMap.AddRange(listSiteMapEntry.Select(siteMapEntry => new SiteMapEntry { Loc = siteMapEntry.Loc + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate })); #endregion #region subcategory-category-city-project-listing // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["subcategory-category-city-project-listing"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region subcategory-category-city-district-project-listing // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["subcategory-category-city-district-project-listing"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion } #endregion #region PROJECT var projectModel = new SitemapData().GetProjects(); if (projectModel.Count > 0) { #region category-project listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in projectModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Category.UrlFriendly() + "-" + item.CategoryId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); // Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["category-project"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["category-project"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region category-city-project listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in projectModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Category.UrlFriendly() + "-" + item.CategoryId + "/" + item.State.UrlFriendly() + "-s" + item.StateId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); // Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["category-city-project"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["category-city-project"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region category-city-district-project listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in projectModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Category.UrlFriendly() + "-" + item.CategoryId + "/" + item.State.UrlFriendly() + "-" + item.District.UrlFriendly() + "-d" + item.DistrictId, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); // Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["category-city-district-project"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["category-city-district-project"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region project listSiteMapEntry = new List<SiteMapEntry>(); listSiteMapEntry.AddRange(projectModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Category.UrlFriendly() + "-" + item.CategoryId + "/" + item.Title.UrlFriendly() + "-" + item.Id, Lastmod = getDate, Changefreq = "daily", Priority = 0.8m })); siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); // Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["project"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["project"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion } var projectListingModel = new SitemapData().GetProjectListings(); #region subcategory-category-city-project-listing listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in projectListingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Level2Category.UrlFriendly() + "-" + item.Category.UrlFriendly() + "-" + item.CategoryId + "/" + item.State.UrlFriendly() + "-s" + item.StateId + "/" + item.ProjectName.UrlFriendly() + "-p" + item.ProjectId, Lastmod = getDate, Changefreq = "daily", Priority = 0.9m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((siteMap.ToString())); //Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["subcategory-category-city-project-listing"] + ConfigurationManager.AppSettings["extSitemap"]); #endregion #region subcategory-category-city-district-project-listing listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in projectListingModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/" + item.Level2Category.UrlFriendly() + "-" + item.Category.UrlFriendly() + "-" + item.CategoryId + "/" + item.State.UrlFriendly() + "-" + item.District.UrlFriendly() + "-d" + item.DistrictId + "/" + item.ProjectName.UrlFriendly() + "-p" + item.ProjectId, Lastmod = getDate, Changefreq = "daily", Priority = 0.9m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((siteMap.ToString())); //Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["subcategory-category-city-district-project-listing"] + ConfigurationManager.AppSettings["extSitemap"]); #endregion #endregion #region BUSINESS var businessModel = new SitemapData().GetCompanies(); if (businessModel.Count > 0) { #region category-business listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in businessModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/doanh-nghiep/" + item.Category.UrlFriendly() + "-" + item.CategoryId, Lastmod = getDate, Changefreq = "weekly", Priority = 0.5m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); // Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["category-business"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["category-business"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region category-city-business listSiteMapEntry = new List<SiteMapEntry>(); foreach (var siteMapEntry in businessModel.Select(item => new SiteMapEntry { //Loc = "http://www.muabannhadat.vn/doanh-nghiep/" + item.Category.UrlFriendly() + "-" + item.CategoryId + "?cmpsct=" + item.StateId, Loc = "http://www.muabannhadat.vn/doanh-nghiep/" + item.Category.UrlFriendly() + "-" + item.CategoryId, Lastmod = getDate, Changefreq = "weekly", Priority = 0.5m }).Where(siteMapEntry => listSiteMapEntry.All(s => s.Loc != siteMapEntry.Loc))) { listSiteMapEntry.Add(siteMapEntry); } siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); // Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["category-city-business"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["category-city-business"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion #region business listSiteMapEntry = new List<SiteMapEntry>(); //listSiteMapEntry.AddRange(businessModel.Select(item => new SiteMapEntry //{ // Loc = "http://www.muabannhadat.vn/doanh-nghiep/" + item.Category.UrlFriendly() + "-" + item.CategoryId + "/detail/" + item.Name.UrlFriendly() + "-" + item.Id, // Lastmod = getDate, // Changefreq = "weekly", // Priority = 0.5m //})); listSiteMapEntry.AddRange(businessModel.Select(item => new SiteMapEntry { Loc = "http://www.muabannhadat.vn/doanh-nghiep/detail/" + item.Name.UrlFriendly() + "-" + item.Id, Lastmod = getDate, Changefreq = "weekly", Priority = 0.5m })); siteMap = sitemapHelper.GenerateSiteMap(listSiteMapEntry); doc.LoadXml((xmltype + siteMap)); // Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemapCategory"] + ConfigurationManager.AppSettings["business"] + ConfigurationManager.AppSettings["extSitemap"]); // Save to sitemap listSiteMap.Add(new SiteMapEntry { Loc = ConfigurationManager.AppSettings["linkCategorySitemap"] + ConfigurationManager.AppSettings["business"] + ConfigurationManager.AppSettings["extSitemap"], Lastmod = getDate }); #endregion } #endregion // SITEMAP listSiteMap.Add(new SiteMapEntry { Loc = "http://www.muabannhadat.vn/tin-tuc/sitemap-3.xml", Lastmod = getDate }); siteMap = sitemapHelper.GenerateSiteMapMain(listSiteMap); doc.LoadXml((xmltype + siteMap)); //Save the document to a file. doc.Save(ConfigurationManager.AppSettings["pathSitemap"] + "sitemap.xml"); }