Пример #1
0
        public static void AddChapter(int creativeId)
        {
            var entity = new CreativeNetworkEntities();
            var creative = entity.Creative.FirstOrDefault(a => a.Id == creativeId);
            int number;
            if (creative.Chapter.Select(a => a.Number).Max() == null)
            {
                number = 0;
            }
            else
            {
                number = (int) creative.Chapter.Select(a => a.Number).Max() +1;
            }

                var chapter = new Chapter
                    {
                        Text = "",
                        Name = "Chapter " + number.ToString(),
                        Number = number,

                    };
            entity.Creative.FirstOrDefault(a => a.Id == creativeId).Chapter.Add(chapter);
            entity.SaveChanges();
        }
Пример #2
0
        private static void _addToLuceneIndex(Chapter chapter, IndexWriter writer)
        {
            // remove older index entry
            var searchQuery = new TermQuery(new Term("IdChap", chapter.Id.ToString()));
            writer.DeleteDocuments(searchQuery);

            // add new index entry
            var doc = new Document();

            // add lucene fields mapped to db fields
            doc.Add(new Field("IdChap", chapter.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Name", chapter.Name, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Text", chapter.Text, Field.Store.YES, Field.Index.ANALYZED));

            // add entry to index
            writer.AddDocument(doc);
        }