public static string GetBooksByAgeRestriction(BookShopContext context, string command) { var currentString = Char.ToUpper(command[0]) + command.Substring(1).ToLower(); var sb = new StringBuilder(); try { AgeRestriction enumValue = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), currentString); var books = context.Books .Where(p => p.AgeRestriction == enumValue) .Select(p => p.Title) .OrderBy(p => p) .ToArray(); foreach (var book in books) { sb.AppendLine(book); } } catch { sb.AppendLine("Invalid age restriction"); } return(sb.ToString().Trim()); }
private static void SeedBooks(BookShopContext context) { int authorsCount = context.Authors.Local.Count; string[] books = File.ReadAllLines(@"C:\Programs\vs\Databases Advanced - Entity Framework\BookShopSystem\BookShopSystem\Import\books.csv"); for (int i = 1; i < books.Length; i++) { string[] data = books[i] .Split(',') .Select(arg => arg.Replace("\"", string.Empty)) .ToArray(); int authorIndex = i % authorsCount; Author author = context.Authors.Local[authorIndex]; EditionType edition = (EditionType)int.Parse(data[0]); DateTime releaseDate = DateTime.ParseExact(data[1], "d/M/yyyy", CultureInfo.InvariantCulture); int copies = int.Parse(data[2]); decimal price = decimal.Parse(data[3]); AgeRestriction ageRestriction = (AgeRestriction)int.Parse(data[4]); string title = data[5]; Book book = new Book { Author = author, Type = edition, ReleaseDate = releaseDate, Copies = copies, Price = price, AgeRestriction = ageRestriction, Title = title }; context.Books.AddOrUpdate(b => new { b.Title }, book); } }
public static void ImportMovie(MovieDTO movieDto) { string movieName = movieDto.Name; InputDataValidator.ValidateStringMaxLength(movieName, Constants.MaxMovieNameLength); float?rating = movieDto.Rating; InputDataValidator.ValidateFloatInRange(rating, Constants.MinRatingValue, Constants.MaxRatingValue); int releaseYear = movieDto.ReleaseYear; MovieValidator.ValidateMovieDoesNotExist(movieName, releaseYear); List <string> categories = movieDto.Categories.Select(c => c.Name).ToList(); CategoryValidator.CheckCategoriesExist(categories); string directorName = movieDto.DirectorName; int length = movieDto.Length; AgeRestriction ageRestriction = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), movieDto.AgeRestriction); string synopsis = movieDto.Synopsis; string releaseCountry = movieDto.ReleaseCountry; byte[] image = movieDto.Image; MovieService.AddMovie(movieName, rating, length, directorName, releaseYear, ageRestriction, synopsis, releaseCountry, image); MovieImportService.AddCategoriesToMovie(movieName, releaseYear, categories); Console.WriteLine(string.Format(Constants.ImportSuccessMessages.MoviesAddedSuccess, movieName)); }
private void SeedBooks(BookShopContext context) { int authoCount = context.Authors.Local.Count; string[] books = File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "../../Import/books.csv"); for (int i = 1; i < books.Length; i++) { string[] data = books[i].Split(',').Select(arg => arg.Replace("\"", string.Empty)).ToArray(); int authorIndex = i % authoCount; Author author = context.Authors.Local[authorIndex]; EditionType edition = (EditionType)int.Parse(data[0]); DateTime resleaseDate = DateTime.ParseExact(data[1], "d/M/yyyy", CultureInfo.InvariantCulture); int copies = int.Parse(data[2]); decimal price = decimal.Parse(data[3]); AgeRestriction ageRestriction = (AgeRestriction)int.Parse(data[4]); string title = data[5]; context.Books.AddOrUpdate(b => new { b.Title, b.AuthorId }, new Book() { Author = author, AuthorId = author.Id, EditionType = edition, ReleaseDate = resleaseDate, Copies = copies, Price = price, AgeRestriction = ageRestriction, Title = title }); } }
public List <Movie> GetMovies() { List <Movie> movies = new List <Movie>(); using (SqlConnection conn = new SqlConnection(connecstring)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("dbo.GetMovies", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int id = reader.GetInt32(0); string name = reader.GetString(1); Genre genre = (Genre)Enum.ToObject(typeof(Genre), reader.GetInt32(2)); DateTime date = reader.GetDateTime(3); AgeRestriction agerestriction = (AgeRestriction)Enum.ToObject(typeof(AgeRestriction), reader.GetInt32(2)); int duration = reader.GetInt32(5); //string img_url = reader.GetString(6); Movie movie = new Movie(id, name, genre, date, agerestriction, duration); movies.Add(movie); } } } conn.Close(); } return(movies); }
public Movie GetMovieOnId(int movieId) { Movie movie = null; using (SqlConnection conn = new SqlConnection(connecstring)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("dbo.GetMovieOnId", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("in_Id", movieId); cmd.ExecuteNonQuery(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int id = reader.GetInt32(0); string name = reader.GetString(1); Genre genre = (Genre)Enum.ToObject(typeof(Genre), reader.GetInt32(2)); DateTime date = reader.GetDateTime(3); AgeRestriction ageRestriction = (AgeRestriction)Enum.ToObject(typeof(AgeRestriction), reader.GetInt32(4)); int duration = reader.GetInt32(5); //string img_URL = reader.GetString(6); movie = new Movie(id, name, genre, date, ageRestriction, duration); } } } conn.Close(); } return(movie); }
private void ageRestrictionComboBox_SelectedIndexChanged(object sender, EventArgs e) { switch (this.ageRestrictionComboBox.SelectedItem.ToString()) { case "A": this.ageRestriction = AgeRestriction.A; break; case "B": this.ageRestriction = AgeRestriction.B; break; case "C": this.ageRestriction = AgeRestriction.C; break; case "D": this.ageRestriction = AgeRestriction.D; break; case "X": this.ageRestriction = AgeRestriction.X; break; default: break; } }
//1. Age Restriction public static string GetBooksByAgeRestriction(BookShopContext context, string command) { var result = string.Empty; var check = new AgeRestriction(); switch (command.ToLower()) { case "minor": check = (AgeRestriction)0; break; case "teen": check = (AgeRestriction)1; break; case "adult": check = (AgeRestriction)2; break; } var titles = context.Books .Where(x => x.AgeRestriction.Equals(check)) .OrderBy(x => x.Title) .Select(x => new { x.Title }) .ToList(); foreach (var title in titles) { result += $"{title.Title}" + Environment.NewLine; } return(result.TrimEnd()); }
//1. Age Restriction public static string GetBooksByAgeRestriction(BookShopContext context, string command) { AgeRestriction parsed = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), command, true); var books = context.Books.Where(b => b.AgeRestriction == parsed).OrderBy(b => b.Title).Select(b => b.Title).ToArray(); return(string.Join(Environment.NewLine, books)); }
public Movie(string name, Genre genre, DateTime releaseDate, AgeRestriction ageRestriction, int duration) { Name = name; Genre = genre; ReleaseDate = SetDate(releaseDate); AgeRestriction = ageRestriction; Duration = duration; }
public Game(string id, string title, decimal price, Genre genre, AgeRestriction ageRestriction = AgeRestriction.Minor) : base(id, title, price) { this.AgeRestriction = ageRestriction; this.SetOfGenres = new List <Genre> { genre }; }
public Book(string title, string descr, int copies, EditionType editionType, AgeRestriction ageRestr, Author author) { this.Title = title; this.Description = descr; this.Copies = copies; this.EditionType = editionType; this.AgeRestriction = ageRestr; this.Author = author; }
public static string GetBooksByAgeRestriction(BookShopContext context, string command) { AgeRestriction restriction = Enum.Parse <AgeRestriction>(command, true); return(string.Join(Environment.NewLine, context.Books .Where(x => x.AgeRestriction == restriction) .OrderBy(x => x.Title) .Select(x => x.Title))); }
public override int GetHashCode() { unchecked { int hashCode = (ISBN != null ? ISBN.GetHashCode() : 0); hashCode = (hashCode * 397) ^ PublisherId; hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ ReleaseDate.GetHashCode(); hashCode = (hashCode * 397) ^ (AgeRestriction != null ? AgeRestriction.GetHashCode() : 0); return(hashCode); } }
public static void BooksTitleByAgeRestriction() { BookShopContext context = new BookShopContext(); string input = Console.ReadLine(); AgeRestriction restriction = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), input, true); foreach (var book in context.Books.Where(s => s.AgeRestriction == restriction)) { Console.WriteLine(book.Title); } }
public static string GetBooksByAgeRestriction(BookShopContext context, string command) { AgeRestriction ageRestriction = Enum.Parse <AgeRestriction>(command, true); List <string> titles = context.Books .Where(b => b.AgeRestriction == ageRestriction) .OrderBy(b => b.Title) .Select(b => b.Title) .ToList(); return(string.Join(Environment.NewLine, titles)); }
public static string GetBooksByAgeRestriction(BookShopContext db, string command) { AgeRestriction parsed = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), command, true); var books = db.Books .Where(x => x.AgeRestriction == parsed) .OrderBy(x => x.Title) .Select(x => x.Title) .ToList(); return(string.Join(Environment.NewLine, books)); }
public static string GetBooksByAgeRestriction(BookShopContext dbContext, string input) { AgeRestriction ageRestriction = Enum.Parse <AgeRestriction>(input, true); string[] books = dbContext .Books .Where(b => b.AgeRestriction == ageRestriction) .Select(b => b.Title) .OrderBy(b => b) .ToArray(); return(string.Join(Environment.NewLine, books)); }
public static string GetBooksByAgeRestriction(BookShopContext context, string command) { AgeRestriction ar = CheckAge(command); var books = context.Books.Where(x => x.AgeRestriction == ar).OrderBy(x => x.Title); var sb = new StringBuilder(); foreach (var book in books) { sb.AppendLine($"{book.Title}"); } return(sb.ToString().TrimEnd()); }
// Done public static string GetBooksByAgeRestriction(BookShopContext context, string command) { AgeRestriction restriction = Enum.Parse <AgeRestriction>(command, true); string[] bookTitles = context.Books .Where(b => b.AgeRestriction == restriction) .Select(b => b.Title) .OrderBy(t => t) .ToArray(); string result = string.Join(Environment.NewLine, bookTitles); return(result); }
public static string GetBooksByAgeRestriction(BookShopContext context, string command) { AgeRestriction ageRestriction = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), command, true); string[] resultArr = context.Books .Where(b => b.AgeRestriction == ageRestriction) .Select(b => b.Title) .OrderBy(b => b) .ToArray(); var result = string.Join(Environment.NewLine, resultArr); return(result); }
public static string GetBooksByAgeRestriction(BookShopContext context, string command) { AgeRestriction myEnum = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), command, true); var titles = context.Books .Where(x => x.AgeRestriction == myEnum) .OrderBy(x => x.Title) .Select(x => x.Title) .ToList(); var result = string.Join(Environment.NewLine, titles); return(result); }
public static string GetBooksByAgeRestriction(BookShopContext context, string command) { StringBuilder stringbuilder = new StringBuilder(); var formattedCommand = string.Concat(char.ToUpper(command[0]), command.Substring(1).ToLower()); AgeRestriction ageRestriction = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), formattedCommand); context.Books .Where(b => b.AgeRestriction == ageRestriction) .OrderBy(b => b.Title) .Select(b => b.Title) .ToList() .ForEach(t => stringbuilder.AppendLine(t)); return(stringbuilder.ToString().Trim()); }
public static string GetBooksByAgeRestriction(BookShopContext context, string command) { AgeRestriction ageRestriction = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), command, true); var books = context.Books .Where(b => b.AgeRestriction == ageRestriction) .Select(b => b.Title) .OrderBy(b => b) .ToList(); var output = string.Join($"{Environment.NewLine}", books); return(output); }
//2. Age Restriction public static string GetBooksByAgeRestriction(BookShopContext context, string command) { StringBuilder sb = new StringBuilder(); AgeRestriction ar = Enum.Parse <AgeRestriction>(command, true); var booksTitle = context.Books .Where(b => b.AgeRestriction == ar) .OrderBy(b => b.Title) .Select(b => b.Title) .ToArray(); foreach (var title in booksTitle) { sb.AppendLine(title); } return(sb.ToString().TrimEnd()); }
public static string GetBooksByAgeRestriction(BookShopContext context, string command = null) { if (command == null) { command = Console.ReadLine(); } AgeRestriction ageRestriction = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), command, true); var books = context.Books .Where(b => b.AgeRestriction == ageRestriction) .Select(b => b.Title) .ToList() .OrderBy(b => b); return(string.Join($"{Environment.NewLine}", books)); }
public static string GetBooksByAgeRestriction(BookShopContext context, AgeRestriction command) { var result = context.Books .Where(x => x.AgeRestriction == command) .Select(x => x.Title) .OrderBy(t => t) .ToList(); StringBuilder sb = new StringBuilder(); foreach (var bookTitle in result) { sb.AppendLine(bookTitle); } return(sb.ToString().Trim()); }
private static void GetBooksByAgeRestriction() { Console.Write("Enter age group (Minor, Teen or Adult): "); string ageGroup = Console.ReadLine().ToLower(); using (var context = new BookShopContext()) { //Minor 0 //Teen 1 //Adult 2 AgeRestriction ageRest = new AgeRestriction(); switch (ageGroup) { case "minor": ageRest = AgeRestriction.Minor; break; case "teen": ageRest = AgeRestriction.Teen; break; case "adult": ageRest = AgeRestriction.Adult; break; default: ageRest = AgeRestriction.Adult; Console.WriteLine("Your input does not match any age group, the default group is Adult."); break; } var books = context.Books .Where(a => a.AgeRestriction == ageRest) .Select(s => s.Title) .ToList(); foreach (var bookTitle in books) { Console.WriteLine(bookTitle); } } }
static void Main() { Console.WriteLine("Enter age category:"); string input = Console.ReadLine().Trim(); AgeRestriction ageRestriction = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), input, true); var context = new BookShopDBContext(); var bookTitles = context.Books .Where(b => b.AgeRestriction == (int)ageRestriction) .Select(b => b.Title) .ToList(); foreach (var title in bookTitles) { Console.WriteLine(title); } }
public static string GetBooksByAgeRestriction(BookShopContext context, string command) { command = command.ToLower(); command = command.First().ToString().ToUpper() + command.Substring(1); AgeRestriction intType = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), command); // FormattableString nativeSQLQuery = $"SELECT * FROM dbo.Books WHERE AgeRestriction = {intType} ORDER BY Title"; // var books = context.Books.FromSqlInterpolated((FormattableString)nativeSQLQuery); var books = context.Books.Where(x => x.AgeRestriction == intType) .OrderBy(x => x.Title) .Select(x => x.Title); var sb = new StringBuilder(); foreach (var book in books) { sb.AppendLine(book); } return(sb.ToString()); }
public Game(string gameId, string gameTitle, decimal price, string genre, AgeRestriction ageRestriction = AgeRestriction.Minor) : base(gameId, gameTitle, price) { this._ageRestriction = ageRestriction; this.AddGenre = genre; }
public Game(string gameId, string gameTitle, decimal price, List<string> genres, AgeRestriction ageRestriction = AgeRestriction.Minor) : base(gameId, gameTitle, price, genres) { this._ageRestriction = ageRestriction; }
public Game(string id, string name, decimal price, string genre, AgeRestriction ageRestriction = DefaultAgeRestriction) : this(id, name, price, new List<string> { genre }, ageRestriction) { }
public Game(string id, string title, decimal price, string genre, AgeRestriction ageRestriction = AgeRestriction.Minor) : base(id, title, price, genre) { this.ageRestriction = ageRestriction; }
public Game(string id, string title, decimal price, string genre, AgeRestriction ageRestriction = AgeRestriction.Minor) : this(id, title, price, new List<string>() { genre }, ageRestriction) { }
public Game(string id, string title, decimal price, IList<string> genres, AgeRestriction ageRestriction = AgeRestriction.Minor) : base(id, title, price, genres) { this.AgeRestriction = ageRestriction; }