Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Repository
- {
- using System;
- using System.Collections.Generic;
- using System.Text;
- public class Repository
- {
- private Dictionary<int,Person> persons;
- public Dictionary<int,Person> Persons
- {
- get { return this.persons; }
- set { this.persons = value; }
- }
- public Repository()
- {
- this.Persons = new Dictionary<int, Person>();
- }
- public int Count => this.persons.Count;
- public void Add(Person person)
- {
- int idNumber = 0;
- if (!persons.ContainsKey(idNumber))
- {
- persons.Add(idNumber,person);
- }
- else
- {
- idNumber++;
- persons.Add(idNumber,person);
- }
- }
- public Person Get(int idNumber)
- {
- if (persons.ContainsKey(idNumber))
- {
- var currentPerson = persons[idNumber];
- return currentPerson;
- }
- return null;
- }
- public void Update(int idNumber, Person newPerson)
- {
- if (persons.ContainsKey(idNumber))
- {
- persons[idNumber] = newPerson;
- Console.WriteLine("true");
- }
- else
- {
- Console.WriteLine("false");
- }
- }
- public void Delete(int idNumber)
- {
- if (persons.ContainsKey(idNumber))
- {
- persons.Remove(idNumber);
- Console.WriteLine("true");
- }
- else
- {
- Console.WriteLine("false");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment