public IEnumerable <WorkshopViewModel> GetBySlug(IEnumerable <string> ids) { using (var scope = _dbContextScope.CreateReadOnly()) { //TODO: bullshit code, needs refactoring - //root cause: need to merge categories from 2 contexts var workshops = _workshopRepo.GetBySlug(ids).ToList(); if (workshops.Any()) { var dbCategories = workshops.Select(x => { var workshopCategories = x.WorkshopCategories.Select(y => y.CategoryID); return(categoryRepo.Get(workshopCategories)); }).ToList(); if (dbCategories.Count != 0) { for (var i = 0; i < dbCategories.Count; i++) { var wCategories = workshops[i].WorkshopCategories.ToList(); var index = 0; foreach (var c in dbCategories[i]) { wCategories[index++].Category = c; } } } } return(Mapper.Map <IEnumerable <WorkshopViewModel> >(workshops)); } }