Skip to content

Instantly share code, notes, and snippets.

@bbachi
Created February 27, 2021 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbachi/d60b77c6a6daf55d8d038fd9a131e171 to your computer and use it in GitHub Desktop.
Save bbachi/d60b77c6a6daf55d8d038fd9a131e171 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
namespace angular_dotnet_example.Models
{
public interface IUserRepository
{
IEnumerable<UserModel> GetAll();
UserModel Add(UserModel user);
}
}
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