Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- namespace MovieDatabase.Models
- {
- public class Database
- {
- private List<Movie> db; // list of movies in the database
- private int _index; // position of current movie in the database
- // initialise the database properties
- public Database()
- {
- }
- // A property to Return number of movies in the database
- public int Count
- {
- // get will return Count
- get
- {
- return Count;
- }
- // set Count to size of database (amount of movies)
- set
- {
- Count = db.Count;
- }
- }
- // A property to return current _index position which should be either
- // -1 if database is empty
- // 0 - db.Count-1 if database is not empty
- public int Index
- {
- get
- {
- return _index;
- }
- set
- {
- if (!db.Any())
- {
- int temp_IndexVal;
- temp_IndexVal = _index;
- _index = (db.Count - 1);
- // set _index to first element
- if (value == 0)
- _index = 0;
- // set _index to next element
- if (value == -2)
- _index = temp_IndexVal++;
- // set _index to previous element
- if (value == -3)
- _index = temp_IndexVal--;
- }
- else
- {
- _index = -1;
- }
- }
- }
- // Add a movie to current position in database
- public void Add(Movie m)
- {
- db.Add(m);
- }
- // Return current movie or null if database empty
- public Movie Get()
- {
- var currentMovie = new Movie();
- if (db[Index] != null)
- {
- currentMovie = db.ElementAt(Index);
- }
- else
- {
- currentMovie = null;
- }
- return currentMovie;
- }
- // Delete current movie at index if there is a movie and update index
- public void Delete()
- {
- if (db[Index] != null)
- {
- db.RemoveAt(Index);
- }
- }
- // Update the current movie at index if there is a movie and update index
- public void Update(Movie m)
- {
- }
- // Delete all movies from the database and reset index
- public void clear()
- {
- db.Clear();
- }
- // Move index position to first movie (0)
- // return true if index update was possible, false otherwise
- public bool First()
- {
- bool updatePossible = false;
- if (db[Index] != db[0])
- {
- Index = 0;
- updatePossible = true;
- }
- return updatePossible;
- }
- // Move index position to last movie
- // true if index update was possible, false otherwise</returns>
- public bool Last()
- {
- bool updatePossible = false;
- int lastMovie = (db.Count - 1);
- if (db[Index] != db[lastMovie])
- {
- Index = lastMovie;
- updatePossible = true;
- }
- return updatePossible;
- }
- // Move index position to next movie
- // true if index update was possible, false otherwise<
- public bool Next()
- {
- bool movePossible = false;
- int lastMovie = (db.Count - 1);
- if (db[Index] != db[lastMovie])
- {
- Index = -2;
- movePossible = true;
- }
- return movePossible;
- }
- // Move index position to previous movie
- // true if index update was possible, false otherwise
- public bool Prev()
- {
- bool movePossible = false;
- if (db[Index] != db[0])
- {
- Index = -3;
- movePossible = true;
- }
- return movePossible;
- }
- }
- // Load movies from a json file and set index to first record
- public void Load(string file)
- {
- }
- // Save movies to a Json file
- public void Save(string file)
- {
- }
- // Following methods update the List of movies (db) to the specified order
- // order the database by year of movie
- public void OrderByYear()
- {
- }
- // order the database by title of movie (ascending)
- public void OrderByTitle()
- {
- }
- // order the database by budget of movie (ascending)
- public void OrderByBudget()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement