private dtoExternal CreateExternal(ProfileAttributesRow row) { dtoExternal item = new dtoExternal(); item.ExternalUserInfo = row.GetCellValue(ProfileAttributeType.externalUserInfo); return(item); }
public dtoBaseProfile GetProfileData(MacUrlAuthenticationProvider provider, List <UserProfileAttribute> pAttributes, List <dtoMacUrlUserAttribute> attributes, Int32 idOrganization, Int32 idProfileType) { dtoBaseProfile profile = new dtoBaseProfile(); String pwd = lm.Comol.Core.DomainModel.Helpers.RandomKeyGenerator.GenerateRandomKey(6, 10, true, true, false); Language language = GetUserLanguage(provider.GetAttributeValue(ProfileAttributeType.language, pAttributes, attributes)); switch (idProfileType) { case (int)UserTypeStandard.ExternalUser: profile = new dtoExternal(); break; case (int)UserTypeStandard.Company: profile = new dtoCompany(); break; case (int)UserTypeStandard.Employee: profile = new dtoEmployee(); break; default: profile = new dtoBaseProfile(); break; } profile.Login = provider.GetAttributeValue(ProfileAttributeType.login, pAttributes, attributes); if (String.IsNullOrEmpty(profile.Login)) { profile.Login = provider.GetAttributeValue(ProfileAttributeType.externalId, attributes); } profile.Name = provider.GetAttributeValue(ProfileAttributeType.name, pAttributes, attributes); profile.Surname = provider.GetAttributeValue(ProfileAttributeType.surname, pAttributes, attributes); profile.TaxCode = provider.GetAttributeValue(ProfileAttributeType.taxCode, pAttributes, attributes); if (String.IsNullOrEmpty(profile.TaxCode)) { profile.TaxCode = UrlService.GenerateRandomTaxCode(); } profile.Mail = provider.GetAttributeValue(ProfileAttributeType.mail, pAttributes, attributes); if (String.IsNullOrEmpty(profile.Mail)) { profile.Mail = profile.Login + "@invalid.invalid.it"; } //if (!String.IsNullOrEmpty(profile.Mail)) // profile.Mail = profile.Mail.ToLower(); profile.Password = pwd; profile.ShowMail = false; if (!String.IsNullOrEmpty(profile.Surname)) { profile.FirstLetter = profile.Surname[0].ToString().ToLower(); } profile.IdProfileType = idProfileType; profile.AuthenticationProvider = provider.ProviderType; profile.IdLanguage = language.Id; profile.LanguageName = language.Name; switch (idProfileType) { case (int)UserTypeStandard.Company: dtoCompany dCompany = (dtoCompany)profile; dCompany.Info.Address = provider.GetAttributeValue(ProfileAttributeType.companyAddress, pAttributes, attributes); dCompany.Info.City = provider.GetAttributeValue(ProfileAttributeType.companyCity, pAttributes, attributes); dCompany.Info.Name = provider.GetAttributeValue(ProfileAttributeType.companyName, pAttributes, attributes); dCompany.Info.Region = provider.GetAttributeValue(ProfileAttributeType.companyRegion, pAttributes, attributes); dCompany.Info.TaxCode = provider.GetAttributeValue(ProfileAttributeType.companyTaxCode, pAttributes, attributes); dCompany.Info.ReaNumber = provider.GetAttributeValue(ProfileAttributeType.companyReaNumber, pAttributes, attributes); dCompany.Info.AssociationCategories = provider.GetAttributeValue(ProfileAttributeType.companyAssociations, pAttributes, attributes); return(dCompany); case (int)UserTypeStandard.Employee: dtoEmployee dEmployee = (dtoEmployee)profile; Person anonymous = ProfileService.GetAnonymousUser(); Agency agency = null; if (anonymous == null) { Dictionary <ProfileAttributeType, string> agencyAttributes = GetUserAttributesForAgency(provider, attributes); agency = ProfileService.GetAgency(agencyAttributes); if (agency == null) { agency = ProfileService.GetDefaultAgency(idOrganization); } } else { agency = GetAgencyByAttributes(anonymous.Id, idOrganization, provider, attributes); } if (agency != null) { dEmployee.CurrentAgency = new KeyValuePair <long, string>(agency.Id, agency.Name); } else { dEmployee.CurrentAgency = ProfileService.GetEmptyAgency(idOrganization); } return(dEmployee); case (int)UserTypeStandard.ExternalUser: dtoExternal dExternal = (dtoExternal)profile; dExternal.ExternalUserInfo = provider.GetAttributeValue(ProfileAttributeType.externalUserInfo, pAttributes, attributes); return(dExternal); default: return(profile); } }
private List <Person> CreateProfiles(dtoImportSettings settings, Int32 idDefaultOrganization, ProfileExternalResource selectedItems, List <dtoImportedProfile> createdProfiles, List <dtoBaseProfile> notCreatedProfiles) { List <Person> profiles = new List <Person>(); Language language = CurrentManager.GetDefaultLanguage(); AuthenticationProvider provider = Service.GetAuthenticationProvider(settings.IdProvider); if (provider != null && language != null) { Boolean created = false; Int32 idPerson = 0; Int32 index = 1; foreach (ProfileAttributesRow row in selectedItems.Rows) { dtoBaseProfile baseItem = null; switch (settings.IdProfileType) { case (int)UserTypeStandard.ExternalUser: dtoExternal externalUser = CreateExternal(row); baseItem = externalUser; break; case (int)UserTypeStandard.Company: dtoCompany company = CreateCompanyUser(row); baseItem = company; break; case (int)UserTypeStandard.Employee: dtoEmployee employee = CreateEmployee(row); baseItem = employee; break; default: baseItem = new dtoBaseProfile(); break; } created = false; if (baseItem != null) { GenerateBaseProfile(baseItem, settings, row, provider.ProviderType, GetUserLanguage(row, language)); if (InternalService.isUniqueMail(baseItem.Mail)) { PersonInfo info = GeneratePersonInfo(row, baseItem); idPerson = View.AddUserProfile(baseItem, info, idDefaultOrganization, provider); if (idPerson > 0) { Person person = CurrentManager.GetPerson(idPerson); if (person != null) { created = AddAuthentication(person, baseItem, settings, row, provider); if (created) { Service.SetDefaultProvider(provider.Id, person.Id); } profiles.Add(person); createdProfiles.Add(new dtoImportedProfile() { Profile = baseItem, Info = info }); } } } if (!created) { notCreatedProfiles.Add(baseItem); } View.UpdateProfileCreation(0, index, created, baseItem.DisplayName); } else { View.UpdateProfileCreation(0, index, created, " // "); } index++; } } return(profiles); }