示例#1
0
        public AjaxResult SaveDesiredJobDetails(string desiredJobTitle,
                                                string desiredSalaryLower, string desiredSalaryUpper,
                                                string desiredSalaryLabel, int desiredJobTypes,
                                                string desiredJobTypesLabel, bool emailSuggestedJobs,
                                                string desiredLocalitiesLabel,
                                                string relocationChoiceLabel,
                                                string relPref,
                                                string selectedLocalities)
        {
            var errorMessages = new List <string>();

            RelocationPreference relocationPreference = RelocationPreference.No;

            try
            {
                relocationPreference = (RelocationPreference)Enum.Parse(typeof(RelocationPreference), relPref);
            }
            catch (ArgumentException)
            {
                errorMessages.Add(NoRelocationPreferenceSpecified);
            }

            if (errorMessages.Count != 0)
            {
                return(new AjaxResult(AjaxResultCode.FAILURE, ConvertMessagesToString(errorMessages)));
            }

            try
            {
                EnsureMemberLoggedIn();

                var member         = LoggedInMember;
                var localitiesText = String.Empty;

                var candidate     = _candidatesCommand.GetCandidate(member.Id);
                var desiredSalary = SalaryExtensions.Parse(desiredSalaryLower, desiredSalaryUpper, SalaryRate.Year, true);

                // Update.

                candidate.DesiredJobTitle      = desiredJobTitle;
                candidate.DesiredJobTypes      = (JobTypes)desiredJobTypes;
                candidate.DesiredSalary        = desiredSalary;
                candidate.RelocationPreference = relocationPreference;
                candidate.RelocationLocations  = WillingnessToRelocate.GetSelectedLocations(candidate, selectedLocalities);
                _candidatesCommand.UpdateCandidate(candidate);

                if (candidate.RelocationPreference != RelocationPreference.No)
                {
                    localitiesText = TextUtil.TruncateForDisplay(candidate.GetRelocationsDisplayText(), DesiredJob.MaxRelocationLocalitiesLength);
                }

                var relocationPreferenceText = DesiredJob.GetRelocationPreference(candidate.RelocationPreference);

                UpdateSuggestedJobs(member.Id, emailSuggestedJobs);

                var userData = new ElementValuesUserData(
                    new[]
                {
                    desiredSalaryLabel,
                    desiredJobTypesLabel,
                    desiredLocalitiesLabel,
                    relocationChoiceLabel
                },
                    new[]
                {
                    candidate.DesiredSalary == null ? string.Empty : candidate.DesiredSalary.GetDisplayText(),
                    candidate.DesiredJobTypes.GetDesiredClauseDisplayText(),
                    localitiesText, relocationPreferenceText
                });

                return(new AjaxResult(AjaxResultCode.SUCCESS, null, userData));
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
示例#2
0
        public AjaxResult SaveProfileDetails(string firstName, string lastName,
                                             string gender, int day, int month, string year, string countryStr, string location, int ethnicStatus,
                                             string ageControlName, string ethnicStatusControlName)
        {
            try
            {
                EnsureMemberLoggedIn();

                var errors = new List <string>();

                if (string.IsNullOrEmpty(firstName))
                {
                    errors.Add(ValidationErrorMessages.REQUIRED_FIELD_FIRST_NAME);
                }

                if (string.IsNullOrEmpty(lastName))
                {
                    errors.Add(ValidationErrorMessages.REQUIRED_FIELD_LAST_NAME);
                }

                PartialDate?dateOfBirth = null;
                if (day != 0 && month != 0 && !string.IsNullOrEmpty(year))
                {
                    try
                    {
                        dateOfBirth = new PartialDate(ParseUtil.ParseUserInputInt32(year, "year of birth"), month, day);
                    }
                    catch (ArgumentException)
                    {
                        errors.Add(ValidationErrorMessages.INVALID_DATE_OF_BIRTH);
                    }
                    catch (UserException ex)
                    {
                        errors.Add(ex.Message);
                    }
                }
                else if (day != 0 || month != 0 || !string.IsNullOrEmpty(year))
                {
                    errors.Add(ValidationErrorMessages.INCOMPLETE_DATE_OF_BIRTH);
                }

                Country country = null;
                if (string.IsNullOrEmpty(countryStr))
                {
                    errors.Add(ValidationErrorMessages.REQUIRED_FIELD_COUNTRY);
                }
                else
                {
                    country = _locationQuery.GetCountry(countryStr);
                    if (country == null)
                    {
                        errors.Add(ValidationErrorMessages.INVALID_COUNTRY);
                    }
                }

                if (string.IsNullOrEmpty(location))
                {
                    errors.Add(ValidationErrorMessages.REQUIRED_FIELD_SUBURB);
                }

                if (errors.Count > 0)
                {
                    return(new AjaxResult(AjaxResultCode.FAILURE, errors.ToArray()));
                }

                var member = LoggedInMember;
                member.FirstName        = firstName;
                member.LastName         = lastName;
                member.Address.Location = _locationQuery.ResolveLocation(country, location);
                member.DateOfBirth      = dateOfBirth;
                member.Gender           = GetGender(member, gender);
                member.EthnicStatus     = (EthnicStatus)ethnicStatus;
                _memberAccountsCommand.UpdateMember(member);

                _authenticationManager.UpdateUser(new HttpContextWrapper(HttpContext.Current), member, false);

                var ageValue          = member.DateOfBirth.GetAgeDisplayText();
                var ethnicStatusValue = NetworkerFacade.GetEthnicStatusText(member, true);

                var userData = new ElementValuesUserData(
                    new[] { ageControlName, ethnicStatusControlName },
                    new[] { ageValue, ethnicStatusValue });

                return(new AjaxResult(AjaxResultCode.SUCCESS, null, userData));
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }