Exemplo n.º 1
0
        private static void CreateMovie() // Create a new record.
        {
            Console.WriteLine("");
            Console.WriteLine("Type the following data to create the movie file:");
            Console.WriteLine("");
            Console.ForegroundColor = ConsoleColor.Yellow;

            using (var context = new RDBContext())
            {
                var newMovie = new Tmovie();

                Console.Write("Title: ");
                newMovie.Title = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Console.ReadLine().Trim());
                Console.Write("Year: ");
                newMovie.Year = int.Parse(Console.ReadLine().Trim());

                var existingMovie = context.Tmovie.Where(x => x.Title.ToLower() == newMovie.Title.ToLower()).FirstOrDefault();

                Console.WriteLine("");

                if (existingMovie == null)
                {
                    context.Tmovie.Add(newMovie);
                    var result = context.SaveChanges();

                    if (result == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("The movie was created succesfully.");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }

                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Error, the movie wasn't created.");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                }

                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error, already existed a movie with the same name.");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
            }

            Console.WriteLine("");
            Console.Write("Type any key to continue...");
            Console.ReadKey();
            Console.Clear();
            ShowMenu();
        }
Exemplo n.º 2
0
        public IActionResult Create(Tmovie movie)
        {
            // Verify it does not empty title.

            if (movie.Title != null)
            {
                // Verify it does not exists another movie with the same title.

                var existingMovie = _context.Tmovie.Where(x => x.Title.ToLower() == movie.Title.Trim().ToLower()).FirstOrDefault();

                // If it does not (null) exists another movie with the same title, save a new one.

                if (existingMovie == null)
                {
                    _context.Tmovie.Add(movie);
                    var result = _context.SaveChanges();

                    // Result variable allow return a message if the process was succesfully.

                    if (result == 1)
                    {
                        ViewBag.Movie = movie;
                    }
                    else
                    {
                        ViewBag.Error = "Error, the movie was not updated.";
                    }
                }
                else
                {
                    ViewBag.Error = "Already exits a movie with the same title.";
                }
            }
            else
            {
                ViewBag.Error = "Title must not be empty.";
            }

            return(View());
        }
Exemplo n.º 3
0
        private static void PickMovie()
        {
            using (var context = new RDBContext())
            {
                var random = new Random();

                int totalMovie = context.Tmovie.Where(x => x.Pick == false).ToList().Count();

                int randomNumber = random.Next(0, totalMovie);

                Console.WriteLine("");

                Console.WriteLine("");
                Console.Write("The movie picked was: ");

                var moviePicked = context.Tmovie.Where(x => x.Pick == false).Skip(randomNumber - 1).Take(1).FirstOrDefault();

                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("ID: " + moviePicked.Idmovie + ". Title: " + moviePicked.Title + ". Year: " + moviePicked.Year + ".");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine("");

                moviePicked.Pick     = true;
                moviePicked.PickDate = DateTime.Now;

                context.Tmovie.Update(moviePicked);
                var result = context.SaveChanges();

                if (result == 1)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("The movie was updated succesfully.");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }

                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error, the movie wasn't updated.");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }

                Console.WriteLine("");
                Console.Write("Type any key to continue...");
                Console.ReadKey();
                Console.Clear();
                ShowMenu();
            }
        }
Exemplo n.º 4
0
        private static void DeleteMovie()
        {
            Console.WriteLine("");
            Console.Write("Type a id movie that you want to delete: ");
            int idMovie = int.Parse(Console.ReadLine());

            Console.WriteLine("");
            using (var context = new RDBContext())
            {
                var deleteMovie = context.Tmovie.Where(x => x.Idmovie == idMovie).FirstOrDefault();

                if (deleteMovie != null)
                {
                    Console.Write("Do you want to delete ");
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write(deleteMovie.Title);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine("?");
                    Console.WriteLine("");

                    char deleteOption = '\0';
                    bool optionToggle = true;
                    do
                    {
                        Console.Write("Type an option (S/N): ");
                        deleteOption = Console.ReadKey().KeyChar;

                        if (deleteOption == 's' || deleteOption == 'S' || deleteOption == 'n' || deleteOption == 'N')
                        {
                            optionToggle = false;
                        }
                    } while (optionToggle);

                    if (deleteOption == 's' || deleteOption == 'S')
                    {
                        Console.WriteLine("");

                        context.Tmovie.Remove(deleteMovie);
                        var result = context.SaveChanges();

                        if (result == 1)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("The movie was deleted succesfully.");
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }

                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Error, the movie wasn't deleted.");
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }
                    }
                }

                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("It doesn't exist any movie with the id typed.");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }

                Console.WriteLine("");
                Console.Write("Type any key to continue...");
                Console.ReadKey();
                Console.Clear();
                ShowMenu();
            }
        }
Exemplo n.º 5
0
        private static void UpdateMenu() // Update a existing record.
        {
            Console.WriteLine("");
            Console.Write("Type a id movie that you want to update: ");
            int idMovie = int.Parse(Console.ReadLine());

            Console.WriteLine("");

            using (var context = new RDBContext())
            {
                var updateMovie = context.Tmovie.Where(x => x.Idmovie == idMovie).FirstOrDefault();

                if (updateMovie != null)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("1.Title: " + updateMovie.Title);
                    Console.WriteLine("2.Year: " + updateMovie.Year);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine("");
                    Console.Write("What data do you want to update? ");
                    int dataOption = int.Parse(Console.ReadLine());
                    Console.WriteLine("");

                    switch (dataOption)
                    {
                    case 1:
                        do
                        {
                            Console.Write("Type a new Title: ");
                            updateMovie.Title = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Console.ReadLine()).Trim();
                        } while (updateMovie.Title == "");

                        break;

                    case 2:
                        do
                        {
                            Console.Write("Type a new Year: ");
                            updateMovie.Title = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Console.ReadLine()).Trim();
                        } while (updateMovie.Title == "");

                        break;

                    default:
                        break;
                    }

                    var existingMovie = context.Tmovie.Where(x => x.Title.ToLower() == updateMovie.Title.ToLower()).FirstOrDefault();

                    Console.WriteLine("");

                    if (existingMovie == null)
                    {
                        context.Tmovie.Update(updateMovie);
                        var result = context.SaveChanges();

                        if (result == 1)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("The movie was updated succesfully.");
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }

                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Error, the movie wasn't updated.");
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }
                    }

                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Error, already existed a movie with the same name.");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                }

                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("It doesn't exist any movie with the id typed.");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
            }

            Console.WriteLine("");
            Console.Write("Type any key to continue...");
            Console.ReadKey();
            Console.Clear();
            ShowMenu();
        }