I'm adding the ability to select a language for a user and a company in an existing Entity Framework code first application, and I'm not quite sure how to best go about it.
This is an example of the kind of scenario I want:
All available languages in the system: English, German, French, Spanish, Portuguese, Italian, Dutch, Danish, Swedish and Norwegian
Company A: English, German and French are available, English is default.
Company B: Spanish, Portuguese, Italian and English are available, Italian is default.
User X: Belongs to Company A, so English, German and French are available. When the user was created English was set to their selected language (as it's the default language for the company), but the user has selected French as their selected language instead.
User Y: Does not belong to any company. English and French are available, English is selected.
I've created the entities like this (additional properties removed for brevity):
public class Language
{
[Key]
public Guid Id { get; set; }
public string LanguageCode { get; set; }
public string Name { get; set; }
}
public class Company
{
public ICollection<Language> AvailableLanguages { get; set; }
public Language DefaultLanguage { get; set; }
}
public class User
{
public ICollection<Language> AvailableLanguages { get; set; }
public Language SelectedLanguage { get; set; }
}
This gives me a Languages table containing Id, LanguageCode, Name, CompanyId and UserId, which is fine for mapping companies and users to languages, but it doesn't give me anywhere to store the master list of languages. Do I need to create a separate entity for this to work, or what would be the best way to achieve this?