Пример #1
0
        /// <summary>
        /// Deletes an URL record
        /// </summary>
        /// <param name="urlRecord">URL record</param>
        public virtual void DeleteUrlRecord(UrlRecord urlRecord)
        {
            if (urlRecord == null)
            {
                throw new ArgumentNullException(nameof(urlRecord));
            }

            _urlRecordRepository.Delete(urlRecord);

            //cache
            _cacheManager.RemoveByPattern(URLRECORD_PATTERN_KEY);
        }
Пример #2
0
        /// <summary>
        /// Updates the URL record
        /// </summary>
        /// <param name="urlRecord">URL record</param>
        public virtual void UpdateUrlRecord(UrlRecord urlRecord)
        {
            if (urlRecord == null)
            {
                throw new ArgumentNullException(nameof(urlRecord));
            }

            _urlRecordRepository.Update(urlRecord);

            //cache
            _cacheManager.RemoveByPattern(NopSeoDefaults.UrlRecordPatternCacheKey);
        }
Пример #3
0
        /// <summary>
        /// Updates the URL record
        /// </summary>
        /// <param name="urlRecord">URL record</param>
        public virtual void UpdateUrlRecord(UrlRecord urlRecord)
        {
            if (urlRecord == null)
            {
                throw new ArgumentNullException("urlRecord");
            }

            _urlRecordRepository.Update(urlRecord);

            //cache
            _cacheManager.Remove(URLRECORD_PATTERN_KEY);
        }
Пример #4
0
        /// <summary>
        /// Inserts an URL record
        /// </summary>
        /// <param name="urlRecord">URL record</param>
        public virtual void InsertUrlRecord(UrlRecord urlRecord)
        {
            if (urlRecord == null)
            {
                throw new ArgumentNullException("urlRecord");
            }

            _urlRecordRepository.Insert(urlRecord);

            //cache
            _cacheManager.RemoveByPattern(URLRECORD_PATTERN_KEY);
        }
Пример #5
0
        /// <summary>
        /// Inserts an URL record
        /// </summary>
        /// <param name="urlRecord">URL record</param>
        public virtual async Task InsertUrlRecord(UrlRecord urlRecord)
        {
            if (urlRecord == null)
            {
                throw new ArgumentNullException("urlRecord");
            }

            await _urlRecordRepository.InsertAsync(urlRecord);

            //cache
            await _cacheManager.RemoveByPrefix(CacheKey.URLRECORD_PATTERN_KEY);
        }
Пример #6
0
        /// <summary>
        /// Updates the URL record
        /// </summary>
        /// <param name="urlRecord">URL record</param>
        public virtual async Task UpdateUrlRecord(UrlRecord urlRecord)
        {
            if (urlRecord == null)
            {
                throw new ArgumentNullException("urlRecord");
            }

            await _urlRecordRepository.UpdateAsync(urlRecord);

            //cache
            _cacheManager.RemoveByPattern(URLRECORD_PATTERN_KEY);
        }
Пример #7
0
        public override RouteValueDictionary GetRouteValues(UrlRecord urlRecord, RouteValueDictionary values)
        {
            // TODO: (core) Implement DefaultSlugRouter once all affected entity types are ported.
            switch (urlRecord.EntityName.ToLowerInvariant())
            {
            case "product":
                return(new RouteValueDictionary
                {
                    { "area", string.Empty },
                    { "controller", "Product" },
                    { "action", "ProductDetails" },
                    { "productId", urlRecord.EntityId },
                    { "entity", urlRecord }
                });

            case "category":
                return(new RouteValueDictionary
                {
                    { "area", string.Empty },
                    { "controller", "Catalog" },
                    { "action", "Category" },
                    { "categoryId", urlRecord.EntityId },
                    { "entity", urlRecord }
                });

            case "manufacturer":
                return(new RouteValueDictionary
                {
                    { "area", string.Empty },
                    { "controller", "Catalog" },
                    { "action", "Manufacturer" },
                    { "manufacturerId", urlRecord.EntityId },
                    { "entity", urlRecord }
                });

            case "topic":
                //case "newsitem": // TODO: (core) Move newsitem and blogpost to external modules
                //case "blogpost":
                return(new RouteValueDictionary
                {
                    { "area", string.Empty },
                    { "controller", "Home" },
                    { "action", "Slug" },
                    { "entity", urlRecord }
                });

            default:
                break;
            }

            return(null);
        }
