Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. //using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6.  
  7. namespace MovieDatabase.Models
  8. {
  9. public class Database
  10. {
  11. private List<Movie> db; // list of movies in the database
  12. private int _index; // position of current movie in the database
  13.  
  14. // initialise the database properties
  15. public Database()
  16. {
  17.  
  18. }
  19.  
  20. // A property to Return number of movies in the database
  21. public int Count
  22. {
  23. // get will return Count
  24. get
  25. {
  26. return Count;
  27. }
  28.  
  29. // set Count to size of database (amount of movies)
  30. set
  31. {
  32. Count = db.Count;
  33. }
  34. }
  35.  
  36. // A property to return current _index position which should be either
  37. // -1 if database is empty
  38. // 0 - db.Count-1 if database is not empty
  39. public int Index
  40. {
  41. get
  42. {
  43. return _index;
  44. }
  45.  
  46. set
  47. {
  48. if (!db.Any())
  49. {
  50. int temp_IndexVal;
  51. temp_IndexVal = _index;
  52.  
  53. _index = (db.Count - 1);
  54.  
  55. // set _index to first element
  56. if (value == 0)
  57. _index = 0;
  58.  
  59. // set _index to next element
  60. if (value == -2)
  61. _index = temp_IndexVal++;
  62.  
  63. // set _index to previous element
  64. if (value == -3)
  65. _index = temp_IndexVal--;
  66. }
  67. else
  68. {
  69. _index = -1;
  70. }
  71. }
  72. }
  73.  
  74. // Add a movie to current position in database
  75. public void Add(Movie m)
  76. {
  77. db.Add(m);
  78. }
  79.  
  80. // Return current movie or null if database empty
  81. public Movie Get()
  82. {
  83. var currentMovie = new Movie();
  84.  
  85. if (db[Index] != null)
  86. {
  87. currentMovie = db.ElementAt(Index);
  88. }
  89. else
  90. {
  91. currentMovie = null;
  92. }
  93.  
  94. return currentMovie;
  95. }
  96.  
  97. // Delete current movie at index if there is a movie and update index
  98. public void Delete()
  99. {
  100. if (db[Index] != null)
  101. {
  102. db.RemoveAt(Index);
  103. }
  104. }
  105.  
  106. // Update the current movie at index if there is a movie and update index
  107. public void Update(Movie m)
  108. {
  109.  
  110. }
  111.  
  112. // Delete all movies from the database and reset index
  113. public void clear()
  114. {
  115. db.Clear();
  116. }
  117.  
  118. // Move index position to first movie (0)
  119. // return true if index update was possible, false otherwise
  120. public bool First()
  121. {
  122. bool updatePossible = false;
  123.  
  124. if (db[Index] != db[0])
  125. {
  126. Index = 0;
  127. updatePossible = true;
  128. }
  129. return updatePossible;
  130. }
  131.  
  132. // Move index position to last movie
  133. // true if index update was possible, false otherwise</returns>
  134. public bool Last()
  135. {
  136. bool updatePossible = false;
  137. int lastMovie = (db.Count - 1);
  138.  
  139. if (db[Index] != db[lastMovie])
  140. {
  141. Index = lastMovie;
  142. updatePossible = true;
  143. }
  144. return updatePossible;
  145. }
  146.  
  147. // Move index position to next movie
  148. // true if index update was possible, false otherwise<
  149. public bool Next()
  150. {
  151. bool movePossible = false;
  152. int lastMovie = (db.Count - 1);
  153.  
  154. if (db[Index] != db[lastMovie])
  155. {
  156. Index = -2;
  157. movePossible = true;
  158. }
  159. return movePossible;
  160.  
  161. }
  162.  
  163. // Move index position to previous movie
  164. // true if index update was possible, false otherwise
  165. public bool Prev()
  166. {
  167. bool movePossible = false;
  168.  
  169. if (db[Index] != db[0])
  170. {
  171. Index = -3;
  172. movePossible = true;
  173. }
  174. return movePossible;
  175.  
  176. }
  177. }
  178.  
  179. // Load movies from a json file and set index to first record
  180. public void Load(string file)
  181. {
  182.  
  183. }
  184.  
  185. // Save movies to a Json file
  186. public void Save(string file)
  187. {
  188.  
  189. }
  190.  
  191. // Following methods update the List of movies (db) to the specified order
  192.  
  193. // order the database by year of movie
  194. public void OrderByYear()
  195. {
  196.  
  197. }
  198.  
  199. // order the database by title of movie (ascending)
  200. public void OrderByTitle()
  201. {
  202.  
  203. }
  204.  
  205. // order the database by budget of movie (ascending)
  206. public void OrderByBudget()
  207. {
  208.  
  209. }
  210.  
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement