Exemplo n.º 1
0
        public List <SpecificationsModel> GetSpecificationsByProductId(int productId)
        {
            var prodCatSpecList = prod_catSpecsRepo.GetProd_CatSpecsByProductId(productId);

            var catSpecList = catSpecRepo.GetAllByIds(prodCatSpecList.Select(x => x.CategorySpecsId));

            var        specIds    = catSpecList.Select(x => x.SpecId);
            List <int> specIntIds = new List <int>();

            foreach (var s in specIds)
            {
                specIntIds.Add(s);
            }
            var specList = specsRepo.ReadByIds(specIntIds);


            var joinedSpecList = from prodCatSpec in prodCatSpecList
                                 join catspec in catSpecList
                                 on prodCatSpec.CategorySpecsId equals catspec.CategorySpecsId
                                 join spec in specList
                                 on catspec.SpecId equals spec.SpecId
                                 into Specs
                                 from Spec in Specs.DefaultIfEmpty()
                                 select new
            {
                prodCatSpec,
                catspec,
                Spec
            };

            var specModelList = new List <SpecificationsModel>();

            foreach (var item in joinedSpecList)
            {
                specModelList.Add(new SpecificationsModel
                {
                    SpecId         = item.Spec.SpecId,
                    Name           = item.Spec.Name,
                    CategorySpecId = item.catspec.CategorySpecsId,
                    Prod_CatSpecId = item.prodCatSpec.Prod_CatSpecId,
                    Value          = item.prodCatSpec.SpecValue
                });
            }

            return(specModelList);
        }