Пример #8
0
 public static UrlRecordForCaching Transform(UrlRecord obj)
 {
     if (obj == null) return null;
     return new UrlRecordForCaching
     {
         Id = obj.Id,
         EntityId = obj.EntityId,
         EntityName = obj.EntityName,
         IsActive = obj.IsActive,
         LanguageId = obj.LanguageId,
         Slug = obj.Slug
     };
 }
Пример #9
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmAddUrl form = new FrmAddUrl();
            form.ShowDialog();
            foreach (String item in form.Urls)
            {
                UrlRecord record = new UrlRecord { Url = item, Status = 0 };
                m_records.Add(record);
            }

            BindingSource bs = new BindingSource();
            bs.DataSource = m_records;
            this.dgv.DataSource = bs;
        }
Пример #10
0
        public ActionResult Delete(Guid id)
        {
            Menu      obj       = MenuBLL.GetById(id);
            UrlRecord urlRecord = UrlBLL.Table.FirstOrDefault(o => o.EntityName == "Menu" && o.EntityId == obj.Id);

            if (urlRecord != null)
            {
                UrlBLL.Delete(urlRecord);
            }
            MenuBLL.Delete(obj);
            CacheManager.Remove(Consts.MenuCacheKey);
            CacheManager.Remove(Consts.UrlRecordCacheKey);
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Пример #11
0
        public ActionResult Create(PostModel model)
        {
            if (ModelState.IsValid)
            {
                var post = new Post()
                {
                    AllowComment   = model.AllowComment,
                    CategoryId     = model.CategoryId,
                    Description    = model.FullContent,
                    IsActive       = model.IsActive,
                    ApproveComment = model.ApproveComment,
                    IsDelete       = model.IsDelete,
                    UserId         = User.Identity.GetUserId(),
                    Title          = model.Title,
                    CreateDateUtc  = DateTime.UtcNow,
                    UpdateDateUtc  = DateTime.UtcNow,
                    Format         = model.PostFormat.ToString(),
                    FormatValue    = model.PostFormatValue,
                    PictureId      = model.PictureId,
                    ViewName       = model.ViewName
                };

                var result = postService.Insert(post);
                if (result)
                {
                    this.NotifySuccess("Successfully saved.");
                }
                else
                {
                    this.NotifyError("Item can not saved!");
                }

                this.SavePostTags(post, model.Tags);

                var urlRecord = new UrlRecord
                {
                    EntityId   = post.Id,
                    EntityName = nameof(Post),
                    Slug       = model.Title.ToUrlSlug()
                };
                urlService.Save(urlRecord);

                return(RedirectToAction("Edit", new { Id = post.Id }));
            }

            model.Categories         = categoryService.GetActives();
            model.AvailableViewNames = this.GetViewNames();
            model.AvailableTags      = new MultiSelectList(postTagService.GetAllTags().Select(s => s.Name), model.Tags);
            return(View(model));
        }
Пример #12
0
        private void InsertUrlRecord(T entity)
        {
            var namedEntity = (INameSupported)entity;
            var urlRecord   = new UrlRecord()
            {
                EntityId   = entity.Id,
                EntityName = typeof(T).Name,
                IsActive   = true,
                LanguageId = _workContext.WorkingLanguage.Id,
                Slug       = Nop.Services.Seo.SeoExtensions.GetSeName(namedEntity.Name, true, false)
            };

            _urlRecordService.InsertUrlRecord(urlRecord);
        }
Пример #13
0
        public static UrlRecord GetManufacturerUrlRecordForUpdate(List <UrlRecord> urlRecords, int manufacturerId, string brand, List <UrlRecord> existingUpdateUrlRecords)
        {
            UrlRecord urlRecord = urlRecords.Where(ur => ur.EntityId == manufacturerId && ur.EntityName == "Manufacturer").FirstOrDefault();
            UrlRecord existingUpdateUrlRecord = existingUpdateUrlRecords.Where(ur => ur.EntityId == manufacturerId && ur.EntityName == "Manufacturer").FirstOrDefault();

            if (urlRecord != null && existingUpdateUrlRecord == null)
            {
                urlRecord.Slug       = UrlUtil.ModifyUrl(brand);
                urlRecord.IsActive   = true;
                urlRecord.LanguageId = 0;
                return(urlRecord);
            }

            return(null);
        }
Пример #14
0
        public virtual void DeleteUrlRecord(UrlRecord urlRecord)
        {
            Guard.NotNull(urlRecord, nameof(urlRecord));

            try
            {
                // cache
                ClearCacheSegment(urlRecord.EntityName, urlRecord.EntityId, urlRecord.LanguageId);
                HasChanges = true;

                // db
                _urlRecordRepository.Delete(urlRecord);
            }
            catch { }
        }
        public static UrlRecord GetCategoryUrlRecordForUpdate(List <UrlRecord> urlRecords, Category category, List <UrlRecord> existingUpdateUrlRecords)
        {
            UrlRecord urlRecord = urlRecords.Where(ur => ur.EntityId == category.Id && ur.EntityName == "category").FirstOrDefault();
            UrlRecord existingUpdateUrlRecord = existingUpdateUrlRecords.Where(ur => ur.EntityId == category.Id && ur.EntityName == "Category").FirstOrDefault();

            if (urlRecord != null && existingUpdateUrlRecord == null)
            {
                urlRecord.Slug       = UrlUtil.ModifyUrl(category.Name);
                urlRecord.IsActive   = true;
                urlRecord.LanguageId = 0;
                return(urlRecord);
            }

            return(null);
        }
        private void PrepareUrlRecordModel(UrlRecordModel model, UrlRecord urlRecord, bool forList = false)
        {
            if (!forList)
            {
                var allLanguages = _languageService.GetAllLanguages(true);

                model.AvailableLanguages = allLanguages
                                           .Select(x => new SelectListItem {
                    Text = x.Name, Value = x.Id.ToString()
                })
                                           .ToList();

                model.AvailableLanguages.Insert(0, new SelectListItem {
                    Text = T("Admin.System.SeNames.Language.Standard"), Value = "0"
                });
            }

            if (urlRecord != null)
            {
                model.Id         = urlRecord.Id;
                model.Slug       = urlRecord.Slug;
                model.EntityName = urlRecord.EntityName;
                model.EntityId   = urlRecord.EntityId;
                model.IsActive   = urlRecord.IsActive;
                model.LanguageId = urlRecord.LanguageId;

                if (urlRecord.EntityName.IsCaseInsensitiveEqual("BlogPost"))
                {
                    model.EntityUrl = Url.Action("Edit", "Blog", new { id = urlRecord.EntityId });
                }
                else if (urlRecord.EntityName.IsCaseInsensitiveEqual("Forum"))
                {
                    model.EntityUrl = Url.Action("EditForum", "Forum", new { id = urlRecord.EntityId });
                }
                else if (urlRecord.EntityName.IsCaseInsensitiveEqual("ForumGroup"))
                {
                    model.EntityUrl = Url.Action("EditForumGroup", "Forum", new { id = urlRecord.EntityId });
                }
                else if (urlRecord.EntityName.IsCaseInsensitiveEqual("NewsItem"))
                {
                    model.EntityUrl = Url.Action("Edit", "News", new { id = urlRecord.EntityId });
                }
                else
                {
                    model.EntityUrl = Url.Action("Edit", urlRecord.EntityName, new { id = urlRecord.EntityId });
                }
            }
        }
        private void InstallWebPages()
        {
            if (_webPageRepo.Table.Count() > 0)
            {
                return;
            }

            var sections = new List <Section>
            {
                new HtmlContentSection {
                    Html = "test html section"
                }
            };
            var pages = new List <WebPage>
            {
                new WebPage {
                    ParentId = 0, MetaTitle = "Home", NavigationName = "Home", VirtualPath = "Home", DisplayOrder = 1, Sections = sections
                },
                new WebPage {
                    ParentId = 0, MetaTitle = "Contact", NavigationName = "Contact", VirtualPath = "Contact", DisplayOrder = 2
                },
                new WebPage {
                    ParentId = 2, MetaTitle = "About", NavigationName = "About", VirtualPath = "Contact-About", DisplayOrder = 7
                }
            };

            foreach (var page in pages)
            {
                var p = _webPageRepo.Table.Where(x => x.VirtualPath == page.VirtualPath).FirstOrDefault();
                if (p == null)
                {
                    page.CreatedOn = DateTime.Now;
                    page.UpdatedOn = DateTime.Now;
                    _webPageRepo.Add(page);
                    _unitOfWork.Complete();
                    var urlRecord = new UrlRecord()
                    {
                        EntityId   = page.Id,
                        EntityName = "WebPage",
                        Slug       = page.VirtualPath,
                        LanguageId = 0,
                        IsActive   = true,
                    };
                    _urlRecordRepo.Add(urlRecord);
                }
            }
            //_unitOfWork.Complete();
        }
Пример #18
0
 public ActionResult Delete(Guid id)
 {
     foreach (Guid gid in GetIdAndChildId(TableCache.Where(o => o.Id == id).ToList()))
     {
         Category  obj       = CateBLL.GetById(gid);
         UrlRecord urlRecord = UrlBLL.Table.FirstOrDefault(o => o.EntityName == "Category" && o.EntityId == obj.Id);
         if (urlRecord != null)
         {
             UrlBLL.Delete(urlRecord);
         }
         CateBLL.Delete(obj);
     }
     CacheManager.Remove(Consts.CategoryCacheKey);
     CacheManager.Remove(Consts.UrlRecordCacheKey);
     return(Json(true, JsonRequestBehavior.AllowGet));
 }
Пример #19
0
        /// <summary>
        /// Save slug
        /// </summary>
        /// <typeparam name="T">Type</typeparam>
        /// <param name="entity">Entity</param>
        /// <param name="slug">Slug</param>
        /// <param name="languageId">Language ID</param>
        public virtual void SaveSlug <T>(T entity, string slug, int languageId) where T : BaseEntity, ISlugSupported
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            int    entityId   = entity.Id;
            string entityName = typeof(T).Name;

            var query = from ur in _urlRecordRepository.Table
                        where ur.EntityId == entityId &&
                        ur.EntityName == entityName &&
                        ur.LanguageId == languageId
                        select ur;
            var urlRecord = query.FirstOrDefault();

            if (urlRecord != null)
            {
                if (string.IsNullOrWhiteSpace(slug))
                {
                    //delete
                    DeleteUrlRecord(urlRecord);
                }
                else
                {
                    //update
                    urlRecord.Slug = slug;
                    UpdateUrlRecord(urlRecord);
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(slug))
                {
                    //insert
                    urlRecord = new UrlRecord()
                    {
                        EntityId   = entity.Id,
                        EntityName = entityName,
                        Slug       = slug,
                        LanguageId = languageId,
                    };
                    InsertUrlRecord(urlRecord);
                }
            }
        }
