Exemple #1
0
        public static void CreateSlides(BookStoreDbContext dbContext, UserManager <ApplicationUser> userManager)
        {
            var          userId = userManager.FindByEmailAsync("*****@*****.**").Result.Id;
            List <Slide> slides = new List <Slide>
            {
                new Slide
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "slide 1",
                    UserId       = userId,
                    Authors      = "Hồ Chí Minh",
                    Content      = "Lao động trí óc mà không lao động chân tay, chỉ biết lý luận mà không biết thực hành thì cũng là trí thức có một nửa. Vì vậy, cho nên các cháu trong lúc học lý luận cũng phải kết hợp với thực hành và tất cả các ngành khác đều phải: lý luận kết hợp với thực hành, học tập kết hợp với lao động.",
                    DisplayOrder = 1,
                    Image        = "http://www.mediafire.com/convkey/2b3c/cfd3i2sc2t4tr4izg.jpg",
                    IsChoose     = true,
                    Status       = true
                },
                new Slide
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "slide 2",
                    UserId       = userId,
                    Authors      = "Frank Herbert ",
                    Content      = "Người ta chỉ học được từ sách và các ví dụ rằng một số thứ có thể làm được. Học hỏi thực sự yêu cầu bạn phải thực hiện chúng.",
                    DisplayOrder = 1,
                    Image        = "http://www.mediafire.com/convkey/6546/66qp4fak56c84qtzg.jpg",
                    IsChoose     = true,
                    Status       = true
                }
            };

            slides.ForEach(x => dbContext.Slides.Add(x));
            dbContext.SaveChanges();
        }
Exemple #2
0
        private static void CreatePage(BookStoreDbContext dbContext, UserManager <ApplicationUser> userManager)
        {
            var         userId = userManager.FindByEmailAsync("*****@*****.**").Result.Id;
            List <Page> pages  = new List <Page>
            {
                new Page
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "footer",
                    Content     = "footer",
                    CreatedDate = DateTime.Now,
                    UserId      = userId,
                    Status      = true
                }, new Page
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "contact",
                    Content     = "contact content seeder",
                    CreatedDate = DateTime.Now,
                    UserId      = userId,
                    Status      = true
                }, new Page
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "about",
                    Content     = "about content seeder",
                    CreatedDate = DateTime.Now,
                    UserId      = userId,
                    Status      = true
                }
            };

            pages.ForEach(x => dbContext.Pages.Add(x));
            dbContext.SaveChanges();
        }
Exemple #3
0
        private static void CreateFormat(BookStoreDbContext dbContext)
        {
            List <DownloadFormat> formats = new List <DownloadFormat>
            {
                new DownloadFormat
                {
                    DisplayName = "link1",
                    PdfLink     = "http://www.mediafire.com/file/7vl63g7szf5opcd/advanced-aspnet-ajax-server-controls-adam-calderon.pdf/file",
                }
            };

            formats.ForEach(x => dbContext.DownloadFormats.Add(x));
            dbContext.SaveChanges();
        }
Exemple #4
0
        private static void CreateContacts(BookStoreDbContext dbContext, UserManager <ApplicationUser> userManager)
        {
            var userId  = userManager.FindByEmailAsync("*****@*****.**").Result.Id;
            var contact = new Contact
            {
                Name    = "Liên hệ",
                Address = "Phường Tân Thạnh - Tp.Tam Kỳ - Quảng Nam",
                Email   = "*****@*****.**",
                Phone   = "0169 565 5783",
                Status  = true,
                UserId  = userId
            };

            dbContext.Contacts.Add(contact);
            dbContext.SaveChanges();
        }
Exemple #5
0
        private static void CreateCourses(BookStoreDbContext dbContext, UserManager <ApplicationUser> userManager)
        {
            var           userId  = userManager.FindByEmailAsync("*****@*****.**").Result.Id;
            List <Course> courses = new List <Course>
            {
                new Course
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Lập trình .net core",
                    MetaName    = "lap-trinh-net-core",
                    AvatarData  = "/",
                    CreatedDate = DateTime.Now,
                    Description = "Lập trình .net core",
                    UserId      = userId,
                    Status      = true,
                    Authors     = "NA",
                    SharedUrl   = "x"
                },
                new Course
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Thành thạo Linq trong vòng 7 tuần",
                    MetaName    = "thanh-thao-linq-trong-vong-7-tuan",
                    AvatarData  = "/",
                    CreatedDate = DateTime.Now,
                    Description = "Lập trình .net core",
                    UserId      = userId,
                    Status      = true,
                    Authors     = "NA",
                    SharedUrl   = "x"
                }
            };

            courses.ForEach(x => dbContext.Courses.Add(x));
            dbContext.SaveChanges();
        }
