Exemplo n.º 1
0
        public static string ExportOldestBooks(BookShopContext context, DateTime date)
        {
            var oldestBooks = context.Books
                              .Where(b => b.PublishedOn < date && b.Genre == (Genre)3)
                              .Select(b => new ExportBookDto
            {
                Name  = b.Name,
                Date  = b.PublishedOn.ToString("d", CultureInfo.InvariantCulture),
                Pages = b.Pages
            })
                              .OrderByDescending(b => b.Pages)
                              .ThenByDescending(b => b.Date)
                              .Take(10)
                              .ToArray();

            string res = XmlConverter.Serialize(oldestBooks, "Books");

            return(res);
        }
        public static string ExportOldestBooks(BookShopContext context, DateTime date)
        {
            var data = context.Books
                       .Where(b => b.PublishedOn < date && b.Genre == Genre.Science)
                       .OrderByDescending(b => b.Pages)
                       .ThenByDescending(b => b.PublishedOn)
                       .Select(b => new BookXmlExportModel
            {
                Pages = b.Pages,
                Name  = b.Name,
                Date  = b.PublishedOn.ToString("d", CultureInfo.InvariantCulture)
            })
                       .Take(10)
                       .ToArray();

            string xml = XmlConverter.Serialize(data, "Books");

            return(xml);
        }
Exemplo n.º 3
0
        public static string ExportOldestBooks(BookShopContext context, DateTime date)
        {
            var targetBooks = context.Books
                              .AsEnumerable()
                              .Where(x => x.PublishedOn < date && x.Genre.ToString().ToLower() == "science")
                              .Select(x => new ExportBookDTO
            {
                Pages = x.Pages,
                Name  = x.Name,
                Date  = x.PublishedOn.ToString("MM/dd/yyyy")
            })
                              .OrderByDescending(x => x.Pages)
                              .ThenByDescending(x => DateTime.Parse(x.Date))
                              .Take(10)
                              .ToList();
            var resultXml = XmlConverter.Serialize(targetBooks, "Books");

            return(resultXml);
        }
Exemplo n.º 4
0
        public static string ExportOldestBooks(BookShopContext context, DateTime date)
        {
            var books = context.Books.ToList()
                        .Where(x => x.PublishedOn < date && x.Genre.ToString() == "Science")
                        .Select(x => new BookExportXmlModel
            {
                Pages = x.Pages,
                Name  = x.Name,
                Date  = x.PublishedOn.ToString("d", CultureInfo.InvariantCulture)
            })
                        .OrderByDescending(x => x.Pages)
                        .ThenByDescending(x => x.Date)
                        .Take(10)
                        .ToList();

            string root   = "Books";
            var    result = XmlConverter.Serialize(books, root);

            return(result.ToString().TrimEnd());
        }
Exemplo n.º 5
0
        public static string ExportOldestBooks(BookShopContext context, DateTime date)
        {
            var books = context.Books
                        .ToArray()
                        .Where(x => x.PublishedOn < date && x.Genre == Genre.Science)
                        .OrderByDescending(o => o.Pages)
                        .ThenByDescending(o => o.PublishedOn)
                        .Select(x => new ExportBookDto
            {
                Name  = x.Name,
                Date  = x.PublishedOn.ToString("d", CultureInfo.InvariantCulture),
                Pages = x.Pages
            })
                        .Take(10)
                        .ToArray();

            string xml = XmlConverter.Serialize(books, "Books");

            return(xml);
        }
        public static string ExportOldestBooks(BookShopContext context, DateTime date)
        {
            var books = context.Books.Where(x => x.PublishedOn < date && x.Genre == Genre.Science)
                        .ToList()
                        .OrderByDescending(x => x.Pages)
                        .ThenByDescending(x => x.PublishedOn)
                        .Select(x => new BooksXmlOutputDto
            {
                Pages = x.Pages.ToString(),
                Name  = x.Name,
                Date  = x.PublishedOn.ToString("d", CultureInfo.InvariantCulture),
            }).ToList()

                        .Take(10)
                        .ToList();

            var result = XmlConverter.Serialize(books, "Books");

            return(result);
        }
Exemplo n.º 7
0
        public static string ExportOldestBooks(BookShopContext context, DateTime date)
        {
            var sortedBooks = context
                              .Books
                              .ToList()
                              .Where(b => b.PublishedOn < date && b.Genre.ToString() == "Science")
                              .OrderByDescending(b => b.Pages)
                              .ThenBy(b => b.PublishedOn)
                              .Select(b => new OldestBooksExportModel()
            {
                Name  = b.Name,
                Date  = b.PublishedOn.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture),
                Pages = b.Pages.ToString()
            })
                              .Take(10)
                              .ToList();

            var jsonResult = XmlConverter.Serialize(sortedBooks, "Books");

            return(jsonResult);
        }
Exemplo n.º 8
0
        public static string ExportOldestBooks(BookShopContext context, DateTime date)
        {
            var books = context.Books
                        .ToArray()
                        .Where(b => b.PublishedOn <= date && b.Genre == Data.Models.Enums.Genre.Science)
                        .Select(b => new ExportBookDTO
            {
                Pages = b.Pages,
                Name  = b.Name,
                Date  = b.PublishedOn.ToString("MM/dd/yyyy"),
            })
                        .OrderByDescending(b => b.Pages)
                        .ThenByDescending(b => b.Date)
                        .Take(10)
                        .ToList();

            var root = "Books";
            var xml  = XmlConverter.Serialize(books, root);

            return(xml);
        }