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 JsonResult Remove(string id) { JsonOperationResponse result = new JsonOperationResponse(); result.Successful = false; try { var parts = id.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { var attachmentHash = parts[0]; var attachmentId = parts[1]; Attachment at = new Attachment() { Id = Convert.ToInt64(attachmentId) }; at.Author = KBVaultHelperFunctions.UserAsKbUser(User).Id; KbVaultAttachmentHelper.RemoveAttachment(attachmentHash, KBVaultHelperFunctions.UserAsKbUser(User).Id); KbVaultLuceneHelper.RemoveAttachmentFromIndex(at); result.Successful = true; return(Json(result)); } throw new ArgumentOutOfRangeException("Invalid file hash"); } catch (Exception ex) { Log.Error(ex); result.ErrorMessage = ex.Message; return(Json(result)); } }
public JsonResult Remove(int id) { var result = new JsonOperationResponse(); try { using (var db = new KbVaultContext()) { var currentUserId = KBVaultHelperFunctions.UserAsKbUser(User).Id; var queryParams = new SqlParameter[] { new SqlParameter("ArticleId", id) }; db.Database.ExecuteSqlCommand("Delete from ArticleTag Where ArticleId = @ArticleId", queryParams); var article = db.Articles.Single(a => a.Id == id); if (article == null) { throw new Exception(ErrorMessages.ArticleNotFound); } while (article.Attachments.Count > 0) { var a = article.Attachments.First(); KbVaultAttachmentHelper.RemoveLocalAttachmentFile(a); KbVaultLuceneHelper.RemoveAttachmentFromIndex(a); article.Attachments.Remove(a); /* * Also remove the attachment from db.attachments collection * * http://stackoverflow.com/questions/17723626/entity-framework-remove-vs-deleteobject * * If the relationship is required (the FK doesn't allow NULL values) and the relationship is not * identifying (which means that the foreign key is not part of the child's (composite) primary key) * you have to either add the child to another parent or you have to explicitly delete the child * (with DeleteObject then). If you don't do any of these a referential constraint is * violated and EF will throw an exception when you call SaveChanges - * the infamous "The relationship could not be changed because one or more of the foreign-key properties * is non-nullable" exception or similar. */ db.Attachments.Remove(a); } article.Author = currentUserId; KbVaultLuceneHelper.RemoveArticleFromIndex(article); db.Articles.Remove(article); db.SaveChanges(); result.Data = id; result.Successful = true; return(Json(result)); } } catch (Exception ex) { Log.Error(ex); result.Successful = false; result.ErrorMessage = ex.Message; return(Json(result)); } }
public async Task <IActionResult> DeleteConfirmed(long id) { var article = await _context.Articles.FindAsync(id); //************************************************************* //stari kod - vrati se while (article.Attachments.Count > 0) { var a = article.Attachments.First(); attachmentHelper.RemoveLocalAttachmentFile(a); _lucene.RemoveAttachmentFromIndex(a); article.Attachments.Remove(a); /* * Also remove the attachment from db.attachments collection * * http://stackoverflow.com/questions/17723626/entity-framework-remove-vs-deleteobject * * If the relationship is required (the FK doesn't allow NULL values) and the relationship is not * identifying (which means that the foreign key is not part of the child's (composite) primary key) * you have to either add the child to another parent or you have to explicitly delete the child * (with DeleteObject then). If you don't do any of these a referential constraint is * violated and EF will throw an exception when you call SaveChanges - * the infamous "The relationship could not be changed because one or more of the foreign-key properties * is non-nullable" exception or similar. */ _context.Attachments.Remove(a); } string currentUser = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); article.AuthorId = currentUser; //KbVaultLuceneHelper.RemoveArticleFromIndex(article); //************************************************************* _context.Articles.Remove(article); await _context.SaveChangesAsync(); //0109 - activity _activityRepository.ArticleActivities(article, "deleted"); return(RedirectToAction(nameof(Index))); }
public JsonResult Remove(string id) { var result = new JsonOperationResponse { Successful = false }; try { var parts = id.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { var attachmentHash = parts[0]; var attachmentId = parts[1]; var at = new Attachment { Id = Convert.ToInt64(attachmentId), //AuthorId = KBVaultHelperFunctions.UserAsKbUser(User).Id AuthorId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier) }; RemoveAttachment(attachmentHash, _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier), _env); _lucene.RemoveAttachmentFromIndex(at); result.Successful = true; return(Json(result)); } throw new ArgumentOutOfRangeException("Invalid file hash"); } catch (Exception ex) { log.Error(ex); result.ErrorMessage = ex.Message; return(Json(result)); } }