示例#1
0
        static void Main()
        {
            // Simple fetch from database
            MovieRecord mr = MovieRecord.GetByID(2);

            Console.WriteLine(mr.ToString());

            // New object is created
            mr = new MovieRecord(123, "The Last Samurai", 2003, 10);
            // Before the object was only in the memory. We need to save it, to store it in the persistence layer
            mr.Save();
            Console.WriteLine(MovieRecord.GetByID(123).ToString());

            // We adjust the price
            mr.ChangePrice(4.5);
            // Price is changed both in the in-memory object and in the persistence layer
            Console.WriteLine(MovieRecord.GetByID(123).ToString());



            // Object is removed from the database
            mr.Remove();
            if (MovieRecord.GetByID(123) == null)
            {
                Console.WriteLine("Object is removed from the database");
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome do DVD rental store");
            Console.Write("Please provide an ID of a movie: ");
            int         movie_id = int.Parse(Console.ReadLine());
            MovieRecord movie    = new MovieRecord(movie_id);

            Console.WriteLine(movie.ToString());

            Console.Write("Provide new price for the movie: ");
            double new_price = double.Parse(Console.ReadLine());

            movie.Price = new_price;
            movie.Save();

            Console.WriteLine("Provide values for new movie: ");
            string title = Console.ReadLine();
            int    year  = int.Parse(Console.ReadLine());
            double price = double.Parse(Console.ReadLine());

            movie = new MovieRecord(title, year, price);
            Console.WriteLine(movie.ToString());
            movie.Save();
        }