public async Task CanGetPublicKnowledgebaseArticles() { ClearArticleRepository(); var article1 = new KnowledgebaseArticle { Name = "CanGetPublicKnowledgebaseArticlesPublic1", Published = true }; var article2 = new KnowledgebaseArticle { Name = "CanGetPublicKnowledgebaseArticlesPublic2", Published = true }; var article3 = new KnowledgebaseArticle { Name = "CanGetPublicKnowledgebaseArticlesNotPublic", Published = false }; await _knowledgebaseService.InsertKnowledgebaseArticle(article1); await _knowledgebaseService.InsertKnowledgebaseArticle(article2); var found = await _knowledgebaseService.GetPublicKnowledgebaseArticles(); Assert.AreEqual(2, found.Count); Assert.AreEqual(true, found.Any(x => x.Name == "CanGetPublicKnowledgebaseArticlesPublic1")); Assert.AreEqual(true, found.Any(x => x.Name == "CanGetPublicKnowledgebaseArticlesPublic2")); Assert.AreEqual(false, found.Any(x => x.Name == "CanGetPublicKnowledgebaseArticlesNotPublic")); }
public virtual async Task DeleteKnowledgebaseArticle(KnowledgebaseArticle knowledgebaseArticle) { await _knowledgebaseService.DeleteKnowledgebaseArticle(knowledgebaseArticle); await _customerActivityService.InsertActivity("DeleteKnowledgebaseArticle", knowledgebaseArticle.Id, _translationService.GetResource("ActivityLog.DeleteKnowledgebaseArticle"), knowledgebaseArticle.Name); }
public async Task AddArticleCommentTokens(LiquidObject liquidObject, KnowledgebaseArticle article, KnowledgebaseArticleComment articleComment, Store store, Language language) { var liquidKnowledgebase = new LiquidKnowledgebase(article, articleComment, store, language); liquidObject.Knowledgebase = liquidKnowledgebase; await _mediator.EntityTokensAdded(articleComment, liquidKnowledgebase, liquidObject); }
/// <summary> /// Deletes knowledgebase article /// </summary> /// <param name="id"></param> public virtual void DeleteKnowledgebaseArticle(KnowledgebaseArticle ka) { _knowledgebaseArticleRepository.Delete(ka); _cacheManager.RemoveByPattern(ARTICLES_PATTERN_KEY); _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY); _eventPublisher.EntityDeleted(ka); }
public async Task CanGetKnowledgebaseArticles() { ClearArticleRepository(); var article1 = new KnowledgebaseArticle() { Published = true }; var article2 = new KnowledgebaseArticle() { Published = true }; var article3 = new KnowledgebaseArticle() { Published = true }; await _knowledgebaseService.InsertKnowledgebaseArticle(article1); await _knowledgebaseService.InsertKnowledgebaseArticle(article2); await _knowledgebaseService.InsertKnowledgebaseArticle(article3); var all = await _knowledgebaseService.GetKnowledgebaseArticles(); Assert.AreEqual(3, all.Count()); }
public async Task CanGetRelatedKnowledgebaseArticles() { ClearArticleRepository(); var article = new KnowledgebaseArticle { Name = "CanGetRelatedKnowledgebaseArticlesMain", Published = true }; var related1 = new KnowledgebaseArticle { Name = "CanGetRelatedKnowledgebaseArticlesRelated1", Published = true }; var related2 = new KnowledgebaseArticle { Name = "CanGetRelatedKnowledgebaseArticlesRelated2", Published = true }; await _knowledgebaseService.InsertKnowledgebaseArticle(related1); await _knowledgebaseService.InsertKnowledgebaseArticle(related2); article.RelatedArticles.Add(related1.Id); article.RelatedArticles.Add(related2.Id); await _knowledgebaseService.InsertKnowledgebaseArticle(article); var found = await _knowledgebaseService.GetRelatedKnowledgebaseArticles(article.Id); Assert.AreEqual(2, found.Count); Assert.AreEqual(true, found.Any(x => x.Name == "CanGetRelatedKnowledgebaseArticlesRelated1")); Assert.AreEqual(true, found.Any(x => x.Name == "CanGetRelatedKnowledgebaseArticlesRelated2")); }
public async Task CanGetPublicKnowledgebaseArticlesByKeyword() { ClearArticleRepository(); var article1 = new KnowledgebaseArticle { Name = "CanGetPublicKnowledgebaseArticlesByKeyword1", Published = true, }; var article2 = new KnowledgebaseArticle { Name = "test", Content = "CanGetPublicKnowledgebaseArticlesByKeyword2", Published = true, }; var article3 = new KnowledgebaseArticle { Name = "Tomato", Content = "Tomato", Published = true, }; await _knowledgebaseService.InsertKnowledgebaseArticle(article1); await _knowledgebaseService.InsertKnowledgebaseArticle(article2); await _knowledgebaseService.InsertKnowledgebaseArticle(article3); var found = await _knowledgebaseService.GetPublicKnowledgebaseArticlesByKeyword("keyword"); Assert.AreEqual(2, found.Count); Assert.AreEqual(true, found.Any(x => x.Name == "CanGetPublicKnowledgebaseArticlesByKeyword1")); Assert.AreEqual(true, found.Any(x => x.Name == "test")); Assert.AreEqual(false, found.Any(x => x.Name == "Tomato")); }
public virtual void DeleteKnowledgebaseArticle(KnowledgebaseArticle knowledgebaseArticle) { _knowledgebaseService.DeleteKnowledgebaseArticle(knowledgebaseArticle); _customerActivityService.InsertActivity("DeleteKnowledgebaseArticle", knowledgebaseArticle.Id, _localizationService.GetResource("ActivityLog.DeleteKnowledgebaseArticle"), knowledgebaseArticle.Name); }
public async Task CanGetPublicKnowledgebaseArticlesByCategory() { ClearArticleRepository(); var article1 = new KnowledgebaseArticle { Name = "CanGetPublicKnowledgebaseArticlesByCategory1", Published = true, ParentCategoryId = "CanGetPublicKnowledgebaseArticlesByCategory1" }; var article2 = new KnowledgebaseArticle { Name = "CanGetPublicKnowledgebaseArticlesByCategory2", Published = true, ParentCategoryId = "CanGetPublicKnowledgebaseArticlesByCategory1" }; var article3 = new KnowledgebaseArticle { Name = "CanGetPublicKnowledgebaseArticlesByCategory3", Published = true, ParentCategoryId = "CanGetPublicKnowledgebaseArticlesByCategory3" }; await _knowledgebaseService.InsertKnowledgebaseArticle(article1); await _knowledgebaseService.InsertKnowledgebaseArticle(article2); await _knowledgebaseService.InsertKnowledgebaseArticle(article3); var found = await _knowledgebaseService.GetPublicKnowledgebaseArticlesByCategory("CanGetPublicKnowledgebaseArticlesByCategory1"); Assert.AreEqual(2, found.Count); Assert.AreEqual(true, found.Any(x => x.Name == "CanGetPublicKnowledgebaseArticlesByCategory1")); Assert.AreEqual(true, found.Any(x => x.Name == "CanGetPublicKnowledgebaseArticlesByCategory2")); Assert.AreEqual(false, found.Any(x => x.Name == "CanGetPublicKnowledgebaseArticlesByCategory3")); }
public LiquidKnowledgebase(KnowledgebaseArticle article, KnowledgebaseArticleComment articleComment, Store store, Language language) { _article = article; _articleComment = articleComment; _store = store; _language = language; AdditionalTokens = new Dictionary <string, string>(); }
/// <summary> /// Deletes knowledgebase article /// </summary> /// <param name="id"></param> public virtual async Task DeleteKnowledgebaseArticle(KnowledgebaseArticle ka) { await _knowledgebaseArticleRepository.DeleteAsync(ka); _cacheManager.RemoveByPattern(ARTICLES_PATTERN_KEY); _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY); await _eventPublisher.EntityDeleted(ka); }
/// <summary> /// Edits knowledgebase article /// </summary> /// <param name="ka"></param> public virtual void UpdateKnowledgebaseArticle(KnowledgebaseArticle ka) { ka.UpdatedOnUtc = DateTime.UtcNow; _knowledgebaseArticleRepository.Update(ka); _cacheManager.RemoveByPattern(ARTICLES_PATTERN_KEY); _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY); _eventPublisher.EntityUpdated(ka); }
/// <summary> /// Inserts knowledgebase article /// </summary> /// <param name="ka"></param> public virtual async Task InsertKnowledgebaseArticle(KnowledgebaseArticle ka) { ka.CreatedOnUtc = DateTime.UtcNow; ka.UpdatedOnUtc = DateTime.UtcNow; await _knowledgebaseArticleRepository.InsertAsync(ka); _cacheManager.RemoveByPattern(ARTICLES_PATTERN_KEY); _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY); await _eventPublisher.EntityInserted(ka); }
/// <summary> /// Deletes knowledgebase article /// </summary> /// <param name="id"></param> public virtual async Task DeleteKnowledgebaseArticle(KnowledgebaseArticle ka) { await _knowledgebaseArticleRepository.DeleteAsync(ka); await _cacheManager.RemoveByPrefix(ARTICLES_PATTERN_KEY); await _cacheManager.RemoveByPrefix(CATEGORIES_PATTERN_KEY); await _mediator.EntityDeleted(ka); }
/// <summary> /// Deletes knowledgebase article /// </summary> /// <param name="id"></param> public virtual async Task DeleteKnowledgebaseArticle(KnowledgebaseArticle ka) { await _knowledgebaseArticleRepository.DeleteAsync(ka); await _cacheBase.RemoveByPrefix(CacheKey.ARTICLES_PATTERN_KEY); await _cacheBase.RemoveByPrefix(CacheKey.KNOWLEDGEBASE_CATEGORIES_PATTERN_KEY); await _mediator.EntityDeleted(ka); }
public LiquidObjectBuilder AddArticleCommentTokens(KnowledgebaseArticle article, KnowledgebaseArticleComment articleComment, Store store, Language language) { _chain.Add(async liquidObject => { var liquidKnowledgebase = new LiquidKnowledgebase(article, articleComment, store, language); liquidObject.Knowledgebase = liquidKnowledgebase; await _mediator.EntityTokensAdded(articleComment, liquidKnowledgebase, liquidObject); }); return(this); }
/// <summary> /// Edits knowledgebase article /// </summary> /// <param name="ka"></param> public virtual async Task UpdateKnowledgebaseArticle(KnowledgebaseArticle ka) { ka.UpdatedOnUtc = DateTime.UtcNow; await _knowledgebaseArticleRepository.UpdateAsync(ka); await _cacheBase.RemoveByPrefix(CacheKey.ARTICLES_PATTERN_KEY); await _cacheBase.RemoveByPrefix(CacheKey.KNOWLEDGEBASE_CATEGORIES_PATTERN_KEY); await _mediator.EntityUpdated(ka); }
/// <summary> /// Edits knowledgebase article /// </summary> /// <param name="ka"></param> public virtual async Task UpdateKnowledgebaseArticle(KnowledgebaseArticle ka) { ka.UpdatedOnUtc = DateTime.UtcNow; await _knowledgebaseArticleRepository.UpdateAsync(ka); await _cacheManager.RemoveByPattern(ARTICLES_PATTERN_KEY); await _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY); await _mediator.EntityUpdated(ka); }
public async Task CanDeleteKnowledgebaseArticle() { ClearArticleRepository(); var toDelete = new KnowledgebaseArticle(); await _knowledgebaseService.InsertKnowledgebaseArticle(toDelete); Assert.AreEqual(1, _articleRepository.Table.Count()); await _knowledgebaseService.DeleteKnowledgebaseArticle(toDelete); Assert.AreEqual(0, _articleRepository.Table.Count()); }
public async Task CanGetKnowledgebaseArticle() { var article = new KnowledgebaseArticle() { Name = "CanGetKnowledgebaseArticle" }; await _knowledgebaseService.InsertKnowledgebaseArticle(article); var actual = _articleRepository.Table.Where(x => x.Name == "CanGetKnowledgebaseArticle").First(); var found = await _knowledgebaseService.GetKnowledgebaseArticle(actual.Id); Assert.AreEqual(actual.Name, found.Name); }
public async Task GetKnowledgebaseArticlesByName() { ClearArticleRepository(); var article1 = new KnowledgebaseArticle { Name = "GetKnowledgebaseArticlesByName1", Published = true }; await _knowledgebaseService.InsertKnowledgebaseArticle(article1); var found = await _knowledgebaseService.GetKnowledgebaseArticlesByName("GetKnowledgebaseArticlesByName1"); Assert.AreEqual(1, found.Count); Assert.AreEqual("GetKnowledgebaseArticlesByName1", found.First().Name); }
public void GetKnowledgebaseArticle() { KnowledgebaseArticleCollection knowledgebaseArticles = TestSetup.KayakoApiService.Knowledgebase.GetKnowledgebaseArticles(); Assert.IsNotNull(knowledgebaseArticles, "No knowledgebase articles were returned"); Assert.IsNotEmpty(knowledgebaseArticles, "No knowledgebase articles were returned"); KnowledgebaseArticle knowledgebaseArticleToGet = knowledgebaseArticles[new Random().Next(knowledgebaseArticles.Count)]; Trace.WriteLine("GetKnowledgebaseArticle using knowledgebase article id: " + knowledgebaseArticleToGet.Id); KnowledgebaseArticle knowledgebaseArticle = TestSetup.KayakoApiService.Knowledgebase.GetKnowledgebaseArticle(knowledgebaseArticleToGet.Id); AssertObjectXmlEqual(knowledgebaseArticle, knowledgebaseArticleToGet); }
public virtual KnowledgebaseArticle UpdateKnowledgebaseArticleModel(KnowledgebaseArticle knowledgebaseArticle, KnowledgebaseArticleModel model) { knowledgebaseArticle = model.ToEntity(knowledgebaseArticle); knowledgebaseArticle.UpdatedOnUtc = DateTime.UtcNow; knowledgebaseArticle.Locales = model.Locales.ToLocalizedProperty(knowledgebaseArticle, x => x.Name, _urlRecordService); model.SeName = knowledgebaseArticle.ValidateSeName(model.SeName, knowledgebaseArticle.Name, true); knowledgebaseArticle.SeName = model.SeName; knowledgebaseArticle.AllowComments = model.AllowComments; _knowledgebaseService.UpdateKnowledgebaseArticle(knowledgebaseArticle); _urlRecordService.SaveSlug(knowledgebaseArticle, model.SeName, ""); _customerActivityService.InsertActivity("UpdateKnowledgebaseArticle", knowledgebaseArticle.Id, _localizationService.GetResource("ActivityLog.UpdateKnowledgebaseArticle"), knowledgebaseArticle.Name); return(knowledgebaseArticle); }
public void CanGetKnowledgebaseArticles() { ClearArticleRepository(); var article1 = new KnowledgebaseArticle(); var article2 = new KnowledgebaseArticle(); var article3 = new KnowledgebaseArticle(); _knowledgebaseService.InsertKnowledgebaseArticle(article1); _knowledgebaseService.InsertKnowledgebaseArticle(article2); _knowledgebaseService.InsertKnowledgebaseArticle(article3); var all = _knowledgebaseService.GetKnowledgebaseArticles(); Assert.AreEqual(3, all.Count()); }
public async Task CanUpdateKnowledgebaseArticle() { ClearArticleRepository(); var article = new KnowledgebaseArticle() { Name = "CanUpdateKnowledgebaseArticle" }; await _knowledgebaseService.InsertKnowledgebaseArticle(article); article.Name = "CanUpdateKnowledgebaseArticle1"; await _knowledgebaseService.UpdateKnowledgebaseArticle(article); var found = _articleRepository.Table.Where(x => x.Name == "CanUpdateKnowledgebaseArticle1"); Assert.AreEqual(1, found.Count()); }
public void CanGetHomepageKnowledgebaseArticles() { ClearArticleRepository(); var article1 = new KnowledgebaseArticle { ShowOnHomepage = true, Published = true, Name = "homepage" }; var article2 = new KnowledgebaseArticle { ShowOnHomepage = false, Published = true, Name = "not homepage" }; _knowledgebaseService.InsertKnowledgebaseArticle(article1); _knowledgebaseService.InsertKnowledgebaseArticle(article2); var homepage = _knowledgebaseService.GetHomepageKnowledgebaseArticles(); Assert.AreEqual(1, homepage.Count); Assert.AreEqual("homepage", homepage.First().Name); }
public void CanGetPublicKnowledgebaseArticle() { ClearArticleRepository(); var article1 = new KnowledgebaseArticle { Name = "CanGetPublicKnowledgebaseArticlePublic", Published = true }; var article2 = new KnowledgebaseArticle { Name = "CanGetPublicKnowledgebaseArticleNotPublic", Published = false }; _knowledgebaseService.InsertKnowledgebaseArticle(article1); _knowledgebaseService.InsertKnowledgebaseArticle(article2); var found1 = _knowledgebaseService.GetPublicKnowledgebaseArticle(article1.Id); var found2 = _knowledgebaseService.GetPublicKnowledgebaseArticle(article2.Id); Assert.AreEqual("CanGetPublicKnowledgebaseArticlePublic", found1.Name); Assert.AreEqual(null, found2); }
public void GetKnowledgebaseArticlesByCategoryId() { ClearArticleRepository(); var article1 = new KnowledgebaseArticle { ParentCategoryId = "GetKnowledgebaseArticlesByCategoryId1" }; var article2 = new KnowledgebaseArticle { ParentCategoryId = "GetKnowledgebaseArticlesByCategoryId1" }; var article3 = new KnowledgebaseArticle { ParentCategoryId = "GetKnowledgebaseArticlesByCategoryId2" }; _knowledgebaseService.InsertKnowledgebaseArticle(article1); _knowledgebaseService.InsertKnowledgebaseArticle(article2); _knowledgebaseService.InsertKnowledgebaseArticle(article3); var found = _knowledgebaseService.GetKnowledgebaseArticlesByCategoryId("GetKnowledgebaseArticlesByCategoryId1"); Assert.AreEqual(2, found.Count); }
private async Task PrepareKnowledgebaseArticleModel(KnowledgebaseArticleModel model, KnowledgebaseArticle article, ICustomerService customerService) { model.Content = article.GetTranslation(y => y.Content, _workContext.WorkingLanguage.Id); model.Name = article.GetTranslation(y => y.Name, _workContext.WorkingLanguage.Id); model.Id = article.Id; model.ParentCategoryId = article.ParentCategoryId; model.SeName = article.GetTranslation(y => y.SeName, _workContext.WorkingLanguage.Id); model.AllowComments = article.AllowComments; model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnArticleCommentPage; model.MetaTitle = article.GetTranslation(y => y.MetaTitle, _workContext.WorkingLanguage.Id); model.MetaDescription = article.GetTranslation(y => y.MetaDescription, _workContext.WorkingLanguage.Id); model.MetaKeywords = article.GetTranslation(y => y.MetaKeywords, _workContext.WorkingLanguage.Id); var articleComments = await _knowledgebaseService.GetArticleCommentsByArticleId(article.Id); foreach (var ac in articleComments) { var customer = await customerService.GetCustomerById(ac.CustomerId); var commentModel = new KnowledgebaseArticleCommentModel { Id = ac.Id, CustomerId = ac.CustomerId, CustomerName = customer.FormatUserName(_customerSettings.CustomerNameFormat), CommentText = ac.CommentText, CreatedOn = _dateTimeService.ConvertToUserTime(ac.CreatedOnUtc, DateTimeKind.Utc), }; model.Comments.Add(commentModel); } foreach (var id in article.RelatedArticles) { var a = await _knowledgebaseService.GetPublicKnowledgebaseArticle(id); if (a != null) { model.RelatedArticles.Add(new KnowledgebaseArticleModel { SeName = a.SeName, Id = a.Id, Name = a.Name }); } } var category = await _knowledgebaseService.GetKnowledgebaseCategory(article.ParentCategoryId); if (category != null) { string breadcrumbCacheKey = string.Format(CacheKeyConst.KNOWLEDGEBASE_CATEGORY_BREADCRUMB_KEY, article.ParentCategoryId, string.Join(",", _workContext.CurrentCustomer.GetCustomerGroupIds()), _workContext.CurrentStore.Id, _workContext.WorkingLanguage.Id); model.CategoryBreadcrumb = await _cacheBase.GetAsync(breadcrumbCacheKey, async() => (await category.GetCategoryBreadCrumb(_knowledgebaseService, _aclService, _workContext)) .Select(catBr => new KnowledgebaseCategoryModel { Id = catBr.Id, Name = catBr.GetTranslation(x => x.Name, _workContext.WorkingLanguage.Id), SeName = catBr.GetSeName(_workContext.WorkingLanguage.Id) }) .ToList() ); } }
private async Task PrepareKnowledgebaseArticleModel(KnowledgebaseArticleModel model, KnowledgebaseArticle article, ICustomerService customerService) { model.Content = article.GetLocalized(y => y.Content, _workContext.WorkingLanguage.Id); model.Name = article.GetLocalized(y => y.Name, _workContext.WorkingLanguage.Id); model.Id = article.Id; model.ParentCategoryId = article.ParentCategoryId; model.SeName = article.GetLocalized(y => y.SeName, _workContext.WorkingLanguage.Id); model.AllowComments = article.AllowComments; model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnArticleCommentPage; var articleComments = await _knowledgebaseService.GetArticleCommentsByArticleId(article.Id); foreach (var ac in articleComments) { var customer = await customerService.GetCustomerById(ac.CustomerId); var commentModel = new KnowledgebaseArticleCommentModel { Id = ac.Id, CustomerId = ac.CustomerId, CustomerName = customer.FormatUserName(_customerSettings.CustomerNameFormat), CommentText = ac.CommentText, CreatedOn = _dateTimeHelper.ConvertToUserTime(ac.CreatedOnUtc, DateTimeKind.Utc), AllowViewingProfiles = _customerSettings.AllowViewingProfiles && customer != null && !customer.IsGuest(), }; if (_customerSettings.AllowCustomersToUploadAvatars) { commentModel.CustomerAvatarUrl = await _pictureService.GetPictureUrl( customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType : PictureType.Avatar); } model.Comments.Add(commentModel); } foreach (var id in article.RelatedArticles) { var a = await _knowledgebaseService.GetPublicKnowledgebaseArticle(id); if (a != null) { model.RelatedArticles.Add(new KnowledgebaseArticleModel { SeName = a.SeName, Id = a.Id, Name = a.Name }); } } var category = await _knowledgebaseService.GetKnowledgebaseCategory(article.ParentCategoryId); if (category != null) { string breadcrumbCacheKey = string.Format(ModelCacheEventConst.KNOWLEDGEBASE_CATEGORY_BREADCRUMB_KEY, article.ParentCategoryId, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id, _workContext.WorkingLanguage.Id); model.CategoryBreadcrumb = await _cacheManager.GetAsync(breadcrumbCacheKey, async() => (await category.GetCategoryBreadCrumb(_knowledgebaseService, _aclService, _storeMappingService)) .Select(catBr => new KnowledgebaseCategoryModel { Id = catBr.Id, Name = catBr.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id), SeName = catBr.GetSeName(_workContext.WorkingLanguage.Id) }) .ToList() ); } }