Пример #20
0
 private void DownloadForm_Load(object sender, EventArgs e)
 {
     this.dgv.UseDefaultMode00();
     if (InitUriList != null)
     {
         foreach (Uri item in InitUriList)
         {
             UrlRecord record = new UrlRecord();
             record.Url    = item.ToString();
             record.Status = 0;
             m_records.Add(record);
         }
         BindingSource bs = new BindingSource();
         bs.DataSource       = m_records;
         this.dgv.DataSource = bs;
     }
 }
Пример #21
0
        public void Can_save_and_load_urlRecord()
        {
            var urlRecord = new UrlRecord
            {
                EntityId = 1,
                EntityName = "EntityName 1",
                Slug = "Slug 1",
                LanguageId = 2,
            };

            var fromDb = SaveAndLoadEntity(urlRecord);
            fromDb.ShouldNotBeNull();
            fromDb.EntityId.ShouldEqual(1);
            fromDb.EntityName.ShouldEqual("EntityName 1");
            fromDb.Slug.ShouldEqual("Slug 1");
            fromDb.LanguageId.ShouldEqual(2);
        }
Пример #22
0
 private void DownloadForm_Load(object sender, EventArgs e)
 {
     this.dgv.UseDefaultMode00();
     if (InitUriList != null)
     {
         foreach (Uri item in InitUriList)
         {
             UrlRecord record = new UrlRecord();
             record.Url = item.ToString();
             record.Status = 0;
             m_records.Add(record);
         }
         BindingSource bs = new BindingSource();
         bs.DataSource = m_records;
         this.dgv.DataSource = bs;
     }
 }
