Exemplo n.º 1
0
        public async Task <DeletedCleanerCount> DeleteAllMarkedMaterials()
        {
            int deletedMaterialCount = 0;
            int deletedCommentCount  = 0;

            using (await db.BeginTransactionAsync())
            {
                var materials = db.Materials.Where(x => x.DeletedDate != null);

                await materials.Set(x => x.LastCommentId, (x) => null).UpdateAsync();

                deletedCommentCount += await db.Comments.Where(x => x.Material.DeletedDate != null).DeleteAsync();

                deletedMaterialCount += await materials.DeleteAsync();

                deletedCommentCount += await db.Comments.Where(x => x.DeletedDate != null).AsQueryable().DeleteAsync();

                await db.CommitTransactionAsync();
            }

            return(new DeletedCleanerCount
            {
                DeletedMaterials = deletedMaterialCount, DeletedComments = deletedCommentCount
            });
        }