Exemple #6
0
 public void Create(Book book)
 {
     _dbContext.Books.Add(book);
     _dbContext.SaveChanges();
 }
Exemple #7
0
        public static void Import()
        {
            db = new BookStoreDbContext();

            var xmlBooks = XElement.Load(@"..\..\..\complex-books.xml").Elements();

            //var books = xmlBooks.Elements();

            foreach (var xmlBook in xmlBooks)
            {
                var currentBook = new Book();
                currentBook.Title = xmlBook.Element("title").Value;

                var isbn = xmlBook.Element("isbn");
                if (isbn != null)
                {
                    currentBook.ISBN = isbn.Value;
                }

                var price = xmlBook.Element("price");
                if (isbn != null)
                {
                    var bookExists = db.Books.Any(b => b.ISBN == isbn.Value);
                    if (bookExists)
                    {
                        throw new ArgumentException("ISBN exists!");
                    }
                    currentBook.Price = decimal.Parse(price.Value);
                }

                var webSite = xmlBook.Element("web-site");
                if (webSite != null)
                {
                    currentBook.WebSite = webSite.Value;
                }

                var xmlAuthors = xmlBook.Element("autors");
                if (xmlAuthors != null)
                {
                    foreach (var xmlAuthor in xmlAuthors.Elements("author"))
                    {
                        var authotName = xmlAuthor.Value;
                        currentBook.Authors.Add(GetAuthor(authotName));
                    }

                }

                var xmlReviews = xmlBook.Element("reviews");
                if (xmlReviews != null)
                {
                    foreach (var xmlReview in xmlReviews.Elements("review"))
                    {
                        var reviewDate = xmlReview.Attribute("date");
                        var authorName = xmlReview.Attribute("author");
                        var review = new Review
                        {
                            Content = xmlReviews.Value,
                            CreatedOn = reviewDate == null ? DateTime.Now : DateTime.Parse(reviewDate.Value),
                            //Autor = authorName==null? 
                        };

                        if (authorName != null)
                        {
                            review.Autor = GetAuthor(authorName.Value);
                        }

                        currentBook.Reviews.Add(review);
                        db.SaveChanges();
                    }
                }

                db.Books.Add(currentBook);
            }
        }
Exemple #8
0
        /// <summary>
        /// Initializes data in the DataBase
        /// </summary>
        /// <param name="context">DB context</param>
        public static void Initial(BookStoreDbContext context)
        {
            if (!context.Books.Any())
            {
                context.Books.AddRange(Books.Select(c => c.Value));
            }

            if (!context.Sections.Any())
            {
                context.Sections.AddRange(Section.Select(c => c.Value));
            }

            if (!context.Carousels.Any())
            {
                context.Carousels.AddRange(Carousel.Select(c => c.Value));
            }

            context.SaveChanges();

            if (!context.Sections.FirstOrDefault().BookSection.Any()) //TODO: Fix this code...
            {
                context.Sections.FirstOrDefault(s => s.Title == "Discount books")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "C# 8.0 and .NET Core 3.0 - Modern Cross-Platform Development").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "Discount books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "Discount books")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "Pro ASP.NET Core MVC 2, 7th ed. Edition").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "Discount books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "Discount books")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "Pro C# 7: With .NET and .NET Core, 8th ed. Edition").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "Discount books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "New books")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "C# in Depth, 4th Edition").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "New books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "New books")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "ASP.NET Core in Action").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "New books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "Subscriptions")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "Clean Code: A Handbook of Agile Software Craftsmanship").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "New books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "Subscriptions").BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "Introduction to Algorithms, 3rd Edition").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "New books").Id
                });
            }

            context.SaveChanges();
        }
 public void Create(Order order)
 {
     _context.Orders.Add(order);
     _context.SaveChanges();
 }