Пример #23
0
        public List <UrlRecord> FindUrlRecordsForProductToUpdate(Product product)
        {
            string           slug               = UrlUtil.ModifyUrl(product.Name);
            List <UrlRecord> urlRecordsList     = _thyMenaUrlRecordRepository.FindUrlRecordsByEntityIdEntityName(product.Id, "Product");
            List <UrlRecord> urlRecordsToUpdate = new List <UrlRecord>();

            if (urlRecordsList != null && urlRecordsList.Count > 0)
            {
                UrlRecord urlRecord = urlRecordsList[0];
                urlRecord.Slug       = slug;
                urlRecord.IsActive   = true;
                urlRecord.LanguageId = 0;
                urlRecordsToUpdate.Add(urlRecord);
            }
            else
            {
                string           tmpSlug    = "";
                List <UrlRecord> urlRecords = _thyMenaUrlRecordRepository.FindSameUrlRecordsForDifferentProducts(
                    slug, "Product", product.Id);
                if (urlRecords != null && urlRecords.Count > 0)
                {
                    for (int i = 2; i < 6; i++)
                    {
                        tmpSlug    = slug + i.ToString();
                        urlRecords = _thyMenaUrlRecordRepository.FindSameUrlRecordsForDifferentProducts(
                            tmpSlug, "Product", product.Id);
                        if (urlRecords != null && urlRecords.Count > 0)
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                UrlRecord urlRecord = _thyMenaUrlRecordRepository.FindUrlRecordBySlugEntityName(tmpSlug, "Product");
                if (urlRecord == null)
                {
                    urlRecord.EntityId = product.Id;
                    urlRecordsToUpdate.Add(urlRecord);
                }
            }
            return(urlRecordsToUpdate);
        }
Пример #24
0
        //#region Utilities

        protected UrlRecordForCaching Map(UrlRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            var urlRecordForCaching = new UrlRecordForCaching
            {
                Id         = record.Id,
                EntityId   = record.EntityId,
                EntityName = record.EntityName,
                Slug       = record.Slug,
                IsActive   = record.IsActive
            };

            return(urlRecordForCaching);
        }
Пример #25
0
        public void Can_save_and_load_urlRecord()
        {
            var urlRecord = new UrlRecord
            {
                EntityId   = 1,
                EntityName = "EntityName 1",
                Slug       = "Slug 1",
                LanguageId = 2,
            };

            var fromDb = SaveAndLoadEntity(urlRecord);

            fromDb.ShouldNotBeNull();
            fromDb.EntityId.ShouldEqual(1);
            fromDb.EntityName.ShouldEqual("EntityName 1");
            fromDb.Slug.ShouldEqual("Slug 1");
            fromDb.LanguageId.ShouldEqual(2);
        }
Пример #26
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmAddUrl form = new FrmAddUrl();

            form.ShowDialog();
            foreach (String item in form.Urls)
            {
                UrlRecord record = new UrlRecord {
                    Url = item, Status = 0
                };
                m_records.Add(record);
            }

            BindingSource bs = new BindingSource();

            bs.DataSource       = m_records;
            this.dgv.DataSource = bs;
        }
Пример #27
0
        public bool Save(UrlRecord url)
        {
            if (url == null || string.IsNullOrEmpty(url.Slug))
            {
                return(false);
            }

            var m = (from t in urlRepository.Table
                     where t.Slug.Equals(url.Slug, StringComparison.InvariantCultureIgnoreCase) &&
                     t.EntityId == url.EntityId && t.EntityName == url.EntityName
                     select t).FirstOrDefault();

            if (m == null)
            {
                return(urlRepository.Insert(url));
            }
            return(true);
        }
Пример #28
0
        public ActionResult Create(PortfolioModel model)
        {
            model.Categories = portfolioCategoryService.GetActives();
            if (ModelState.IsValid)
            {
                var portfolio = new Portfolio()
                {
                    CategoryId    = model.CategoryId,
                    Description   = model.Content,
                    IsActive      = model.IsActive,
                    IsDelete      = model.IsDelete,
                    UserId        = User.Identity.GetUserId(),
                    Title         = model.Title,
                    CreateDateUtc = DateTime.UtcNow,
                    UpdateDateUtc = DateTime.UtcNow,
                    Format        = model.PortfolioFormat.ToString(),
                    FormatValue   = model.PortfolioFormatValue,
                    PictureId     = model.PictureId,
                    ViewName      = model.ViewName
                };

                var result = portfolioService.Insert(portfolio);
                if (result)
                {
                    this.NotifySuccess("Successfully saved.");
                }
                else
                {
                    this.NotifyError("Item can not saved!");
                }

                var urlRecord = new UrlRecord
                {
                    EntityId   = portfolio.Id,
                    EntityName = nameof(Portfolio),
                    Slug       = model.Title.ToUrlSlug()
                };
                urlService.Save(urlRecord);

                return(RedirectToAction("Edit", new { Id = portfolio.Id }));
            }

            return(View(model));
        }
Пример #29
0
        public ActionResult Create(JobModel model)
        {
            model.Categories = jobCategoryService.GetActives();
            if (ModelState.IsValid)
            {
                var job = new Job()
                {
                    CategoryId    = model.CategoryId,
                    Description   = model.Description,
                    IsActive      = model.IsActive,
                    IsDelete      = model.IsDelete,
                    JobType       = model.WorkType,
                    Location      = model.Location,
                    SallaryMin    = model.SallaryMin,
                    SallaryMax    = model.SallaryMax,
                    Title         = model.Title,
                    CreateDateUtc = DateTime.UtcNow,
                    UpdateDateUtc = DateTime.UtcNow,
                };

                var result = jobService.Insert(job);
                if (result)
                {
                    this.NotifySuccess("Successfully saved.");
                }
                else
                {
                    this.NotifyError("Item can not saved!");
                }

                var urlRecord = new UrlRecord
                {
                    EntityId   = job.Id,
                    EntityName = nameof(Job),
                    Slug       = model.Title.ToUrlSlug()
                };
                urlService.Save(urlRecord);

                return(RedirectToAction("Edit", new { Id = job.Id }));
            }

            return(View(model));
        }
Пример #30
0
        private void InsertUrlRecord(T entity)
        {
            var namedEntity = (INameSupported)entity;
            var slugEntity  = entity as ISlugSupported;

            var seName = SeoExtensions.GetSeName(namedEntity.Name, true, false);

            seName = ValidateSeName(entity, seName, namedEntity.Name);
            var urlRecord = new UrlRecord()
            {
                EntityId   = entity.Id,
                EntityName = typeof(T).Name,
                IsActive   = true,
                LanguageId = _workContext.WorkingLanguage.Id,
                Slug       = seName
            };

            _urlRecordService.InsertUrlRecord(urlRecord);
        }
Пример #31
0
        public static UrlRecord GetManufacturerUrlRecordForInsert(List <UrlRecord> urlRecords, int manufacturerId, string brand, List <UrlRecord> existingInsertUrlRecords)
        {
            UrlRecord existingInsertUrlRecord = existingInsertUrlRecords.Where(ur => ur.EntityId == manufacturerId && ur.EntityName == "Manufacturer").FirstOrDefault();

            if (existingInsertUrlRecord == null)
            {
                return(new UrlRecord()
                {
                    EntityId = manufacturerId,
                    EntityName = "Manufacturer",
                    Slug = UrlUtil.ModifyUrl(brand),
                    IsActive = true,
                    LanguageId = 0,
                });
            }
            else
            {
                return(null);
            }
        }
        public static UrlRecord GetCategoryUrlRecordForInsert(List <UrlRecord> urlRecords, Category category, List <UrlRecord> existingInsertUrlRecords)
        {
            UrlRecord existingInsertUrlRecord = existingInsertUrlRecords.Where(ur => ur.EntityId == category.Id && ur.EntityName == "Category").FirstOrDefault();

            if (existingInsertUrlRecord == null)
            {
                return(new UrlRecord()
                {
                    EntityId = category.Id,
                    EntityName = "Category",
                    Slug = UrlUtil.ModifyUrl(category.Name),
                    IsActive = true,
                    LanguageId = 0,
                });
            }
            else
            {
                return(null);
            }
        }
Пример #33
0
            // Parses the URLs of this webpage.
            Task ParseUrls(HtmlNode doc, Uri url)
            {
                using var dataHelper = new DataHelper(DataHelperConfig.Create(config.ConnectionString));

                try
                {
                    var urls = doc.Descendants("a")
                               .Select(x => x.GetAttributeValue("href", "").ToLower())                                        // Select all links of `a` tag
                               .Where(x => !string.IsNullOrWhiteSpace(x))                                                     // remove empty links
                               .Select(x => new Uri(url, x))                                                                  // Convert it to a Uri type
                               .Select(x => new Uri(x.GetComponents(UriComponents.HttpRequestUrl, UriFormat.Unescaped)))      // format the links
                               .Distinct()                                                                                    // Make it unique
                               .Where(x => !(x.LocalPath.EndsWith(".js") || x.LocalPath.EndsWith(".css")))                    // Don't include JS and CSS files
                               .Where(x => !(dataHelper.Queue.Any(y => y.Url == x) || dataHelper.Index.Any(y => y.Url == x))) // Check if already exists
                               .Select(x =>
                    {
                        DomainName dn;
                        // making sure there is no duplicates
                        if (!dataHelper.DomainNames.Any(y => y.Domain == x.DnsSafeHost))
                        {
                            dn = dataHelper.DomainNames.Add(new DomainName(x.DnsSafeHost)).Entity;
                            dataHelper.SaveChanges();
                        }
                        else
                        {
                            dn = dataHelper.DomainNames.First(y => y.Domain == x.DnsSafeHost);
                        }
                        var ur = new UrlRecord(x, dn);
                        dn.AddUrlRecord(ur);
                        return(ur);
                    });     // Convert it to a UrlRecord type

                    dataHelper.Queue.AddRange(urls);
                    dataHelper.SaveChanges();
                }
                catch (Exception e)
                {
                    LogMessage($"Parsing URLs in `{url.AbsoluteUri}` didn't success. Error: {e.Message}", DebugLevel.Warning);
                }
                return(Task.CompletedTask);
            }
Пример #34
0
        public IActionResult Index(string?group)
        {
            if (string.IsNullOrEmpty(group))
            {
                List <Category> model = new List <Category>();
                foreach (Category category in _categoryService.GetAllCategories())
                {
                    if (_categoryService.GetAllCategoriesByParentCategoryId(category.Id).Count > 0)
                    {
                        model.Add(category);
                    }
                }
                return(View(model));
            }
            UrlRecord record = _urlRecordService.GetBySlug(group);

            if (record == null)
            {
                return(View(null));
            }
            return(View(new List <Category>(_categoryService.GetAllCategoriesByParentCategoryId(record.EntityId))));
        }