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);
            }
        }
예제 #3
0
        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));
        }
예제 #4
0
        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
                });
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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;
            }
        }
예제 #8
0
        //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());
        }
예제 #9
0
        //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));
        }
예제 #10
0
 public Movie(string name, Genre genre, DateTime releaseDate, AgeRestriction ageRestriction, int duration)
 {
     Name           = name;
     Genre          = genre;
     ReleaseDate    = SetDate(releaseDate);
     AgeRestriction = ageRestriction;
     Duration       = duration;
 }
예제 #11
0
 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;
 }
예제 #13
0
        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)));
        }
예제 #14
0
 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);
     }
 }
예제 #15
0
        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);
            }
        }
예제 #16
0
        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));
        }
예제 #17
0
        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));
        }
예제 #19
0
        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());
        }
예제 #20
0
        // 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);
        }
예제 #21
0
        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);
        }
예제 #22
0
        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);
        }
예제 #23
0
        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());
        }
예제 #24
0
        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);
        }
예제 #25
0
        //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());
        }
예제 #26
0
        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));
        }
예제 #27
0
        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());
        }
예제 #28
0
파일: Startup.cs 프로젝트: nayots/SoftUni
        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);
                }
            }
        }
예제 #29
0
        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);
            }
        }
예제 #30
0
        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());
        }
예제 #31
0
파일: Game.cs 프로젝트: HristoHristov/OOP
 public Game(string gameId, string gameTitle, decimal price, string genre, AgeRestriction ageRestriction = AgeRestriction.Minor)
     : base(gameId, gameTitle, price)
 {
     this._ageRestriction = ageRestriction;
     this.AddGenre = genre;
 }
예제 #32
0
파일: Game.cs 프로젝트: HristoHristov/OOP
 public Game(string gameId, string gameTitle, decimal price, List<string> genres, AgeRestriction ageRestriction = AgeRestriction.Minor)
     : base(gameId, gameTitle, price, genres)
 {
     this._ageRestriction = ageRestriction;
 }
예제 #33
0
 public Game(string id, string name, decimal price, string genre, AgeRestriction ageRestriction = DefaultAgeRestriction)
     : this(id, name, price, new List<string> { genre }, ageRestriction)
 {
 }
예제 #34
0
 public Game(string id, string title, decimal price, string genre, AgeRestriction ageRestriction = AgeRestriction.Minor)
     : base(id, title, price, genre)
 {
     this.ageRestriction = ageRestriction;
 }
예제 #35
0
파일: Game.cs 프로젝트: hkostadinov/SoftUni
 public Game(string id, string title, decimal price, string genre, AgeRestriction ageRestriction = AgeRestriction.Minor)
     : this(id, title, price, new List<string>() { genre }, ageRestriction)
 {
 }
예제 #36
0
파일: Game.cs 프로젝트: hkostadinov/SoftUni
 public Game(string id, string title, decimal price, IList<string> genres, AgeRestriction ageRestriction = AgeRestriction.Minor)
     : base(id, title, price, genres)
 {
     this.AgeRestriction = ageRestriction;
 }