Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace BookShop
- {
- using BookShop.Data;
- using BookShop.Initializer;
- using BookShop.Models;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- public class StartUp
- {
- public static void Main()
- {
- using (var context = new BookShopContext())
- {
- //DbInitializer.ResetDatabase(db);
- //1.Age Restriction
- string command = Console.ReadLine();
- string ageRestricted = GetBooksByAgeRestriction(context, command);
- Console.WriteLine(ageRestricted);
- }
- }
- public static string GetBooksByAgeRestriction(BookShopContext context, string command)
- {
- var books = context.Books.OrderBy(x => x.Title).ToList();
- string result = string.Empty;
- int compare = -1;
- switch (command.ToLower())
- {
- case "minor":
- compare = 0;
- var minors = context.Books
- .Where(x => (int)x.AgeRestriction == compare)
- .OrderBy(x => x.Title)
- .Select(x => x.Title)
- .ToList();
- result = string.Join(Environment.NewLine, minors);
- break;
- case "teen":
- compare = 1;
- var teens = context.Books
- .Where(x => (int)x.AgeRestriction == compare)
- .OrderBy(x => x.Title)
- .Select(x => x.Title)
- .ToList();
- result = string.Join(Environment.NewLine, teens);
- break;
- case "adult":
- compare = 2;
- var adults = context.Books
- .Where(x => (int)x.AgeRestriction == compare)
- .OrderBy(x => x.Title)
- .Select(x => x.Title)
- .ToList();
- result = string.Join(Environment.NewLine, adults);
- break;
- default:
- break;
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment