Exemplo n.º 1
0
        public void UpdateMoviesWithActors(int id, Movies_Actors movies_actors)
        {
            if (m_config.AllowDBWrite)
            {
                string query = $"update movies_actors set actor_id={movies_actors.Actor_ID}, movie_id={movies_actors.Movie_ID}" +
                               $" where id= {id}";


                try
                {
                    conn.Open();

                    NpgsqlCommand cmd = new NpgsqlCommand(query,
                                                          conn);
                    cmd.ExecuteNonQuery();

                    my_logger.Info($"update movies_actors  ");
                }
                catch (Exception ex)
                {
                    my_logger.Error($"Failed to update movies_actors. Error : {ex}");
                    my_logger.Error($"UpdateMoviesWithActors: [{query}]");
                }

                conn.Close();
            }
            else
            {
                my_logger.Info("Tried to write into Db while in read-pnly mode");
                Console.WriteLine($"Not allow to write into DB. check config");
            }
        }
Exemplo n.º 2
0
        public void AddMoviesWithActors(Movies_Actors movies_actors)
        {
            if (m_config.AllowDBWrite)
            {
                string query = $"insert  into movies_actors (movie_id,actor_id ) " +
                               $"values ({movies_actors.Movie_ID},{movies_actors.Actor_ID}); " +
                               $" SELECT LASTVAL();";

                try
                {
                    conn.Open();

                    NpgsqlCommand cmd = new NpgsqlCommand(query,
                                                          conn);
                    cmd.ExecuteNonQuery();
                    cmd.CommandType = CommandType.Text;
                    Decimal result = Convert.ToDecimal(cmd.ExecuteScalar());

                    my_logger.Info($"New movies_actors was added  with id {result}");
                }
                catch (Exception ex)
                {
                    my_logger.Error($"Failed to add movies_actors to data base. Error : {ex}");
                    my_logger.Error($"AddMoviesWithActors: [{query}]");
                }

                conn.Close();
            }
            else
            {
                my_logger.Info("Tried to write into Db while in read-pnly mode");
                Console.WriteLine($"Not allow to write into DB. check config");
            }
        }
Exemplo n.º 3
0
        public override bool Equals(object obj)
        {
            Movies_Actors movies_Actors = obj as Movies_Actors;

            if (movies_Actors != null)
            {
                return(this.ID == movies_Actors.ID);
            }

            return(false);
        }
Exemplo n.º 4
0
        public Movies_Actors GetMoviesWithActorsById(int id)
        {
            Movies_Actors movies_actors = null;
            string        query         = $"SELECT * FROM movies_actors where id={id}";

            try
            {
                conn.Open();

                NpgsqlCommand cmd = new NpgsqlCommand(query,
                                                      conn);
                var reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    movies_actors =
                        new Movies_Actors
                    {
                        ID       = Convert.ToInt32(reader["id"]),
                        Actor_ID = Convert.ToInt32(reader["actor_id"]),
                        Movie_ID = Convert.ToInt32(reader["movie_id"])
                    };
                }
                cmd.Connection.Close();

                my_logger.Info($"get movies_actors with id= {id} ");
            }
            catch (Exception ex)
            {
                my_logger.Error($"Failed to get movies_actors. Error : {ex}");
                my_logger.Error($"GetMoviesWithActorsById: [{query}]");
            }
            conn.Close();


            return(movies_actors);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            my_logger.Info("******************** System startup");

            m_config = new PostgresSQL_AppConfig();

            string m_conn = m_config.ConnectionString;

            Console.WriteLine($"-- Hello App {m_config.AppName}");

            Actors actor1 = new Actors
            {
                ID       = 11,
                Name     = "adi chen",
                BirtDate = "13.04.1956"
            };

            Actors actor2 = new Actors
            {
                ID       = 12,
                Name     = "adi levi",
                BirtDate = "13.04.1966"
            };

            Geners gener1 = new Geners
            {
                ID   = 9,
                Name = "horror"
            };


            Geners gener2 = new Geners
            {
                ID   = 9,
                Name = "france"
            };

            Movies movie1 = new Movies
            {
                Name        = "fast and angery",
                genre_ID    = 1,
                ID          = 9,
                releaseDate = "12.05.2000"
            };

            Movies movie2 = new Movies
            {
                Name        = "rain man",
                genre_ID    = 2,
                ID          = 19,
                releaseDate = "12.05.2011"
            };

            Movies_Actors movies_actors1 = new Movies_Actors
            {
                ID       = 33,
                Actor_ID = 21,
                Movie_ID = 1
            };

            Movies_Actors movies_actors2 = new Movies_Actors
            {
                ID       = 34,
                Actor_ID = 14,
                Movie_ID = 2
            };

            DAO dAO = new DAO();

            dAO.AddActors(actor1);
            dAO.AddGeneres(gener1);
            dAO.AddMovies(movie1);
            dAO.AddMoviesWithActors(movies_actors1);



            Console.WriteLine("GetActorsById: ");
            Console.WriteLine(dAO.GetActorsById(3).ToString());
            Console.WriteLine();



            Console.WriteLine("GetMoviesById: ");
            Console.WriteLine(dAO.GetMoviesById(3).ToString());
            Console.WriteLine();


            Console.WriteLine("GetMoviesWithActorsById: ");
            Console.WriteLine(dAO.GetMoviesWithActorsById(51).ToString());
            Console.WriteLine();


            Console.WriteLine("GetGeneresById: ");
            Console.WriteLine(dAO.GetGeneresById(3).ToString());
            Console.WriteLine();

            Console.WriteLine("GetAllGeneres: ");
            dAO.GetAllGeneres().ForEach(s => Console.WriteLine(s.ToString()));
            Console.WriteLine();

            Console.WriteLine("GetAllActors: ");
            dAO.GetAllActors().ForEach(s => Console.WriteLine(s.ToString()));
            Console.WriteLine();

            Console.WriteLine("GetAllMovies: ");
            dAO.GetAllMovies().ForEach(s => Console.WriteLine(s.ToString()));
            Console.WriteLine();

            Console.WriteLine("GetAllMoviesWithActors: ");
            dAO.GetAllMoviesWithActors().ForEach(s => Console.WriteLine(s.ToString()));
            Console.WriteLine();

            Console.WriteLine("GetAllMoviesWithActorBornBefore1972: ");
            dAO.GetAllMoviesWithActorBornBefore1972().ForEach(s => Console.WriteLine(s.ToString()));
            Console.WriteLine();



            Console.WriteLine("GetActorWithMaxMovies: ");
            dAO.GetActorWithMaxMovies().ForEach(s => Console.WriteLine(s.ToString()));;
            Console.WriteLine();

            Console.WriteLine("GetFristMoviesInEveryYesr: ");
            dAO.GetFristMoviesInEveryYesr().ForEach(s => Console.WriteLine(s.ToString()));;
            Console.WriteLine();

            Console.ReadLine();

            /*    dAO.UpdateActors(11, actor2);
             *  dAO.UpdateGeneres(11, gener2);
             *  dAO.UpdateMovies(11, movie2);
             *  dAO.UpdateMoviesWithActors(11,movies_actors2);
             *
             *
             * dAO.DeleteActors(5);
             * dAO.DeleteGeneres(5);
             * dAO.DeleteMovies(5);
             * dAO.DeleteMoviesWithActors(5);*/

            my_logger.Info("******************** System shutdown");
        }