Exemple #1
0
        public async Task <bool> UpdateCategory(Category category)
        {
            using (DbContext ctx = new advanced7Context())
            {
                ctx.Set <Category>().Update(category);
                using (var writer = GetCategoryIndexWriter())
                {
                    writer.UpdateDocument(new Term("Id", category.Id.ToString()), GetCategoryDoc(category));

                    return(await ctx.SaveChangesAsync() > 0);
                }
            }
        }
Exemple #2
0
        public async Task <bool> AddCategory(Category category)
        {
            using (DbContext ctx = new advanced7Context())
            {
                await ctx.AddAsync(category);

                using (IndexWriter writer = GetCategoryIndexWriter())
                {
                    writer.AddDocument(GetCategoryDoc(category));
                    writer.Flush(false, false);
                    return(await ctx.SaveChangesAsync() > 0);
                }
            }
        }
Exemple #3
0
        public async Task InitIndex()
        {
            using (DbContext ctx = new advanced7Context())
            {
                using (var writer = GetCategoryIndexWriter())
                {
                    var entices = await ctx.Set <Category>().ToListAsync();

                    foreach (var item in entices)
                    {
                        writer.AddDocument(GetCategoryDoc(item));
                    }

                    writer.Flush(false, false);
                }
            }
        }