public ActionResult Create([Bind("Id,Title,Content,IsDraft,PublishStartDate,PublishEndDate,SefName,Category,Tags")] CreateArticleViewModel model) { try { //ModelState.Remove("Category.Name"); //ModelState.Remove("Category.SefName"); if (ModelState.IsValid) { string currentUser = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); var article = _articleFactory.CreateArticleFromViewModel_Create(model, currentUser); var id = _articleRepository.Add(article, model.Tags, currentUser); if (article.IsDraft == 0) { //KbVaultLuceneHelper.AddArticleToIndex(article); _lucene.AddArticleToIndex(article); } //vrati se //ShowOperationMessage(UIResources.ArticleCreatePageCreateSuccessMessage); } } catch (Exception ex) { log.Error(ex); ModelState.AddModelError("Exception", ex.Message); } return(RedirectToAction(nameof(Index))); }
public ActionResult Create([Bind(Exclude = "Category.Name")] ArticleViewModel model) { try { ModelState.Remove("Category.Name"); if (ModelState.IsValid) { var article = ArticleFactory.CreateArticleFromViewModel(model, KBVaultHelperFunctions.UserAsKbUser(User).Id); var id = ArticleRepository.Add(article, model.Tags); if (article.IsDraft == 0) { KbVaultLuceneHelper.AddArticleToIndex(article); } ShowOperationMessage(UIResources.ArticleCreatePageCreateSuccessMessage); return(RedirectToAction("Edit", "Article", new { id = article.Id })); } return(View(model)); } catch (Exception ex) { Log.Error(ex); ModelState.AddModelError("Exception", ex.Message); return(View(model)); } }
public void RebuildIndexes() { var categories = CategoryRepository.GetAllCategories(); var totalCategories = categories.Count(); var indexingCategory = 1; foreach (var cat in categories) { Clients.All.updateProgress(indexingCategory, totalCategories, cat.Name, "-"); var articles = CategoryRepository.GetArticles(cat.Id); foreach (var article in articles) { Clients.All.updateProgress(indexingCategory, totalCategories, cat.Name, article.Title); foreach (var attachment in article.Attachments) { try { KbVaultLuceneHelper.RemoveAttachmentFromIndex(attachment); KbVaultLuceneHelper.AddAttachmentToIndex(attachment); } #pragma warning disable CC0004 // Catch block cannot be empty catch (Exception) { } #pragma warning restore CC0004 // Catch block cannot be empty } KbVaultLuceneHelper.AddArticleToIndex(article); } indexingCategory++; } Clients.All.updateProgress(string.Empty, string.Empty, string.Empty, "Finished indexing"); }
public void RebuildIndexes() { var categories = CategoryRepository.GetAllCategories(); int totalCategories = categories.Count(); int indexingCategory = 1; foreach (var cat in categories) { Clients.All.updateProgress(indexingCategory, totalCategories, cat.Name, "-"); var articles = CategoryRepository.GetArticles(cat.Id); foreach (var article in articles) { Clients.All.updateProgress(indexingCategory, totalCategories, cat.Name, article.Title); foreach (var attachment in article.Attachments) { try { KbVaultLuceneHelper.RemoveAttachmentFromIndex(attachment); KbVaultLuceneHelper.AddAttachmentToIndex(attachment); } catch (Exception ex) { //Eat it :d } } KbVaultLuceneHelper.AddArticleToIndex(article); } indexingCategory++; } Clients.All.updateProgress("", "", "", "Finished indexing"); }
public ActionResult Edit([Bind(Exclude = "Category.Name,Category.SefName")] ArticleViewModel model) { try { ModelState.Remove("Category.Name"); ModelState.Remove("Category.SefName"); if (ModelState.IsValid) { if (model.PublishEndDate < model.PublishStartDate) { ModelState.AddModelError("PublishDate", ErrorMessages.PublishEndDateMustBeGreater); } else { var article = ArticleRepository.Get(model.Id); article.CategoryId = model.Category.Id; article.IsDraft = model.IsDraft ? 1 : 0; article.PublishEndDate = model.PublishEndDate; article.PublishStartDate = model.PublishStartDate; article.Edited = DateTime.Now; article.Title = model.Title; article.Content = model.Content; article.Author = KBVaultHelperFunctions.UserAsKbUser(User).Id; article.SefName = model.SefName; ArticleRepository.Update(article, model.Tags); if (article.IsDraft == 0) { KbVaultLuceneHelper.AddArticleToIndex(article); } else { KbVaultLuceneHelper.RemoveArticleFromIndex(article); } ShowOperationMessage(UIResources.ArticleCreatePageEditSuccessMessage); } } } catch (Exception ex) { Log.Error(ex); ModelState.AddModelError("Exception", ex.Message); } return(View("Create", model)); }