示例#1
0
        private void UpdateProfileByToken(Person person, MacUrlAuthenticationProvider provider, List <dtoMacUrlUserAttribute> attributes)
        {
            List <UserProfileAttribute> pAttributes = provider.Attributes.Where(p => p.Deleted == BaseStatusDeleted.None && p.GetType() == typeof(UserProfileAttribute)).Select(p => (UserProfileAttribute)p).ToList();
            Int32 idDefaultType = 0;
            List <OrganizationAttributeItem> items = provider.GetOrganizationsInfo(attributes);

            UpdateOrganizationAssociations(person, provider, attributes);
            Dictionary <ProfileAttributeType, string> agencyAttributes = Helper.GetUserAttributesForAgency(provider, attributes);

            if (items.Count == 1)
            {
                idDefaultType = items[0].IdDefaultProfile;
                if (idDefaultType != person.TypeID)
                {
                    CurrentManager.Detach(person);
                    EditProfileType(person.Id, idDefaultType, items[0].Organization.Id, provider, pAttributes, attributes);
                }
                else if (agencyAttributes.Count > 0 && person.TypeID == (int)UserTypeStandard.Employee)
                {
                    Employee emp       = (Employee)person;
                    Agency   empAgency = Helper.GetAgencyByAttributes(person.Id, items[0].Organization.Id, provider, attributes);
                    if (emp.CurrentAffiliation == null || (empAgency != null && emp.CurrentAffiliation.Agency.Id != empAgency.Id))
                    {
                        UpdateAgencyAssocation(person.Id, empAgency);
                    }
                }
            }
            else if (items.Count > 0 && agencyAttributes.Count > 0 && person.TypeID != (int)UserTypeStandard.Employee)
            {
                idDefaultType = (int)UserTypeStandard.Employee;
                CurrentManager.Detach(person);
                EditProfileType(person.Id, idDefaultType, items[0].Organization.Id, provider, pAttributes, attributes);
            }
            else if (items.Count > 0 && agencyAttributes.Count > 0 && person.TypeID == (int)UserTypeStandard.Employee)
            {
                Employee emp       = (Employee)person;
                Agency   empAgency = Helper.GetAgencyByAttributes(emp.Id, items[0].Organization.Id, provider, attributes);
                if (emp.CurrentAffiliation == null || (empAgency != null && emp.CurrentAffiliation.Agency.Id != empAgency.Id))
                {
                    UpdateAgencyAssocation(person.Id, empAgency);
                }
            }
            if (provider.HasCatalogues())
            {
                UrlService.UpdateCatalogueAssocation(person.Id, provider, attributes);
            }
        }
示例#2
0
        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);
        }