public Boolean SaveData() { Boolean result = false; if (View.IdProfileType == (int)UserTypeStandard.Company) { dtoCompany company = (dtoCompany)View.CurrentProfile; PersonInfo userInfo = View.ProfilePersonalData; result = (Service.SaveCompanyUser(company, userInfo) != null); } else if (View.IdProfileType == (int)UserTypeStandard.Employee) { dtoEmployee employee = (dtoEmployee)View.CurrentProfile; PersonInfo userInfo = View.ProfilePersonalData; Employee savedEmployee = Service.SaveEmployee(employee, userInfo); if (savedEmployee != null && employee.CurrentAgency.Key > 0) { SaveAgencyAffiliation(employee.CurrentAgency.Key, employee.Id); } result = (savedEmployee != null); } else { result = View.SaveProfile(View.CurrentProfile, View.ProfilePersonalData); if (result == true) { Service.UpdateFirstLetter(View.IdProfile); } } return(result); }
public dtoBaseProfile GetCurrentProfileData(Int32 idProfile, Int32 idProfileType, AuthenticationProviderType type, dtoBaseProfile oldProfile) { dtoBaseProfile profile = new dtoBaseProfile(); Person person = CurrentManager.GetPerson(idProfile); if (person != null) { Language language = CurrentManager.GetLanguage(person.LanguageID); switch (idProfileType) { case (int)UserTypeStandard.Company: profile = new dtoCompany(CurrentManager.Get <CompanyUser>(idProfile)); break; case (int)UserTypeStandard.Employee: profile = new dtoEmployee(CurrentManager.Get <Employee>(idProfile)); break; default: profile = oldProfile; break; } profile.IdProfileType = idProfileType; profile.AuthenticationProvider = type; profile.IdLanguage = language.Id; profile.LanguageName = language.Name; } return(profile); }
private dtoCompany CreateCompanyUser(ProfileAttributesRow row) { dtoCompany item = new dtoCompany(); item.Info.Name = row.GetCellValue(ProfileAttributeType.companyName); item.Info.Address = row.GetCellValue(ProfileAttributeType.companyAddress); item.Info.City = row.GetCellValue(ProfileAttributeType.companyCity); item.Info.Region = row.GetCellValue(ProfileAttributeType.companyRegion); item.Info.TaxCode = row.GetCellValue(ProfileAttributeType.companyTaxCode); item.Info.ReaNumber = row.GetCellValue(ProfileAttributeType.companyReaNumber); item.Info.AssociationCategories = row.GetCellValue(ProfileAttributeType.companyAssociations); return(item); }
public Boolean EditProfileType(Int32 IdNewType) { Boolean result = false; Int32 IdProfile = View.IdProfile; ProfileTypeChanger person = CurrentManager.Get <ProfileTypeChanger>(IdProfile); Int32 oldIdType = person.TypeID; if (IdProfile > 0 && person != null) { if (person.TypeID == (int)UserTypeStandard.Company && IdNewType != (int)UserTypeStandard.Company) { person = Service.EditProfileType(person, IdNewType); } else if (IdNewType == (int)UserTypeStandard.Company) { person = Service.EditProfileType(person, IdNewType); } else if (person.TypeID == (int)UserTypeStandard.Employee && IdNewType != (int)UserTypeStandard.Employee) { person = Service.EditProfileType(person, IdNewType); } else if (IdNewType == (int)UserTypeStandard.Employee) { person = Service.EditProfileType(person, IdNewType); } if (oldIdType != IdNewType) { if (IdNewType == (int)UserTypeStandard.Company) { dtoCompany company = (dtoCompany)View.CurrentProfile; if (oldIdType == (int)UserTypeStandard.Employee || View.DeletePreviousProfileType(IdProfile, oldIdType, IdNewType)) { result = (Service.SaveCompanyUser(company, null) != null); } } else if (IdNewType == (int)UserTypeStandard.Employee) { dtoEmployee employee = (dtoEmployee)View.CurrentProfile; if (oldIdType == (int)UserTypeStandard.Company || View.DeletePreviousProfileType(IdProfile, oldIdType, IdNewType)) { Employee savedEmployee = Service.SaveEmployee(employee, null); if (savedEmployee != null) { long idAgency = employee.CurrentAgency.Key; if (idAgency < 1) { idAgency = Service.GetEmptyAgency(0).Key; } SaveAgencyAffiliation(employee.CurrentAgency.Key, IdProfile); } result = (savedEmployee != null); } } else { result = View.EditProfileType(View.CurrentProfile, oldIdType, IdNewType); if (result == true) { Service.UpdateFirstLetter(IdProfile); } } if (result && oldIdType == (int)UserTypeStandard.Employee) { Service.CloseEmployeeAffiliations(IdProfile); } } } return(result); }
private Boolean EditProfileType(Int32 idProfile, Int32 idNewType, Int32 idOrganization, MacUrlAuthenticationProvider provider, List <UserProfileAttribute> pAttributes, List <dtoMacUrlUserAttribute> attributes) { Boolean result = false; ProfileTypeChanger person = CurrentManager.Get <ProfileTypeChanger>(idProfile); Int32 idOldType = person.TypeID; dtoBaseProfile profile = GetCurrentProfileData(idProfile, idOldType, provider.ProviderType); if (idProfile > 0 && person != null) { Person people = CurrentManager.GetPerson(idProfile); if (people != null) { CurrentManager.Detach(people); } if (person.TypeID == (int)UserTypeStandard.Company && idNewType != (int)UserTypeStandard.Company) { person = ProfileService.EditProfileType(person, idNewType); } else if (idNewType == (int)UserTypeStandard.Company) { person = ProfileService.EditProfileType(person, idNewType); } else if (person.TypeID == (int)UserTypeStandard.Employee && idNewType != (int)UserTypeStandard.Employee) { person = ProfileService.EditProfileType(person, idNewType); } else if (idNewType == (int)UserTypeStandard.Employee) { person = ProfileService.EditProfileType(person, idNewType); } if (idOldType != idNewType && person != null) { if (idNewType == (int)UserTypeStandard.Company) { dtoCompany company = (dtoCompany)Helper.GetProfileData(profile, provider, pAttributes, attributes, idOrganization, idNewType); if (idOldType == (int)UserTypeStandard.Employee || View.DeletePreviousProfileType(idProfile, idOldType, idNewType)) { result = (ProfileService.SaveCompanyUser(company, null) != null); } } else if (idNewType == (int)UserTypeStandard.Employee) { dtoEmployee employee = (dtoEmployee)Helper.GetProfileData(profile, provider, pAttributes, attributes, idOrganization, idNewType); if (idOldType == (int)UserTypeStandard.Company || View.DeletePreviousProfileType(idProfile, idOldType, idNewType)) { Employee savedEmployee = ProfileService.SaveEmployee(employee, null); if (savedEmployee != null) { //long idAgency = employee.CurrentAgency.Key; //if (idAgency < 1) // idAgency = ProfileService.GetEmptyAgency(0).Key; //SaveAgencyAffiliation(employee.CurrentAgency.Key, IdProfile); UpdateAgencyAssocation(idProfile, idOrganization, provider, attributes); } result = (savedEmployee != null); } } else { result = View.EditProfileType(idProfile, Helper.GetProfileData(profile, provider, pAttributes, attributes, idOrganization, idNewType), idOldType, idNewType); } if (result && idOldType == (int)UserTypeStandard.Employee) { ProfileService.CloseEmployeeAffiliations(idProfile); } } } return(result); }
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 String AnalyzeBody(String body, dtoImportedProfile dto, List <ProfileAttributeType> attributes) { String result = body; foreach (ProfileAttributeType attribute in attributes) { String search = "[" + attribute.ToString() + "]"; switch (attribute) { case ProfileAttributeType.name: result = result.Replace(search, dto.Profile.Name); break; case ProfileAttributeType.surname: result = result.Replace(search, dto.Profile.Surname); break; case ProfileAttributeType.mail: result = result.Replace(search, dto.Profile.Mail); break; case ProfileAttributeType.password: result = result.Replace(search, dto.Profile.Password); break; case ProfileAttributeType.taxCode: result = result.Replace(search, dto.Profile.TaxCode); break; case ProfileAttributeType.autoGeneratedLogin: result = result.Replace("[" + ProfileAttributeType.login.ToString() + "]", dto.Profile.Login); result = result.Replace("[" + ProfileAttributeType.autoGeneratedLogin.ToString() + "]", dto.Profile.Login); break; case ProfileAttributeType.login: result = result.Replace("[" + ProfileAttributeType.login.ToString() + "]", dto.Profile.Login); result = result.Replace("[" + ProfileAttributeType.autoGeneratedLogin.ToString() + "]", dto.Profile.Login); break; case ProfileAttributeType.externalUserInfo: if (typeof(dtoExternal) == dto.Profile.GetType()) { result = result.Replace(search, ((dtoExternal)dto.Profile).ExternalUserInfo); } else { result = result.Replace(search, ""); } break; case ProfileAttributeType.address: result = result.Replace(search, dto.Info.Address); break; case ProfileAttributeType.city: result = result.Replace(search, dto.Info.City); break; case ProfileAttributeType.fax: result = result.Replace(search, dto.Info.Fax); break; case ProfileAttributeType.mobile: result = result.Replace(search, dto.Info.Mobile); break; case ProfileAttributeType.zipCode: result = result.Replace(search, dto.Info.PostCode); break; case ProfileAttributeType.telephoneNumber: result = result.Replace(search, dto.Info.OfficePhone); break; case ProfileAttributeType.language: result = result.Replace(search, dto.Profile.LanguageName); break; } } if (typeof(dtoCompany) == dto.Profile.GetType()) { dtoCompany company = (dtoCompany)dto.Profile; result = result.Replace("[" + ProfileAttributeType.companyCity.ToString() + "]", company.Info.City); result = result.Replace("[" + ProfileAttributeType.companyName.ToString() + "]", company.Info.Name); result = result.Replace("[" + ProfileAttributeType.companyAddress.ToString() + "]", company.Info.Address); result = result.Replace("[" + ProfileAttributeType.companyRegion.ToString() + "]", company.Info.Region); result = result.Replace("[" + ProfileAttributeType.companyTaxCode.ToString() + "]", company.Info.TaxCode); } return(result); }
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); }