/// <summary> /// Returns a MovieExemplar from rental. /// </summary> /// <param name="exemplar">a reference to MovieExemplar to be returned</param> /// public void ReturnItem(MovieExemplar exemplar) { if (exemplar == null || exemplar.RentedAsItem == null) { return; // nothing to do } exemplar.RentedAsItem.ReturnFromRental(); }
/// <summary> /// Removes a first matching movie exemplar from library /// </summary> /// public void RemoveMovieExemplar(Predicate <MovieExemplar> match) { MovieExemplar exemplar = FindMovieExemplar(match); if (exemplar != null) { exemplar.Movie.MovieExemplars.Remove(exemplar); } }
/// <summary> /// Rents a MovieExemplar to a Customer. /// </summary> /// <param name="exemplar">instance of MovieExemplar class; must not be /// already rented</param> /// <param name="customer">instance of Customer class</param> /// <param name="days">an integer with number of days</param> /// <param name="fee">an decimal with rental fee</param> /// public void RentItem(MovieExemplar exemplar, Customer customer, int days, decimal fee) { if (exemplar == null || customer == null) { return; // nothing to rent } if (exemplar.IsRented) { throw new Exception("Cannot rent item that is already rented."); } DateTime dueDate = DateTime.Now.AddDays(days); // Create RentedItem as assocation between MovieExemplar and Customer // RentedItem item = new RentedItem(exemplar, dueDate, fee); item.AddTo(customer); }
///////////////////////////////////////////////////////////////////////////////////// #region [ Database Record Synchronization ] /// <summary> /// Loads contents of the UI components from the <see cref="Record"/>. /// </summary> /// protected override void OnLoadData() { RentedItem rentedItem = Record; //new RentedItem( Record ); this.customerInfo.Text = Customer != null?Customer.ToString() : "(Select a customer to which this exemplar belongs first)"; if (this.Customer == null && MasterRecord != null) { Customer masterCustomer = MasterRecord as Customer; if (masterCustomer != null) { this.Customer = masterCustomer; this.customerInfo.Text = masterCustomer.ToString(); } } if (rentedItem == null) { this.Exemplar = null; this.exemplarInfo.Text = "Select a movie exemplar to be rented..."; this.rentalFee.InitText = "0.00"; this.dueDate.InitText = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd"); } else { this.Exemplar = rentedItem.Exemplar; this.exemplarInfo.Text = rentedItem.Exemplar.ToString(); this.rentalFee.InitText = rentedItem.RentalFee.ToString("0.00"); this.dueDate.InitText = rentedItem.VerboseDueDate; } this.exemplarChanged = false; base.OnLoadData(); }
/// <summary> /// Initializes UI components of the MdiForm. /// </summary> /// protected override void InitializeComponents() { ///////////////////////////////////////////////////////////////////////////////// // Table layout grid definition, with rows and columns in Em units. float[] col = { 3, 18, 40, 50, 79 }; float[] row = { 2, 4, 7, 9, 11, 12, 14, 16, 18, 21, 22 }; float maxLen = 15; // Maximum text length ///////////////////////////////////////////////////////////////////////////////// // Static text int r = 2, c = 0; NewStaticText(col[c], row[r++], "Due Date:"); NewStaticText(col[c], row[r++], "Rental Fee:"); ///////////////////////////////////////////////////////////////////////////////// // Customer info label this.customerInfo = NewLabel(col[0], row[0] - (Em.IsGUI ? 0.2f : 0f), (float)MdiForm.Width / Em.Width - col[0] * 2 ); this.exemplarInfo = NewLabel(col[0], row[1] + (Em.IsGUI ? 0.2f : 0f), (float)MdiForm.Width / Em.Width - col[0] * 2 ); this.exemplarSelect = new MyButton() { Left = (int)(col[2] * Em.Width), Top = (int)((row[2] - (Em.IsGUI ? 0.2f : 0f)) * Em.Height), Text = "&Select Movie Exemplar", AutoSize = true, TabStop = true, TabIndex = NextTabIndex, Parent = MdiForm, }; ///////////////////////////////////////////////////////////////////////////////// // TextBox fields r = 2; c = 1; this.dueDate = NewTextField(col[c], row[r++], maxLen); this.rentalFee = NewTextField(col[c], row[r++], maxLen); ///////////////////////////////////////////////////////////////////////////////// // Field validation event handlers this.dueDate.Validating += (sender, e) => { MdiForm.ErrorMessage = null; if (ReadOnly || !this.dueDate.ContentsChanged) { return; } ValidateNotNull("Due date", this.dueDate.Text, e); ValidateDate("Due date", this.dueDate.Text, "yyyy-M-d", " in ISO format (yyyy-mm-dd).", e); }; this.rentalFee.Validating += (sender, e) => { MdiForm.ErrorMessage = null; if (ReadOnly || !this.rentalFee.ContentsChanged) { return; } string fieldName = "Rental Fee"; ValidateNotNull(fieldName, this.dueDate.Text, e); decimal fieldValue = 0; // default value to satisfy validation if null ValidateDecimal(fieldName, this.rentalFee.Text, e, ref fieldValue); // Rental fee must be either null or an decimal >= 0 // if (!e.Cancel && fieldValue <= 0) { MdiForm.ErrorMessage = fieldName + " must not be a positive number."; MdiForm.Beep(); e.Cancel = true; } }; ///////////////////////////////////////////////////////////////////////////////// // Movie Exemplar Selection as modal MovieExemplarListForm (i.e. dialog) this.exemplarSelect.Click += (sender, e) => { this.ExecuteWithoutFormValidation(() => { MovieExemplarListForm form = new MovieExemplarListForm(); form.CommonFilter = ex => !ex.IsRented; form.OpenModal(this.Exemplar, selectedExemplar => { this.Exemplar = selectedExemplar; this.exemplarInfo.Text = selectedExemplar.ToString(); this.exemplarChanged = true; if (this.Customer != null) { decimal fee = MainForm.VideoStore.GetPrice( this.Customer.Membership, this.Exemplar.PriceClass, this.Customer.RentedItemsCount + 1); this.rentalFee.Text = fee.ToString("0.00"); } form.QuitForm(); this.dueDate.Select(); }); }); }; ///////////////////////////////////////////////////////////////////////////////// // Customer info GUI/TUI specific setup // #if TEXTUI MdiForm.GotFocus += (sender, e) => { this.customerInfo.ForeColorInact = Color.White; this.customerInfo.ForeColor = Color.White; this.exemplarInfo.ForeColorInact = Color.Cyan; this.exemplarInfo.ForeColor = Color.Cyan; }; #else this.customerInfo.Font = MainForm.HeadingFont; this.customerInfo.Height = Em.Height * 15 / 10; this.customerInfo.ForeColor = Color.DarkBlue; this.customerInfo.AutoSize = false; this.customerInfo.AutoEllipsis = true; this.exemplarInfo.Height = Em.Height + (Em.IsGUI ? 2 : 0); this.exemplarInfo.ForeColor = Color.DarkRed; this.exemplarInfo.AutoSize = false; this.exemplarInfo.AutoEllipsis = true; this.MdiForm.FontChanged += (sender, e) => { this.customerInfo.Font = MainForm.HeadingFont; this.customerInfo.Height = Em.Height * 15 / 10; this.exemplarInfo.Height = Em.Height + (Em.IsGUI ? 2 : 0); }; #endif ///////////////////////////////////////////////////////////////////////////////// base.InitializeComponents(); }
///////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Query filter to return all movie exemplars. /// </summary> /// internal bool QueryAllExemplars(MovieExemplar exemplar) { return(true); }
///////////////////////////////////////////////////////////////////////////////// #region [ Random Test Records ] /// <summary> /// Adds random test records to existing database. Basically, this method has /// the same structure as <see cref="CreateSampleDatabase"/>, but it rather /// generates random customer names and movie titles. /// </summary> /// public void AddTestRecords() { if (VideoStore == null) { return; } ///////////////////////////////////////////////////////////////////////////// Customer customer = new Customer() { PersonID = RandomPID, FirstName = RndFirstName, LastName = RndLastName, Address = RndLastName + "sgatan " + (random.Next(32) + 1), PostCode = "128 87", City = "Stockholm", Country = "Sweden", CellPhone = "+46(73)" + (random.Next(10000000) + 50000000), CreditCard = new CreditCard(CreditCardType.MasterCard, "5105-1051-0510-5100", 14, 12), Membership = RndMembership }; customer.AddTo(VideoStore); ///////////////////////////////////////////////////////////////////////////// customer = new Customer() { PersonID = RandomPID, FirstName = RndFirstName, LastName = RndLastName, Address = RndLastName + "svägen " + (random.Next(32) + 1), PostCode = "128 87", City = "Stockholm", Country = "Sweden", CellPhone = "+46(73)" + (random.Next(10000000) + 80000000), Membership = RndMembership }; customer.AddTo(VideoStore); ///////////////////////////////////////////////////////////////////////////// customer = new Customer() { PersonID = RandomPID, FirstName = RndFirstName, LastName = RndLastName, Address = RndLastName + "sgatan " + (random.Next(32) + 1), PostCode = "141 40", City = "Huddinge", Country = "Sweden", CellPhone = "+46(73)" + (random.Next(10000000) + 30000000), EMail = RndFirstName + "@" + RndFirstName + ".name", Membership = RndMembership }; customer.AddTo(VideoStore); ///////////////////////////////////////////////////////////////////////////// Movie movie = new Movie() { Title = RndMovieTitle, IMDB = "Faked Movie", Genre = RndGenre, FirstRelease = RndDateTime, Duration = RndDuration, Country = "UK | US", Language = "English | Russian (only few words)", PgRate = "11 (Sweden)", Directors = new List <string> () { "Stanley Kubrick" }, Writers = new List <string> () { "Stanley Kubrick", "Arthur C Clarke" }, Actors = new List <MovieActor> () { new MovieActor("Keir Dullea", "Dr Dave Bowman"), new MovieActor("Gary Lockwood", "Dr Frank Poole "), new MovieActor("William Sylves", "Dr Heywood R Floyd"), new MovieActor("Douglas Rain", "HAL 9000 (voice)"), } }; movie.AddTo(VideoStore); MovieExemplar exemplar = new MovieExemplar() { Media = Media.VHS, Released = new DateTime(1999, 6, 29), ImageFormat = "NTSC 4:3", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B00000J2KZ", Features = "Turner Home Ent" }; exemplar.AddTo(movie); exemplar = new MovieExemplar() { Media = Media.BluRay, Released = new DateTime(2007, 10, 23), ImageFormat = "2.20:1", Subtitles = "English | Spanish | French", PriceClass = PriceClass.NewMovie, ISAN = "ASIN:B000Q66J1M", Features = "All Regions" }; exemplar.AddTo(movie).CreateCopies(1 + random.Next(2)); ///////////////////////////////////////////////////////////////////////////// movie = new Movie() { Title = RndMovieTitle, IMDB = "Faked Movie", Genre = RndGenre, FirstRelease = RndDateTime, Duration = RndDuration, Country = "UK | US", Language = "English | Vietnamese", PgRate = "15 (Sweden)", Directors = new List <string> () { RndMoviePerson, }, Writers = new List <string> () { RndMoviePerson, }, Actors = new List <MovieActor> () { RndActor, RndActor, RndActor } }; movie.AddTo(VideoStore); exemplar = new MovieExemplar() { Media = Media.DVD, Released = new DateTime(1905 + random.Next(105), 3, 5), ImageFormat = "Anamorphic, 1.85:1", Subtitles = "Spanish | French", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B00005AUJQ", Features = "Special Edition | MGM" }; exemplar.AddTo(movie).CreateCopies(1 + random.Next(2)); ///////////////////////////////////////////////////////////////////////////// movie = new Movie() { Title = RndMovieTitle, IMDB = "Faked Movie", Genre = RndGenre, FirstRelease = RndDateTime, Duration = RndDuration, Country = "Sweden", Language = "Swedish | Norwegian | Spanish", Directors = new List <string> () { RndMoviePerson, RndMoviePerson, }, Writers = new List <string> () { RndMoviePerson, RndMoviePerson, }, Actors = new List <MovieActor> () { RndActor, RndActor, RndActor, RndActor, RndActor, RndActor } }; movie.AddTo(VideoStore); exemplar = new MovieExemplar() { Media = Media.BluRay, Released = new DateTime(2001, 6, 5), ImageFormat = "Widescreen (1.78:1)", Subtitles = "Swedish | Norwegian", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B003TLJY1I", Features = "SF(Fox) | Region 2" }; exemplar.AddTo(movie); ///////////////////////////////////////////////////////////////////////////// movie = new Movie() { Title = RndMovieTitle, IMDB = "Faked Movie", Genre = RndGenre, FirstRelease = RndDateTime, Duration = RndDuration, Country = "USA", Language = "English", PgRate = "15 (Sweden)", Directors = new List <string> () { RndMoviePerson, }, Writers = new List <string> () { RndMoviePerson, RndMoviePerson, }, Actors = new List <MovieActor> () { RndActor, RndActor, RndActor } }; movie.AddTo(VideoStore); exemplar = new MovieExemplar() { Media = Media.DVD, Released = new DateTime(2001, 9, 25), ImageFormat = "B&W, 1.33:1, NTSC", Subtitles = "English | French | Portuguese | Spanish ", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B00003CX9E", Features = "Turner Home Ent | 2 discs" }; exemplar.AddTo(movie).CreateCopies(1 + random.Next(3)); exemplar = new MovieExemplar() { Media = Media.VHS, Released = new DateTime(1996, 8, 13), ImageFormat = "B&W, 1.33:1, NTSC", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:6304119046", Features = "RKO Radio Pictures | Special Edition" }; exemplar.AddTo(movie); exemplar = new MovieExemplar() { Media = Media.BluRay, ImageFormat = "B&W, 1.33:1, NTSC", Subtitles = "English | French | Portuguese | Spanish ", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B001PIHH5M", Features = "Warner" }; exemplar.AddTo(movie); }
///////////////////////////////////////////////////////////////////////////////// #region [ Test Suite ] /// <summary> /// Creates a sample VRO database and runs various tests according ID132V /// Lab3a specification. /// </summary> /// <remarks> /// Final contents of the sample database: /// <pre> /// 3 customers /// 3 price specifications /// 4 movies /// 9 movie exemplars /// 3 rented items /// </pre> /// </remarks> /// public void CreateSampleDatabase() { ///////////////////////////////////////////////////////////////////////////// // Create default instance of VideoRentalOutlet class and hook // our event handler that will trace changes. VideoStore = new VideoRentalOutlet("Blurry Bluray", "SE554078214101") { Address = "Tulegatan 50", PostCode = "112 54", City = "Solna", Country = "Sweden", Phone = "+46(8)90510", EMail = "*****@*****.**", HomePage = "http://www.blurrybluray.com" }; VideoStore.Changed += VideoStore_Changed; Out.Begin(); ///////////////////////////////////////////////////////////////////////////// Out.Title("Dumping contents of initial empty store..."); Out.WriteLine(VideoStore.FullInfo()); Out.WriteLine(VideoStore.PriceList.FullInfo()); Out.WriteLine(VideoStore.Customers.FullInfo()); Out.WriteLine(VideoStore.MovieExemplars.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Changing price list..."); VideoStore.PriceList.UpdatePrice(Membership.Member, PriceClass.OlderMovie, 1, 10m); VideoStore.PriceList.UpdatePrice(Membership.GoldMember, PriceClass.OlderMovie, 1, 5m); VideoStore.PriceList.UpdatePrice(Membership.GoldMember, PriceClass.NewHotMovie, 1, 10m); VideoStore.PriceList.UpdatePrice(Membership.NotMember, PriceClass.OlderMovie, 3, 15m); VideoStore.PriceList.UpdatePrice(Membership.NotMember, PriceClass.SwedishNew, 1, 20m); Out.WriteLine(VideoStore.PriceList.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Getting fees for misc Membership/PriceClass combinations..."); Enum[] membershipsDesc = { Membership.GoldMember, Membership.Member, Membership.NotMember }; Enum[] priceClassesAsc = { PriceClass.OlderMovie, PriceClass.NewMovie, PriceClass.NewHotMovie, PriceClass.SwedishNew, }; int[] quantitiesDesc = { 5, 1 }; foreach (Enum membership in membershipsDesc) { foreach (Enum priceClass in priceClassesAsc) { foreach (int quantity in quantitiesDesc) { decimal fee = VideoStore.GetPrice( (Membership)membership, (PriceClass)priceClass, quantity); Out.WriteLine(string.Format("{0,-12} {1,-15} {2,3} {3,8:0.00}", membership.Verbose(), priceClass.Verbose(), quantity, fee)); } } } ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding Andrew Wiles as a customer..."); Customer customer = new Customer() { PersonID = "US 1953-05-14", FirstName = "Andrew", LastName = "Wiles", Address = "Princeton University", PostCode = "08544", City = "Princeton, NJ", Country = "USA", Phone = "+1(609)789-44-44", CreditCard = new CreditCard(CreditCardType.VISA, "4000-0012-3456-7899", 14, 12), Membership = Membership.Member }; customer.AddTo(VideoStore); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding John Poe as a customer..."); customer = new Customer() { PersonID = "820315-1035", FirstName = "John", LastName = "Poe", Address = "aaa", PostCode = "ppp", City = "ccc", EMail = "*****@*****.**", Membership = Membership.GoldMember }; customer.AddTo(VideoStore); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding Linnéa Andersson as a customer..."); customer = new Customer() { PersonID = "830415-2034", FirstName = "Linnéa", LastName = "Andersson", Address = "Ostmästargatan 12", PostCode = "128 87", City = "Stockholm", CellPhone = "+46(73)45342225", Membership = Membership.GoldMember }; customer.AddTo(VideoStore); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding Richard Liboff as a customer..."); customer = new Customer() { PersonID = "193405143415", FirstName = "Richard", LastName = "Liboff", Address = "Oxvägen 44", PostCode = "141 40", City = "Huddinge", Phone = "+46(8)7798881", EMail = "*****@*****.**" }; customer.AddTo(VideoStore); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Removing non-existing customer..."); VideoStore.RemoveCustomer(cust => cust.FirstName == "(*&*($@"); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Changing customer's last name 'Poe' to 'Doe'..."); customer = VideoStore.FindCustomer(cust => cust.LastName == "Poe"); customer = new Customer(customer); customer.LastName = "Doe"; customer.Update(); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Removing customer with name 'John Doe'..."); VideoStore.RemoveCustomer(cust => cust.FullName == "John Doe"); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Dumping contents of the customer database..."); Out.WriteLine(VideoStore.Customers.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding 1 VHS and 3 BluRay copies of '2001 A Space Odyssey'..."); Movie movie = new Movie() { Title = "2001: A Space Odyssey", IMDB = "http://www.imdb.com/title/tt0062622/", Genre = Genre.ScienceFiction | Genre.Adventure | Genre.Mystery, FirstRelease = new DateTime(1968, 4, 2), Duration = new TimeSpan(0, 141, 0), Country = "UK | US", Language = "English | Russian (only few words)", PgRate = "11 (Sweden)", Directors = new List <string> () { "Stanley Kubrick" }, Writers = new List <string> () { "Stanley Kubrick", "Arthur C Clarke" }, Actors = new List <MovieActor> () { new MovieActor("Keir Dullea", "Dr Dave Bowman"), new MovieActor("Gary Lockwood", "Dr Frank Poole "), new MovieActor("William Sylves", "Dr Heywood R Floyd"), new MovieActor("Douglas Rain", "HAL 9000 (voice)"), } }; movie.AddTo(VideoStore); MovieExemplar exemplar = new MovieExemplar() { Media = Media.VHS, Released = new DateTime(1999, 6, 29), ImageFormat = "NTSC 4:3", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B00000J2KZ", Features = "Turner Home Ent" }; exemplar.AddTo(movie); exemplar = new MovieExemplar() { Media = Media.BluRay, Released = new DateTime(2007, 10, 23), ImageFormat = "2.20:1", Subtitles = "English | Spanish | French", PriceClass = PriceClass.NewMovie, ISAN = "ASIN:B000Q66J1M", Features = "All Regions" }; exemplar.AddTo(movie).CreateCopies(2); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding 2 DVD copies of 'Platoon'..."); movie = new Movie() { Title = "Platoon", IMDB = "http://www.imdb.com/title/tt0091763/", Genre = Genre.Action | Genre.Drama | Genre.War, FirstRelease = new DateTime(1986, 12, 19), Duration = new TimeSpan(0, 120, 0), Country = "UK | US", Language = "English | Vietnamese", PgRate = "15 (Sweden)", Directors = new List <string> () { "Oliver Stone" }, Writers = new List <string> () { "Oliver Stone" }, Actors = new List <MovieActor> () { new MovieActor("Charlie Sheen", "Chris"), new MovieActor("Tom Berenger", "Sgt. Barnes"), new MovieActor("Willem Dafoe", "Sgt. Elias"), } }; movie.AddTo(VideoStore); exemplar = new MovieExemplar() { Media = Media.DVD, Released = new DateTime(2001, 6, 5), ImageFormat = "Anamorphic, 1.85:1", Subtitles = "Spanish | French", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B00005AUJQ", Features = "Special Edition | MGM" }; exemplar.AddTo(movie).CreateCopies(1); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding one exemplar of 'Sällskapsresan'..."); movie = new Movie() { Title = "Sällskapsresan", IMDB = "http://www.imdb.com/title/tt0081590/", FirstRelease = new DateTime(1980, 8, 22), Duration = new TimeSpan(0, 107, 0), Country = "Sweden", Language = "Swedish | Norwegian | Spanish", Directors = new List <string> () { "Lasse Åberg", "Peter Hald" }, Writers = new List <string> () { "Bo Jönsson", "Lasse Åberg" }, Actors = new List <MovieActor> () { new MovieActor("Lasse Åberg", "Stig-Helmer Olsson"), new MovieActor("Lottie Ejebrant", "Maj-Britt Lindberg"), new MovieActor("Jon Skolmen", "Ole Bramserud") } }; movie.AddTo(VideoStore); exemplar = new MovieExemplar() { Media = Media.BluRay, Released = new DateTime(2001, 6, 5), ImageFormat = "Widescreen (1.78:1)", Subtitles = "Swedish | Norwegian", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B003TLJY1I", Features = "SF(Fox) | Region 2" }; exemplar.AddTo(movie); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding 2 DVD, 1 VHS and 1 BluRay copies of 'Citizen Kane'..."); movie = new Movie() { Title = "Citizen Kane", IMDB = "http://www.imdb.com/title/tt0033467/", Genre = Genre.Drama | Genre.Mystery, FirstRelease = new DateTime(1941, 5, 1), Duration = new TimeSpan(0, 119, 0), Country = "USA", Language = "English", PgRate = "15 (Sweden)", Directors = new List <string> () { "Orson Welles" }, Writers = new List <string> () { "Herman J. Mankiewicz", "Orson Welles" }, Actors = new List <MovieActor> () { new MovieActor("Orson Welles", "Kane"), new MovieActor("Joseph Cotten", "Jedediah Leland"), new MovieActor("Dorothy Comingore", "Susan A Kane"), } }; movie.AddTo(VideoStore); exemplar = new MovieExemplar() { Media = Media.DVD, Released = new DateTime(2001, 9, 25), ImageFormat = "B&W, 1.33:1, NTSC", Subtitles = "English | French | Portuguese | Spanish ", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B00003CX9E", Features = "Turner Home Ent | 2 discs" }; exemplar.AddTo(movie).CreateCopies(1); exemplar = new MovieExemplar() { Media = Media.VHS, Released = new DateTime(1996, 8, 13), ImageFormat = "B&W, 1.33:1, NTSC", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:6304119046", Features = "RKO Radio Pictures | Special Edition" }; exemplar.AddTo(movie); exemplar = new MovieExemplar() { Media = Media.BluRay, ImageFormat = "B&W, 1.33:1, NTSC", Subtitles = "English | French | Portuguese | Spanish ", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B001PIHH5M", Features = "Warner" }; exemplar.AddTo(movie); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Removing exemplar with ID #3 from library..."); VideoStore.RemoveMovieExemplar(ex => ex.ID == 3); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Removing exemplar with ID #8 from library..."); VideoStore.RemoveMovieExemplar(ex => ex.ID == 8); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Renting out movie exemplar #4 to user with PID 830415-2034"); try { VideoStore.RentItem( VideoStore.FindMovieExemplar(ex => ex.ID == 4), VideoStore.FindCustomer(cust => cust.PersonID == "830415-2034"), /* rent days: */ 2, /* rental fee: */ 15 ); } catch (Exception ex) { Out.WriteLine(ex.Message); } Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Renting out movie ex #6 to user with first name Andrew..."); try { VideoStore.RentItem( VideoStore.FindMovieExemplar(ex => ex.ID == 6), VideoStore.FindCustomer(cust => cust.FirstName == "Andrew"), /* rent days: */ 3, /* rental fee: */ 20 ); } catch (Exception ex) { Out.WriteLine(ex.Message); } Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Returning exemplar #4 from renting..."); VideoStore.ReturnItem( VideoStore.FindMovieExemplar(ex => ex.ID == 4) ); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Renting out movie exemplar #2 to user with ID #1..."); try { VideoStore.RentItem( VideoStore.FindMovieExemplar(ex => ex.ID == 2), VideoStore.FindCustomer(cust => cust.ID == 1), /* rent days: */ 1, /* rental fee: */ 15 ); } catch (Exception ex) { Out.WriteLine(ex.Message); } Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Renting out movie exemplar #9 to user with ID #3..."); try { VideoStore.RentItem( VideoStore.FindMovieExemplar(ex => ex.ID == 9), VideoStore.FindCustomer(cust => cust.ID == 3), /* rent days: */ 1, /* rental fee: */ 15 ); } catch (Exception ex) { Out.WriteLine(ex.Message); } Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("LINQ: Listing all rented items using LINQ and yield return..."); var rented = from p in VideoStore.RentedItems select p; Out.WriteLine("Total {0} rented items:", rented.Count <RentedItem> ()); foreach (var item in rented) { Out.WriteLine(); Out.WriteLine(item); Out.WriteLine(); Out.WriteLine(" " + item.Exemplar); Out.WriteLine(" " + item.RentedTo); } ///////////////////////////////////////////////////////////////////////////// Out.Title("LINQ: Querying movies having 'odys' in title..."); var queryMovies = from p in VideoStore.Movies where p.FullTitle.ToLower().Contains("odys") select p; Out.WriteLine("Selected {0} movies:", queryMovies.Count <Movie> ()); foreach (var item in queryMovies) { Out.WriteLine(item.FullTitle); } ////////////////////////////////////////////////////////////////////////////// Out.Title("Dumping final movie collection..."); Out.WriteLine(VideoStore.Movies.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Dumping final movie exemplar collection..."); Out.WriteLine(VideoStore.MovieExemplars.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Dumping all customers with rented items..."); Out.WriteLine(VideoStore.QueryAllCustomersWithRentals()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Dumping all rented items..."); Out.WriteLine(VideoStore.QueryAllRentedItems()); ///////////////////////////////////////////////////////////////////////////// // Don't forget to remove hooked event handlers and mark end of test. // VideoStore.Changed -= VideoStore_Changed; Out.End(); ///////////////////////////////////////////////////////////////////////////// // Our sample database is now ready to be used. }