public IActionResult Load(long?ID, long?CategoryID, long?ProductID, long?ProductDetailID, long?CategoryLevel, long?LineOfBusniess, long?SubLineOfBusniess, long?langId) { GetProductCategory operation = new GetProductCategory(); operation.ID = ID; operation.ProductID = ProductID; operation.CategoryID = CategoryID; operation.ProductDetailID = ProductDetailID; operation.CategoryLevel = CategoryLevel; operation.LineOfBusniess = LineOfBusniess; operation.SubLineOfBusniess = SubLineOfBusniess; if (langId.HasValue) { operation.LangID = langId; } else { operation.LangID = 1; } var result = operation.QueryAsync().Result; if (result is ValidationsOutput) { return(Ok(new ApiResult <List <ValidationItem> >() { Data = ((ValidationsOutput)result).Errors })); } else { return(Ok((List <ProductCategory>)result)); } }
public IActionResult LoadUnRelatedCategory(long?ID, long?CategoryID, long?ProductID, long?ProductDetailID, long?CategoryLevel, long?LineOfBusniess, long?SubLineOfBusniess, long?langId) { GetProductCategory operation = new GetProductCategory(); GetCategories operation2 = new GetCategories(); operation.ID = ID; operation.ProductID = ProductID; operation.CategoryID = CategoryID; operation.ProductDetailID = ProductDetailID; operation.CategoryLevel = CategoryLevel; operation.LineOfBusniess = LineOfBusniess; operation.SubLineOfBusniess = SubLineOfBusniess; operation2.LineOfBusniess = LineOfBusniess; operation2.SubLineOfBusniess = SubLineOfBusniess; operation2.CategoryLevel = CategoryLevel; if (langId.HasValue) { operation.LangID = langId; operation2.LangID = langId; } else { operation.LangID = 1; operation2.LangID = 1; } var result = operation.QueryAsync().Result; var productCategories = (List <ProductCategory>)result; var categories = (List <Category>)operation2.QueryAsync().Result; List <ProductCategory> RelatedCategories = new List <ProductCategory>(); List <Category> UnRelatedCategories = new List <Category>(); if (productCategories.Count > 0) { RelatedCategories = productCategories.Where(p => categories.Any(s => s.ID == p.CategoryID && (s.SubLineOfBusniess == SubLineOfBusniess || s.SubLineOfBusniess == null))).ToList(); UnRelatedCategories = categories.Where(s => productCategories.Any(p => p.CategoryID != s.ID && (s.SubLineOfBusniess == SubLineOfBusniess || s.SubLineOfBusniess == null))).ToList(); UnRelatedCategories = UnRelatedCategories.Where(un => !RelatedCategories.Exists(re => un.ID == re.CategoryID)).ToList(); } else { UnRelatedCategories = categories.Where(s => s.SubLineOfBusniess == SubLineOfBusniess || s.SubLineOfBusniess == null).ToList(); } if (result is ValidationsOutput) { return(Ok(new ApiResult <List <ValidationItem> >() { Data = ((ValidationsOutput)result).Errors })); } else { return(Ok(new { UnRelatedCategories, RelatedCategories })); } }