public async Task <SpecificationViewModel> GetSpecificationViewModel(int specificationId) { var specification = await _specificationService.FindSpecificationAsync(specificationId); if (specification == null) { return(null); } var viewModel = _mapper.Map <Specification, SpecificationViewModel>(specification); var categories = await _categoryService.GetCategoriesAsync(); viewModel.CategorySelectItems = categories.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = specification.SpecificationCategories .Any(sv => sv.CategoryId == x.Id) }).ToList(); var videoSources = await _videoSourceService.GetVideoSourcesAsync(); viewModel.VideoSourceSelectItems = videoSources.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = specification.SpecificationVideoSources .Any(sv => sv.VideoSourceId == x.Id) }).ToList(); var articleSources = await _articleSourceService.GetArticleSourcesAsync(); viewModel.ArticleSourceSelectItems = articleSources.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = specification.SpecificationArticleSources .Any(sa => sa.ArticleSourceId == x.Id) }).ToList(); return(viewModel); }