/// <summary>
        /// Groups the project parameters by project dictionary.
        /// </summary>
        /// <param name="projectParameterFields">The project parameter fields.</param>
        /// <returns>Dictionary with projects grouped by project id.</returns>
        private Dictionary <int, ProjectViewModel> GroupProjectParametersByProjectDictionary(
            SpeciesObservationFieldDescriptionList projectParameterFields)
        {
            Dictionary <int, ProjectViewModel> projectsDictionary = new Dictionary <int, ProjectViewModel>();

            if (projectParameterFields == null)
            {
                return(null);
            }

            var projectParametersDictionary = new Dictionary <int, List <Tuple <ISpeciesObservationFieldDescription, ISpeciesObservationFieldMapping> > >();
            var projectSet = new HashSet <ProjectViewModel>();

            foreach (var projectParameter in projectParameterFields)
            {
                foreach (ISpeciesObservationFieldMapping mapping in projectParameter.Mappings)
                {
                    if (mapping.ProjectId.HasValue)
                    {
                        if (!projectParametersDictionary.ContainsKey(mapping.ProjectId.Value))
                        {
                            projectParametersDictionary.Add(mapping.ProjectId.Value, new List <Tuple <ISpeciesObservationFieldDescription, ISpeciesObservationFieldMapping> >());
                            ProjectViewModel project = new ProjectViewModel
                            {
                                Name = mapping.ProjectName,
                                Id   = mapping.ProjectId.Value
                            };
                            projectSet.Add(project);
                        }
                        projectParametersDictionary[mapping.ProjectId.Value].Add(
                            new Tuple <ISpeciesObservationFieldDescription, ISpeciesObservationFieldMapping>(projectParameter, mapping));
                    }
                }
            }

            foreach (var projectViewModel in projectSet)
            {
                var projectParameterDescriptions = projectParametersDictionary[projectViewModel.Id];
                projectViewModel.ProjectParameters = new Dictionary <string, ProjectParameterObservationDetailFieldViewModel>(projectParameterDescriptions.Count);
                foreach (var fieldDescription in projectParameterDescriptions)
                {
                    var projectParameter = ProjectParameterObservationDetailFieldViewModel.Create(
                        fieldDescription.Item1,  //ISpeciesObservationFieldDescription
                        fieldDescription.Item2); // ISpeciesObservationFieldMapping

                    projectViewModel.ProjectParameters.Add(projectParameter.PropertyIdentifier, projectParameter);
                }

                // Order project parameters by its label
                projectViewModel.ProjectParameters =
                    projectViewModel.ProjectParameters.OrderBy(x => x.Value.Label).ToDictionary(x => x.Key, x => x.Value);

                projectsDictionary.Add(projectViewModel.Id, projectViewModel);
            }

            return(projectsDictionary);
        }
        private static ProjectViewModel CreateProjectViewModel(KeyValuePair <int, List <ISpeciesObservationProjectParameter> > pair)
        {
            var projectViewModel      = new ProjectViewModel();
            var firstProjectParameter = pair.Value.First();

            projectViewModel.Name = firstProjectParameter.ProjectName;
            projectViewModel.Id   = firstProjectParameter.ProjectId;
            projectViewModel.Guid = firstProjectParameter.Guid;
            projectViewModel.ProjectParameters = new Dictionary <string, ProjectParameterObservationDetailFieldViewModel>();

            foreach (var projectParameter in pair.Value)
            {
                var field = ProjectParameterObservationDetailFieldViewModel.Create(projectParameter);
                projectViewModel.ProjectParameters.Add(field.PropertyIdentifier, field);
            }

            return(projectViewModel);
        }