public Profile WithUniqueName(Profile profile) { if (profile == null) { return(null); } using (var cached = _cachedProfiles.ProfileData()) { var local = cached.Local.Where(x => x.Status != ProfileStatus.Deleted).ToList(); var sync = cached.Local.Where(x => x.Status != ProfileStatus.Deleted).ToList(); var p = profile.WithUniqueNameCandidate(_appConfig.MaxProfileNameLength); while (ContainsOtherWithSameName(local, p) || ContainsOtherWithSameName(sync, p) || ContainsOtherWithSameName(cached.External, p)) { p = p.WithNextUniqueNameCandidate(_appConfig.MaxProfileNameLength); } return(p); } }
public static Profile WithNextUniqueNameCandidate(this Profile profile, int maxLength) { profile.UniqueNameIndex++; return(profile.WithUniqueNameCandidate(maxLength)); }