Exemple #10
0
        public static void CreatedCategory(BookStoreDbContext dbContext)
        {
            List <Category> cate = new List <Category> {
                new Category
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Máy tính và Công nghệ",
                    MetaName    = StringHelper.ToUnsignString("Máy tính và Công nghệ"),
                    CreatedDate = DateTime.Now,
                    Status      = true
                },
                new Category
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Phát triển kỹ năng",
                    MetaName    = StringHelper.ToUnsignString("Phát triển kỹ năng"),
                    CreatedDate = DateTime.Now,
                    Status      = true
                },
                new Category
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Toán học",
                    MetaName    = StringHelper.ToUnsignString("Toán học"),
                    CreatedDate = DateTime.Now,
                    Status      = true
                }, new Category
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Lịch sử",
                    MetaName    = StringHelper.ToUnsignString("Lịch sử"),
                    CreatedDate = DateTime.Now,
                    Status      = true
                }, new Category
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Y khoa",
                    MetaName    = StringHelper.ToUnsignString("Y khoa"),
                    CreatedDate = DateTime.Now,
                    Status      = true
                }, new Category
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Kinh doanh và Khởi nghiệp",
                    MetaName    = StringHelper.ToUnsignString("Kinh doanh và khởi nghiệp"),
                    CreatedDate = DateTime.Now,
                    Status      = true
                }, new Category
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Tiểu sử và Hồi ký",
                    MetaName    = StringHelper.ToUnsignString("Tiểu sử và hồi ký"),
                    CreatedDate = DateTime.Now,
                    Status      = true
                }, new Category
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Pháp luật",
                    MetaName    = StringHelper.ToUnsignString("Pháp luật"),
                    CreatedDate = DateTime.Now,
                    Status      = true
                }, new Category
                {
                    Id          = Guid.NewGuid().ToString(),
                    Name        = "Nấu ăn",
                    MetaName    = StringHelper.ToUnsignString("Nấu ăn"),
                    CreatedDate = DateTime.Now,
                    Status      = true
                }
            };

            cate.ForEach(c => dbContext.Categories.Add(c));
            dbContext.SaveChanges();
        }
Exemple #11
0
        private static void CreateBookTypeByCategory(BookStoreDbContext dbContext)
        {
            List <BookType> type = new List <BookType>
            {
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Lập trình di động",
                    MetaName     = "Lập trình di động",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Máy tính và Công nghệ").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/t8tn063vcglg808/android-300x300.png",
                    Description  = "Ebook về lập trình di động"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Lập trình website",
                    MetaName     = "Lập trình website",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Máy tính và Công nghệ").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Ebook về lập trình website"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Trí tuệ nhân tạo",
                    MetaName     = "Trí tuệ nhân tạo",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Máy tính và Công nghệ").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Ebook về lập trình trí tuệ nhân tạo"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Kỹ năng giao tiếp",
                    MetaName     = "Kỹ năng giao tiếp",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Phát triển kỹ năng").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Ebook về lập kỹ năng giao tiếp kỹ năng thuyết trình"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Khai phá bản thân",
                    MetaName     = "Khai phá bản thân",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Phát triển kỹ năng").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Ebook khai phá bản thân"
                }, new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Toán học phổ thông",
                    MetaName     = "Toán học phổ thông",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Toán học").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Ebook toán học phổ thông"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Toán học ứng dụng",
                    MetaName     = "Toán học ứng dụng",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Toán học").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Ebook toán học ứng dụng"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Chiến tranh Việt Nam",
                    MetaName     = "Chiến tranh Việt Nam",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Lịch sử").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Chiến tranh Việt Nam"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Lịch sử thế giới",
                    MetaName     = "Lịch sử thế giới",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Lịch sử").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Lịch sử thế giới"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Y khoa thường thức",
                    MetaName     = "Y khoa thường thức",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Y khoa").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Y khoa thường thức"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Y học phương đông",
                    MetaName     = "Y học phương đông",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Y khoa").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Y học phương đông"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Y học phương tây",
                    MetaName     = "Y học phương tây",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Y khoa").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Y học phương tây"
                }, new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Khởi nghiệp",
                    MetaName     = "Khởi nghiệp",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Kinh doanh và Khởi nghiệp").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Khởi nghiệp"
                },
                new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Luật doanh nghiệp",
                    MetaName     = "Luật doanh nghiệp",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Pháp luật").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Luật doanh nghiệp"
                }, new BookType
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = "Luật nhà nước",
                    MetaName     = "Luật nhà nước",
                    CategoryId   = dbContext.Categories.Where(x => x.Name == "Pháp luật").SingleOrDefault().Id,
                    Status       = true,
                    CreatedDate  = DateTime.Now,
                    ThumbnailUrl = "http://www.mediafire.com/view/dwlk4ed7vomaj02/tải%20xuống.png",
                    Description  = "Luật nhà nước"
                },
            };

            type.ForEach(x => dbContext.BookTypes.Add(x));
            dbContext.SaveChanges();
        }