कुछ समय से संघर्ष कर रहा है, तो
मैं वेबएपीआई दुनिया में अपने पैर की अंगुली को डुबो रहा हूं और मेरे पास एक सूची है जिसमें एक ही नाम के साथ उत्पादों को शामिल किया जा सकता है लेकिन अलग-अलग कीमतें हैं। मुझे क्या करना है सभी किसी उत्पाद के संदर्भों को मूल्य में भिन्नता है।
उदाहरण के लिए।
नाम = "कॉर्नफ़्लेक्स" मूल्य = "1.99M"
नाम = "कॉर्नफ़्लेक्स" मूल्य = "1.89M"
नाम = "चावल Krispies" मूल्य = "2.09M"
नाम = "कॉर्नफ़्लेक्स" मूल्य = " 2.0 9 एम "
नहीं कॉर्नफ्लेक्स मेरी अंतिम सूची में दिखाई देना चाहिए।
मुझे थोक लिखा गया है लेकिन यह जल्द ही उत्पादों को हटा रहा है और मुझे यकीन नहीं है कि मुझे उन्हें हटाया जाना चाहिए।
public IEnumerable<Product> GetProductsByCategory(int Id)
{
List<Product> sourceProductList = products.Where(p => p.CategoryID == Id).ToList();
List<Product> tempProducts = new List<Product>();
List<Product> targetProductList = new List<Product>();
foreach (var product in sourceProductList)
{
bool isInTempList = tempProducts.Any(x => x.Name == product.Name);
if (!isInTempList)
{
tempProducts.Add(product);
}
else
{
Product tempProduct = product;
bool isPriceDifferent = tempProducts.Where(y => y.Name == tempProduct.Name).Any(y => y.Price != tempProduct.Price);
if (isPriceDifferent)
{
tempProducts.RemoveAll(p => p.Name == product.Name);
// too soon as I may have lots of products with the same name
// but need to remove based on product.Name
}
}
}
targetProductList.AddRange(tempProducts);
return targetProductList;
}
किसी भी मदद की सराहना की जाएगी।
नोट: अन्य अनाजों उपलब्ध
@MarkByers मैं आश्वासन दिया गया है कि ऐसा कभी नहीं होगा। – Brett