Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining and implementation of PersonTypes #36

Open
marblekirby opened this issue Jul 17, 2019 · 0 comments
Open

Defining and implementation of PersonTypes #36

marblekirby opened this issue Jul 17, 2019 · 0 comments

Comments

@marblekirby
Copy link
Contributor

We should define a list of PersonTypes that will be in the system. If we are going to use these PersonTypes for authorization then I think we should implement an enum-like structure for our PersonType entity. We could define the types first then store them within the PersonType entity. This is an example with 'Volunteer', 'Employee' and 'Manager':

public class PersonType
{
	public static PersonType Volunteer = new PersonType(1, "Volunteer");
	public static PersonType Employee = new PersonType(2, "Employee");
	public static PersonType Manager = new PersonType(3, "Manager");

	public int Id { get; private set; }
	public string Name { get; private set; }
	public ICollection<PersonPersonType> PersonPersonTypes { get; set; }
	public PersonType(int id, string name)
	{
		this.Id = id;
		this.Name = name;
	}

	public List<PersonType> GetList()
	{
		return new List<PersonType> {
			Volunteer, Employee, Manager
	};
}

and then say we need to get all people that have the 'Manager' PersonType, we can use something like the following

_DbContext.Persons
    .Include(x => x.PersonPersonType)
    .ThenInclude(x => x.PersonType)
    .Where(x => x.PersonPersonType.Any(y => y.PersonTypeId == PersonType.Manager.Id));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant