public static void Search() { db = new BookStoreDbContext(); var xmlQueries = XElement.Load(@"..\..\..\reviews-queries.xml").Elements(); var result = new XElement("search-results"); foreach (var xmlQuery in xmlQueries) { var queryInReviews = db.Reviews.AsQueryable(); if (xmlQuery.Attribute("type").Value == "by-period") { var startDate = DateTime.Parse(xmlQuery.Element("start-date").Value); var endDate = DateTime.Parse(xmlQuery.Element("end-date").Value); queryInReviews = queryInReviews.Where(r => r.CreatedOn >= startDate && r.CreatedOn <= endDate); } else if (xmlQuery.Attribute("type").Value == "by-author") { var authorName = xmlQuery.Element("author-name").Value; queryInReviews = queryInReviews.Where(r => r.Autor.Name == authorName); } var resultSet = queryInReviews .OrderBy(r => r.CreatedOn) .ThenBy(r => r.Content) .Select(r => new { Date = r.CreatedOn, Content = r.Content, Book = new { Title = r.Book.Title, // TODO ordre after select Authors = r.Book.Authors .OrderBy(a => a.Name) .Select(a => a.Name), ISBN = r.Book.ISBN, URL = r.Book.WebSite } }).ToList(); var xmlResultSet = new XElement("result-set"); foreach (var reviewInResult in resultSet) { var xmlReview=new XElement("review"); xmlReview.Add(new XElement("date", reviewInResult.Date.ToString("d-MMM-yyyy"))); xmlReview.Add(new XElement("content", reviewInResult.Content)); xmlResultSet.Add(xmlReview); } result.Add(xmlResultSet); } result.Save(@"..\..\..\reviews-search-results.xml"); }
static void Main() { db = new BookStoreDbContext(); //ImportXmlData(); SearchXmlData(); }
public static void Main() { db = new BookStoreDbContext(); // Import(); Search(); }
public static void Main() { Console.WriteLine("USE .!!!"); db = new BookStoreDbContext(); //XmlImporter(); //XmlSearcher(); }
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(); }
public ActionResult Index(string searchString) { var context = new BookStoreDbContext(); var books = context.Books .Include(b => b.Author) .Where(b => b.Title.Contains(searchString) || b.Author.Lastname.Contains(searchString)) .Select(BookViewModel.FromBook); ViewBag.Success = true; ViewBag.SearchString = searchString; return View(books); }
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(); }
public static void Seed(BookStoreDbContext dbContext, RoleManager <IdentityRole> roleManager, UserManager <ApplicationUser> userManager) { if (!dbContext.Users.Any()) { CreateUser(dbContext, roleManager, userManager) .GetAwaiter() .GetResult(); } if (!dbContext.Slides.Any()) { CreateSlides(dbContext, userManager); } if (!dbContext.Books.Any()) { CreateBook(dbContext, userManager); } if (!dbContext.Categories.Any()) { CreatedCategory(dbContext); } if (!dbContext.BookTypes.Any()) { CreateBookTypeByCategory(dbContext); } if (!dbContext.DownloadFormats.Any()) { CreateFormat(dbContext); } if (!dbContext.Pages.Any()) { CreatePage(dbContext, userManager); } if (!dbContext.Contacts.Any()) { CreateContacts(dbContext, userManager); } if (!dbContext.Courses.Any()) { CreateCourses(dbContext, userManager); } if (!dbContext.CourseCategories.Any()) { CreateCourseCategory(dbContext, userManager); } }
public static async Task CreateUser(BookStoreDbContext dbContext, RoleManager <IdentityRole> roleManager, UserManager <ApplicationUser> userManager) { string role_Administrator = "Administrator"; if (!await roleManager.RoleExistsAsync(role_Administrator)) { await roleManager.CreateAsync(new IdentityRole(role_Administrator)); } //create the "Admin" ApplicationUser account var user_Admin = new ApplicationUser { SecurityStamp = Guid.NewGuid().ToString(), UserName = "******", Email = "*****@*****.**", CreatedDate = DateTime.Now, LastModifiedDate = DateTime.Now, Address = "Tiên hiệp - tiên phước - quảng nam", Status = true, PhoneNumber = "0374564297", UrlAvatar = "default", DisplayName = "administrator" }; if (await userManager.FindByNameAsync(user_Admin.UserName) == null) { IdentityResult result = await userManager.CreateAsync(user_Admin, "pass4Admin"); if (result.Succeeded) { await userManager.AddToRoleAsync(user_Admin, role_Administrator); await dbContext.SaveChangesAsync(); } } }
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(); }
// // GET: /Books/ public ActionResult Index() { var context = new BookStoreDbContext(); var books = context.Books.Include(b => b.Author).Include(b => b.Category).Select(BookViewModel.FromBook); return View(books); }
public BooksRepository(BookStoreDbContext dbContext) { _dbContext = dbContext; }
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(); }
public ApplicationsRepository(BookStoreDbContext context) { _context = context; }
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); } }
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(); }
public ActionResult Index() { var context = new BookStoreDbContext(); var categories = context.Categories.Include(c => c.Books); return View(categories); }
/// <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 OrdersRepository(BookStoreDbContext context) { _context = context; }
public static void CreateBook(BookStoreDbContext dbContext, UserManager <ApplicationUser> userManager) { var userId = userManager.FindByEmailAsync("*****@*****.**").Result.Id; IEnumerable <Book> books = new List <Book>(); }
// // GET: /Authors/ public ActionResult Index() { var context = new BookStoreDbContext(); var authors = context.Authors.Include(c => c.Books); return View(authors); }