Created
December 17, 2014 16:34
-
-
Save jonathanfmills/3a1b16729cbf6f41734e to your computer and use it in GitHub Desktop.
Singleton Repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Web; | |
| using ToDoList.Models; | |
| namespace ToDoList.data | |
| { | |
| public sealed class TaskRepository | |
| { | |
| private int nextId = 3; | |
| private static TaskRepository instance = null; | |
| public List<Task> tasks = new List<Task>(new Task[] | |
| { | |
| new Task(){Id=1, Completed = false,Name = "Task 1"}, | |
| new Task(){Id = 2,Completed = true,Name = "Task 2"} | |
| }); | |
| public static TaskRepository GetRepositoryInstance() | |
| { | |
| if (instance == null) | |
| { | |
| instance = new TaskRepository(); | |
| } | |
| return instance; | |
| } | |
| internal void Add(Task value) | |
| { | |
| value.Id = nextId; | |
| nextId++; | |
| tasks.Add(value); | |
| } | |
| internal void UpdateTask(int id, Task value) | |
| { | |
| Task task = tasks.Find(x => x.Id == id); | |
| task.Completed = value.Completed; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment