public async Task SeedAsync(DataSeedContext context)
        {
            if (await _bookRepository.GetCountAsync() <= 0)
            {
                await _bookRepository.InsertAsync(
                    new Book
                {
                    Name        = "1984",
                    Type        = BookType.Dystopia,
                    PublishDate = new DateTime(1949, 6, 8),
                    Price       = 19.84f
                },
                    autoSave : true
                    );

                await _bookRepository.InsertAsync(
                    new Book
                {
                    Name        = "The Hitchhiker's Guide to the Galaxy",
                    Type        = BookType.ScienceFiction,
                    PublishDate = new DateTime(1995, 9, 27),
                    Price       = 42.0f
                },
                    autoSave : true
                    );
            }

            if (await _authorRepository.CountAsync() < 0)
            {
                await _authorRepository.InsertAsync(await _authorManager.CreateAsync("George Orwell", new DateTime(1903, 06, 25), "Orwell produced literary criticism and poetry, fiction and polemical journalism; and is best known for the allegorical novella Animal Farm (1945) and the dystopian novel Nineteen Eighty-Four (1949)."), autoSave : false);

                await _authorRepository.InsertAsync(await _authorManager.CreateAsync("Douglas Adam", new DateTime(1952, 03, 11), "Douglas Adams was an English author, screenwriter, essayist, humorist, satirist and dramatist. Adams was an advocate for environmentalism and conservation, a lover of fast cars, technological innovation and the Apple Macintosh, and a self-proclaimed 'radical atheist'."), autoSave : false);
            }
        }
Ejemplo n.º 2
0
        public virtual async Task SeedAsync(DataSeedContext context)
        {
            using (_currentTenant.Change(context?.TenantId))
            {
                await _identityResourceDataSeeder.CreateStandardResourcesAsync();
                await CreateApiResourcesAsync();
                await CreateApiScopesAsync();
                await CreateClientsAsync();
            }

            if (await _bookRepository.GetCountAsync() > 0)
            {
                return;
            }

            var orwell = await _authorRepository.InsertAsync(
                await _authorManager.CreateAsync(
                    "George Orwell",
                    new DateTime(1903, 06, 25),
                    "Orwell produced literary criticism and poetry, fiction and polemical journalism; and is best known for the allegorical novella Animal Farm (1945) and the dystopian novel Nineteen Eighty-Four (1949)."
                    )
                );

            var douglas = await _authorRepository.InsertAsync(
                await _authorManager.CreateAsync(
                    "Douglas Adams",
                    new DateTime(1952, 03, 11),
                    "Douglas Adams was an English author, screenwriter, essayist, humorist, satirist and dramatist. Adams was an advocate for environmentalism and conservation, a lover of fast cars, technological innovation and the Apple Macintosh, and a self-proclaimed 'radical atheist'."
                    )
                );

            await _bookRepository.InsertAsync(
                new Book
            {
                AuthorId    = orwell.Id,          // SET THE AUTHOR
                Name        = "1984",
                Type        = BookType.Dystopia,
                PublishDate = new DateTime(1949, 6, 8),
                Price       = 19.84f
            },
                autoSave : true
                );

            await _bookRepository.InsertAsync(
                new Book
            {
                AuthorId    = douglas.Id,          // SET THE AUTHOR
                Name        = "The Hitchhiker's Guide to the Galaxy",
                Type        = BookType.ScienceFiction,
                PublishDate = new DateTime(1995, 9, 27),
                Price       = 42.0f
            },
                autoSave : true
                );
        }
Ejemplo n.º 3
0
        public async Task <AuthorWithDetailsDto> CreateAuthorWithBooksAsync(CreateAuthorWithBookDto input)
        {
            var author = await _authorManager.CreateAsync(
                input.Name,
                input.BirthDate,
                input.ShortBio
                );

            var createdAuthor = await _authorRepository.InsertAsync(author);

            var authorWithBooks = ObjectMapper.Map <Author, AuthorWithDetailsDto>(createdAuthor);

            foreach (var book in input.Books)
            {
                var bookEntity = ObjectMapper.Map <CreateBookDto, Book>(book);
                bookEntity.AuthorId = author.Id;
                var createdBook = await Repository.InsertAsync(bookEntity);

                var bookDto = ObjectMapper.Map <Book, BookDto>(createdBook);
                bookDto.AuthorName = author.Name;
                authorWithBooks.Books.Add(bookDto);
            }

            return(authorWithBooks);
        }
Ejemplo n.º 4
0
        public async Task <AuthorDto> CreateAsync(CreateAuthorDto input)
        {
            var author = await _authorManager.CreateAsync(input.Name, input.BirthDate, input.ShortBio);

            await _authorRepository.InsertAsync(author, autoSave : false);

            return(ObjectMapper.Map <Author, AuthorDto>(author));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 初始化数据处理
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task SeedAsync(DataSeedContext context)
        {
            if (await _bookRepository.GetCountAsync() > 0)
            {
                return;
            }
            if (await _authorRepository.GetCountAsync() <= 0)
            {
                var authorLi = await _authorRepository.InsertAsync(
                    await _authorManager.CreateAsync(
                        "Li", new DateTime(1993, 08, 25),
                        "qwertyuiopasdfghjkl")
                    );

                var authorJun = await _authorRepository.InsertAsync(
                    await _authorManager.CreateAsync(
                        "Jun", new DateTime(1993, 08, 25),
                        "sadfkjsdfsaoisdadgfsagdjskssgdladsgafjsfjlskdejfjsfjsaklfjserdofisjdfklsjdfoisdjflskdfjsdhsofjsldkfjsodfisjdkfsiodfjskfsjlgsgijgsagsgsdgsagwgehrtntvsvdsdavvsfbsbsbsfabbsfgsagsdagsadg")
                    );

                if (await _bookRepository.GetCountAsync() <= 0)
                {
                    var bookHD = await _bookRepository.InsertAsync(
                        new Book()
                    {
                        AuthorId    = authorLi.Id,
                        Name        = "2021荒岛日记",
                        Type        = BookType.Adventure,
                        PublishDate = new DateTime(2021, 5, 6),
                        Price       = 19.84f,
                        IsTrue      = BookIsTrue.True
                    },
                        autoSave : true
                        );

                    var bookKB = await _bookRepository.InsertAsync(
                        new Book()
                    {
                        AuthorId    = authorJun.Id,
                        Name        = "2021恐怖小船",
                        Type        = BookType.Horror,
                        PublishDate = new DateTime(2021, 5, 6),
                        Price       = 42.0f,
                        IsTrue      = BookIsTrue.True
                    },
                        autoSave : true
                        );

                    if (await _bookMarkRepository.GetCountAsync() <= 0)
                    {
                        await _bookMarkRepository.InsertAsync(
                            new BookMark()
                        {
                            Name            = "testBookMark",
                            BookId          = bookHD.Id,
                            PageNum         = 1,
                            RowNum          = 10,
                            BookMarkContent = "123456",
                            ContentLength   = 6,
                            StartingWordNum = 5
                        },
                            autoSave : true);

                        await _bookMarkRepository.InsertAsync(
                            new BookMark()
                        {
                            Name            = "testBookMark2",
                            BookId          = bookKB.Id,
                            PageNum         = 1,
                            RowNum          = 10,
                            BookMarkContent = "1234567",
                            ContentLength   = 7,
                            StartingWordNum = 5
                        },
                            autoSave : true);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public async Task SeedAsync(DataSeedContext context)
        {
            if (await _bookRepository.GetCountAsync() > 0)
            {
                return;
            }

            var orwell = await _authorRepository.InsertAsync(
                await _authorManager.CreateAsync(
                    "George Orwell",
                    new DateTime(1903, 06, 25),
                    "Orwell produced literary criticism and poetry, fiction and polemical journalism; and is best known for the allegorical novella Animal Farm (1945) and the dystopian novel Nineteen Eighty-Four (1949)."
                    )
                );

            var douglas = await _authorRepository.InsertAsync(
                await _authorManager.CreateAsync(
                    "Douglas Adams",
                    new DateTime(1952, 03, 11),
                    "Douglas Adams was an English author, screenwriter, essayist, humorist, satirist and dramatist. Adams was an advocate for environmentalism and conservation, a lover of fast cars, technological innovation and the Apple Macintosh, and a self-proclaimed 'radical atheist'."
                    )
                );

            await _bookRepository.InsertAsync(
                new Book
            {
                AuthorId    = orwell.Id,
                Name        = "1984",
                Type        = BookType.Dystopia,
                PublishDate = new DateTime(1949, 6, 8),
                Price       = 19.84f
            },
                autoSave : true
                );

            await _bookRepository.InsertAsync(
                new Book
            {
                AuthorId    = douglas.Id,
                Name        = "The Hitchhiker's Guide to the Galaxy",
                Type        = BookType.ScienceFiction,
                PublishDate = new DateTime(1995, 9, 27),
                Price       = 42.0f
            },
                autoSave : true
                );

            #region Events Seed Data
            await _EventRepository.InsertAsync(
                new Event
            {
                Title       = " Event 1 ",
                Description = " Event 1 Description ",
                StartDate   = new DateTime(2020, 10, 1),
                EndDate     = new DateTime(2020, 10, 1),
                EventType   = EventType.Event
            },
                autoSave : true
                );

            await _EventRepository.InsertAsync(
                new Event
            {
                Title       = " Event 2 ",
                Description = " Event 2 Description ",
                StartDate   = new DateTime(2020, 10, 1),
                EndDate     = new DateTime(2020, 10, 1),
                EventType   = EventType.Event
            },
                autoSave : true
                );


            await _EventRepository.InsertAsync(
                new Event
            {
                Title       = " Event 3 ",
                Description = " Event 3 Description ",
                StartDate   = new DateTime(2020, 10, 1),
                EndDate     = new DateTime(2020, 10, 1),
                EventType   = EventType.Exhibition
            },
                autoSave : true
                );


            await _EventRepository.InsertAsync(
                new Event
            {
                Title       = " Event 4 ",
                Description = " Event 4 Description ",
                StartDate   = new DateTime(2020, 10, 1),
                EndDate     = new DateTime(2020, 10, 1),
                EventType   = EventType.Exhibition
            },
                autoSave : true
                );


            await _EventRepository.InsertAsync(
                new Event
            {
                Title       = " Event 5 ",
                Description = " Event 5 Description ",
                StartDate   = new DateTime(2020, 10, 1),
                EndDate     = new DateTime(2020, 10, 1),
                EventType   = EventType.Exhibition
            },
                autoSave : true
                );


            await _EventRepository.InsertAsync(
                new Event
            {
                Title       = " Event 6 ",
                Description = " Event 6 Description ",
                StartDate   = new DateTime(2020, 10, 1),
                EndDate     = new DateTime(2020, 10, 1),
                EventType   = EventType.Initiative
            },
                autoSave : true
                );

            await _EventRepository.InsertAsync(
                new Event
            {
                Title       = " Event 7 ",
                Description = " Event 7 Description ",
                StartDate   = new DateTime(2020, 10, 1),
                EndDate     = new DateTime(2020, 10, 1),
                EventType   = EventType.Initiative
            },
                autoSave : true
                );

            #endregion
        }
        public async Task SeedAsync(DataSeedContext context)
        {
            //如果数据库没有图书就初始化两本书插入数据库
            if (await _bookRepository.GetCountAsync() > 0)
            {
                return;
            }

            var orwell = await _authorRepository.InsertAsync(
                await _authorManager.CreateAsync(
                    "George Orwell",
                    new DateTime(1903, 06, 25),
                    "Orwell produced literary criticism and poetry, fiction and polemical journalism; and is best known for the allegorical novella Animal Farm (1945) and the dystopian novel Nineteen Eighty-Four (1949)."
                    )
                );

            var douglas = await _authorRepository.InsertAsync(
                await _authorManager.CreateAsync(
                    "Douglas Adams",
                    new DateTime(1952, 03, 11),
                    "Douglas Adams was an English author, screenwriter, essayist, humorist, satirist and dramatist. Adams was an advocate for environmentalism and conservation, a lover of fast cars, technological innovation and the Apple Macintosh, and a self-proclaimed 'radical atheist'."
                    )
                );

            await _bookRepository.InsertAsync(
                new Book
            {
                AuthorId    = orwell.Id, // SET THE AUTHOR
                Name        = "1984",
                Type        = BookType.Dystopia,
                PublishDate = new DateTime(1949, 6, 8),
                Price       = 19.84f
            },
                autoSave : true
                );

            await _bookRepository.InsertAsync(
                new Book
            {
                AuthorId    = douglas.Id,  // SET THE AUTHOR
                Name        = "The Hitchhiker's Guide to the Galaxy",
                Type        = BookType.ScienceFiction,
                PublishDate = new DateTime(1995, 9, 27),
                Price       = 42.0f
            },
                autoSave : true
                );

            //if (await _bookRepository.GetCountAsync() <= 0)
            //{
            //    await _bookRepository.InsertAsync(
            //        new Book
            //        {
            //            Name = "1984",
            //            Type = BookType.Dystopia,
            //            PublishDate = new DateTime(1949, 6, 8),
            //            Price = 19.84f
            //        },
            //        autoSave: true
            //    );

            //    await _bookRepository.InsertAsync(
            //        new Book
            //        {
            //            Name = "The Hitchhiker's Guide to the Galaxy",
            //            Type = BookType.ScienceFiction,
            //            PublishDate = new DateTime(1995, 9, 27),
            //            Price = 42.0f
            //        },
            //        autoSave: true
            //    );
            //}

            //// ADDED SEED DATA FOR AUTHORS
            //if (await _authorRepository.GetCountAsync() <= 0)
            //{
            //    await _authorRepository.InsertAsync(
            //        await _authorManager.CreateAsync(
            //            "George Orwell",
            //            new DateTime(1903, 06, 25),
            //            "Orwell produced literary criticism and poetry, fiction and polemical journalism; and is best known for the allegorical novella Animal Farm (1945) and the dystopian novel Nineteen Eighty-Four (1949)."
            //        )
            //    );

            //    await _authorRepository.InsertAsync(
            //        await _authorManager.CreateAsync(
            //            "Douglas Adams",
            //            new DateTime(1952, 03, 11),
            //            "Douglas Adams was an English author, screenwriter, essayist, humorist, satirist and dramatist. Adams was an advocate for environmentalism and conservation, a lover of fast cars, technological innovation and the Apple Macintosh, and a self-proclaimed 'radical atheist'."
            //        )
            //    );
            //}
        }
Ejemplo n.º 8
0
        public async Task SeedAsync(DataSeedContext context)
        {
            if (await _bookRepository.GetCountAsync() > 0)
            {
                return;
            }

            var orwell = await _authorRepository.InsertAsync(
                await _authorManager.CreateAsync(
                    "George Orwell",
                    new DateTime(1903, 06, 25),
                    "Orwell produced literary criticism and poetry, fiction and polemical journalism; and is best known for the allegorical novella Animal Farm (1945) and the dystopian novel Nineteen Eighty-Four (1949)."
                    )
                );

            var douglas = await _authorRepository.InsertAsync(
                await _authorManager.CreateAsync(
                    "Douglas Adams",
                    new DateTime(1952, 03, 11),
                    "Douglas Adams was an English author, screenwriter, essayist, humorist, satirist and dramatist. Adams was an advocate for environmentalism and conservation, a lover of fast cars, technological innovation and the Apple Macintosh, and a self-proclaimed 'radical atheist'."
                    )
                );

            //await _bookRepository.InsertAsync(
            //    new Book
            //    {
            //        AuthorId = orwell.Id, // SET THE AUTHOR
            //        Name = "1984",
            //        Type = BookType.Dystopia,
            //        PublishDate = new DateTime(1949, 6, 8),
            //        Price = 19.84f
            //    },
            //    autoSave: true
            //);

            //await _bookRepository.InsertAsync(
            //    new Book
            //    {
            //        AuthorId = douglas.Id, // SET THE AUTHOR
            //        Name = "The Hitchhiker's Guide to the Galaxy",
            //        Type = BookType.ScienceFiction,
            //        PublishDate = new DateTime(1995, 9, 27),
            //        Price = 42.0f
            //    },
            //    autoSave: true
            //);

            Guid guid1 = new Guid("4296e711-9e1b-84b9-7c33-39fb7023c6f5");
            Guid guid2 = new Guid("d28db219-54dc-c2b4-c787-39fb7023c721");
            await _bookMarkRepository.InsertAsync(
                new BookMark
            {
                BookId         = guid1,
                BookName       = "1984",
                MarkPage       = 1,
                MarkAnnotation = "1984第一页的一个注释,1984一页的一个注释",
                LastUpdateTime = DateTime.Now
            },
                autoSave : true
                );

            await _bookMarkRepository.InsertAsync(
                new BookMark
            {
                BookId         = guid2,
                BookName       = "The Hitchhiker's Guide to the Galaxy",
                MarkPage       = 1,
                MarkAnnotation = "The Hitchhiker's Guide to the Galaxy第一页的一个注释,The Hitchhiker's Guide to the Galaxy一页的一个注释",
                LastUpdateTime = DateTime.Now
            },
                autoSave : true
                );
        }