public string Get_Attributes_By_ProductType(int?product_Type_Id, int productId) { var request = new ProductType_Attribute_Get_By_ProductType_Id_Request { ProductType_Id = product_Type_Id ?? 0 }; var response = this._IProductType_Service.Get_ProductType_Attribute_By_ProductType_Id(request); var product_Atributes = productId > 0 ? this._IProductAttributeService.Get_ProductAttributes_By_ProductId(productId)?.Results : null; if (response != null && response.Results != null && response.Results.Count > 0) { var _listAtribute_Type = response.Results?.GroupBy(x => new { x.Attrtibute_Type, x.Attrtibute_TypeName }) .Select(o => new Get_ProductAttribute_Types_DTO { Type = o.Key.Attrtibute_Type, TypeName = o.Key.Attrtibute_TypeName, ProductAttributes = response.Results?.Where(p => p.Attrtibute_Type.Equals(o.Key.Attrtibute_Type)) .Select(p => new Get_ProductAttributes_DTO { Id = p.Attribute_Id, Name = p.Attrtibute_Name, Type = p.Attrtibute_Type, TypeName = p.Attrtibute_TypeName, Value = p.Attrtibute_Value, IsSelected = product_Atributes.Where(x => x.ProductAttributeId == p.Attribute_Id).Count() > 0 }).ToList() }).ToList(); string json = JsonConvert.SerializeObject(_listAtribute_Type); return(json); } else { return(string.Empty); } }
public ProductType_Attribute_Get_By_ProductType_Id_Response Get_ProductType_Attribute_By_ProductType_Id(ProductType_Attribute_Get_By_ProductType_Id_Request request) { var param = Mapper.Map <ProductType_Attribute_Get_By_ProductType_Id_Request, ProductType_Attribute_Get_By_ProductType_Id_Parameter>(request); var datas = _IProductType_AttributeRepository.ProductType_Attribute_Get_By_ProductType_Id(param); var retData = Mapper.Map <ResponseBase <List <ProductType_Attribute_Get_By_ProductType_Id> >, ProductType_Attribute_Get_By_ProductType_Id_Response>(datas); if (retData != null && retData.Results != null) { retData.StatusCode = (int)RESULT_STATUS_CODE.SUCCESS; } else { retData.StatusCode = (int)RESULT_STATUS_CODE.NODATA; } return(retData); }