svetlyoek

Untitled

Jun 10th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1.  
  2. namespace Repository
  3. {
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7.  
  8. public class Repository
  9. {
  10. private Dictionary<int,Person> persons;
  11.  
  12. public Dictionary<int,Person> Persons
  13. {
  14. get { return this.persons; }
  15.  
  16. set { this.persons = value; }
  17. }
  18.  
  19. public Repository()
  20. {
  21. this.Persons = new Dictionary<int, Person>();
  22. }
  23.  
  24. public int Count => this.persons.Count;
  25.  
  26. public void Add(Person person)
  27. {
  28. int idNumber = 0;
  29.  
  30. if (!persons.ContainsKey(idNumber))
  31. {
  32. persons.Add(idNumber,person);
  33.  
  34.  
  35. }
  36. else
  37. {
  38. idNumber++;
  39.  
  40. persons.Add(idNumber,person);
  41.  
  42. }
  43.  
  44. }
  45.  
  46. public Person Get(int idNumber)
  47. {
  48.  
  49. if (persons.ContainsKey(idNumber))
  50. {
  51. var currentPerson = persons[idNumber];
  52. return currentPerson;
  53. }
  54.  
  55. return null;
  56. }
  57.  
  58. public void Update(int idNumber, Person newPerson)
  59. {
  60. if (persons.ContainsKey(idNumber))
  61. {
  62.  
  63. persons[idNumber] = newPerson;
  64.  
  65. Console.WriteLine("true");
  66. }
  67. else
  68. {
  69. Console.WriteLine("false");
  70. }
  71. }
  72.  
  73. public void Delete(int idNumber)
  74. {
  75. if (persons.ContainsKey(idNumber))
  76. {
  77. persons.Remove(idNumber);
  78.  
  79. Console.WriteLine("true");
  80. }
  81. else
  82. {
  83. Console.WriteLine("false");
  84. }
  85. }
  86.  
  87.  
  88. }
  89. }
Add Comment
Please, Sign In to add comment