isotonicq

Untitled

Feb 25th, 2018
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections.Generic;
  2. using Db4objects.Db4o;
  3. using ObjectDatabase.Interfaces;
  4. using ObjectDatabase.Models;
  5. using ObjectDatabase.Properties;
  6.  
  7. namespace ObjectDatabase.Controllers
  8. {
  9. public sealed class PersonController : iPerson
  10. {
  11. public bool AddPerson(string firstname, string lastname)
  12. {
  13. var newPerson = new Person(firstname,lastname);
  14.  
  15. using (var container = Db4oEmbedded.OpenFile(Resources.Database))
  16. {
  17. if((container.Query<Person>(x => x.Firstname == firstname && x.Lastname == lastname)).Count > 0) return false;
  18. container.Store(newPerson);
  19. container.Commit();
  20. return true;
  21. }
  22. }
  23.  
  24. public bool AddPerson(string firstname, string lastname, Address address)
  25. {
  26. var newPerson = new Person(firstname, lastname,address);
  27.  
  28. using (var container = Db4oEmbedded.OpenFile(Resources.Database))
  29. {
  30. if ((container.Query<Person>(x => x.Firstname == firstname && x.Lastname == lastname)).Count > 0) return false;
  31. container.Store(newPerson);
  32. container.Commit();
  33. return true;
  34. }
  35. }
  36.  
  37. public bool AddPerson(string firstname, string lastname,IEnumerable<Telephone> telephones)
  38. {
  39. var newPerson = new Person(firstname, lastname,telephones);
  40.  
  41. using (var container = Db4oEmbedded.OpenFile(Resources.Database))
  42. {
  43. if ((container.Query<Person>(x => x.Firstname == firstname && x.Lastname == lastname)).Count > 0) return false;
  44. container.Store(newPerson);
  45. container.Commit();
  46. return true;
  47. }
  48. }
  49.  
  50. public bool AddPerson(string firstname, string lastname, Address address, IEnumerable<Telephone> telephones)
  51. {
  52. var newPerson = new Person(firstname, lastname,address,telephones);
  53.  
  54. using (var container = Db4oEmbedded.OpenFile(Resources.Database))
  55. {
  56. if ((container.Query<Person>(x => x.Firstname == firstname && x.Lastname == lastname)).Count > 0) return false;
  57.  
  58. container.Store(newPerson);
  59. container.Commit();
  60. return true;
  61. }
  62. }
  63.  
  64. public bool DeletePerson(string firstname, string lastname)
  65. {
  66. using (var container = Db4oEmbedded.OpenFile(Resources.Database))
  67. {
  68. var toRemove = container.Query<Person>(x => x.Firstname == firstname && x.Lastname == lastname);
  69.  
  70. if (toRemove.Count != 1) return false;
  71.  
  72. if (toRemove[0].Telephones != null)
  73. {
  74. container.Delete(toRemove[0].Telephones);
  75. }
  76.  
  77. if (toRemove[0].Address != null)
  78. {
  79. container.Delete(toRemove[0].Address);
  80. }
  81.  
  82. container.Delete(toRemove[0]);
  83. container.Commit();
  84. return true;
  85. }
  86. }
  87.  
  88. public bool EditPerson(string oldFirstname, string oldLastname, string newFirstname, string newLastName)
  89. {
  90. using (var container = Db4oEmbedded.OpenFile(Resources.Database))
  91. {
  92. var toEdit = container.Query<Person>(x => x.Firstname == oldFirstname && x.Lastname == oldLastname);
  93.  
  94. if (toEdit.Count != 1) return false;
  95.  
  96. toEdit[0].Firstname = newFirstname;
  97. toEdit[0].Lastname = newLastName;
  98. container.Commit();
  99. return true;
  100. }
  101. }
  102. }
  103. }
RAW Paste Data