Пример #1
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);
        }