Creating a service, Should I include my method in there.

I running into a pittfall I have an action that I'm trying to refactor so that it call a service that will populate a model that I created.

 My only issue is that I have a bunch of method that I'm not sure if they should belong to the service or I just should leave them on the controller level. My assumption is to not implement these method in my new service that I will create.  The methods that I'm referring to are as follow:
 PopulateSecurityParameters(parameters, viewModel);
  PopulateCancelSoldParameters(parameters, viewModel);
  PopulateCallLogParameters(parameters, viewModel);

[  private ViewModel GetViewModel(Employee employee)
        {
            var viewModel = new ViewModel();
            var parameters = ParameterConfigurationService.GetParameters();

            viewModel.CommonSmtpSettingsOptions = GetCommonSmtpSettingsOptions();

            viewModel.StatusInfoList = GetStatusInfoList(parameters);

            PopulateSecurityParameters(parameters, viewModel);
            PopulateCancelSoldParameters(parameters, viewModel);
            PopulateCallLogParameters(parameters, viewModel);
            PopulateGeneralParameters(parameters, viewModel);
            PopulateAppointmentCallParameters(parameters, viewModel);
            PopulateSmtpParameters(viewModel);

            viewModel.CountryOptions = GetViewModelCountryOptions(viewModel.SelectedCountry);
            viewModel.QuickNoteOptions = GetViewModelQuickNoteOptions(viewModel.SelectedQuickNote);

            return viewModel;
        }
/code]


 [code]  private List<Item> GetViewModelCountryOptions(char? selectedCountry)
        {
            var items = new List<Item>();
            var country = CountryCodes.Country.UnitedStates;
            items.Add(new Item
            {
                Text = country.GetText(),
                Value = country.GetCode().ToString(),
                IsSelected = selectedCountry == country.GetCode()
            });
            country = CountryCodes.Country.Canada;
            items.Add(new Item
            {
                Text = country.GetText(),
                Value = country.GetCode().ToString(),
                IsSelected = selectedCountry == country.GetCode()
            });
            country = CountryCodes.Country.UK;
            items.Add(new Item
            {
                Text = country.GetText(),
                Value = country.GetCode().ToString(),
                IsSelected = selectedCountry == country.GetCode()
            });
            country = CountryCodes.Country.Australia;
            items.Add(new Item
            {
                Text = country.GetText(),
                Value = country.GetCode().ToString(),
                IsSelected = selectedCountry == country.GetCode()
            });
            country = CountryCodes.Country.Ireland;
            items.Add(new Item
            {
                Text = country.GetText(),
                Value = country.GetCode().ToString(),
                IsSelected = selectedCountry == country.GetCode()
            });
            country = CountryCodes.Country.France;
            items.Add(new Item
            {
                Text = country.GetText(),
                Value = country.GetCode().ToString(),
                IsSelected = selectedCountry == country.GetCode()
            });

            return items;
        }

Open in new window

yguyon28Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
The Populate* methods belong to the same "level" as your ViewModel class. Cause they are coupled to it.

Patternwise they are part of the builder/factory (method) to create the ViewModel. So when you refactor it, create a builder or factory and place them there.

The only interesting point is your parameters service. This has a code smell. What are these parameters? Why are you using a service to get them? Are they configuration values or a kind of user context?
0
yguyon28Author Commented:
I would be using them in my service because they are configuration type files,
0
ste5anSenior DeveloperCommented:
hmm, did you want to write more?

Otherwise, I referred to your naming: ParameterConfigurationService.GetParameters();

Why is there a parameter service at all?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET MVC

From novice to tech pro — start learning today.