protected CategoryRepoAssociation EnsureEntity(CategoryRepoAssociation association) { if (association == null || (association.IDinRepo == null && association.Category == null)) { return(null); } association.Category = EnsureEntity(association.Category); if (association.Category == null) { association.Category = new Category(); } var keys = GetKeys(association); var rtv = association; foreach (var key in keys) { if (!_categoryRepoAssociations.TryGetValue(key, out rtv)) { _categoryRepoAssociations.Add(key, association); } } return(rtv); }
protected CategoryRepoAssociation EnsureEntity(CategoryRepoAssociation association) { if (association == null || (association.IDinRepo == null && association.Category == null)) { return(null); } association.Category = EnsureEntity(association.Category); if (association.Category == null) { association.Category = new Category(); } var keys = GetKeys(association); var rtv = association; foreach (var key in keys) { if (!_categoryRepoAssociations.TryGetValue(key, out rtv)) { _categoryRepoAssociations.Add(key, association); // This assignment is necessary because if `key` // does not exist in `_categoryRepoAssociations` then // rtv will be set to null. rtv = association; } } return(rtv); }
private List <string> GetKeys(CategoryRepoAssociation association) { var repo = association.Repository == null ? Repo.Name : association.Repository.Name; var id = association.IDinRepo ?? string.Empty; var name = association.Category == null ? string.Empty : association.Category.Name ?? string.Empty; if (string.IsNullOrWhiteSpace(id) && string.IsNullOrWhiteSpace(name)) { return(new List <string>()); } string a = null, b = null, c = null; a = string.Join("::", repo, id, name); if (!string.IsNullOrWhiteSpace(name)) { b = string.Join("::", repo, string.Empty, name); } if (!string.IsNullOrWhiteSpace(id)) { c = string.Join("::", repo, id, string.Empty); } var keys = new List <string> { a }; if (b != null && b != a) { keys.Add(b); } if (c != null && c != b && c != a) { keys.Add(c); } return(keys); }