Created
February 27, 2021 04:46
-
-
Save bbachi/d60b77c6a6daf55d8d038fd9a131e171 to your computer and use it in GitHub Desktop.
This file contains 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; | |
namespace angular_dotnet_example.Models | |
{ | |
public interface IUserRepository | |
{ | |
IEnumerable<UserModel> GetAll(); | |
UserModel Add(UserModel user); | |
} | |
} |
This file contains 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; | |
namespace angular_dotnet_example.Models | |
{ | |
public class UserRepository: IUserRepository | |
{ | |
private List<UserModel> users = new List<UserModel>(); | |
private int _nextId = 1; | |
public UserRepository() | |
{ | |
Add(new UserModel { firstName= "first1", lastName="last1", email="email1@gmail.com"}); | |
Add(new UserModel { firstName= "first2", lastName="last2", email="email2@gmail.com"}); | |
Add(new UserModel { firstName= "first3", lastName="last3", email="email3@gmail.com"}); | |
} | |
public IEnumerable<UserModel> GetAll() | |
{ | |
return users; | |
} | |
public UserModel Add(UserModel item) | |
{ | |
if (item == null) | |
{ | |
throw new ArgumentNullException("item"); | |
} | |
item.Id = _nextId++; | |
users.Add(item); | |
return item; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment