locked
Combination Logic In C# RRS feed

  • Question

  • User1944504294 posted

    Hi,

    please help

    I want check the 2 combinations if no combinations exisits I need to do insert

    My Code

    combinations:

    Category Name, Category Type:

    Music , Album

    Music, Single and etc..

    Here I need to check if there is no existing combination then I need to add to cartcollection

           Entity_CategoryCollection cartCollection = new Entity_CategoryCollection();

              if (cartCollection.Count == 0)
                        {
                            cartCollection.Add(category);
                        }
                        else
                        {
                            for (int j = 0; j < cartCollection.Count; j++)
                            {
                                if (cartCollection[j].CategoryName != category.CategoryName)                                                             
                                {
                                     cartCollection.Add(category);
                                }
                                if (cartCollection[j].CategoryName == category.CategoryName)
                                {
                                    //Here I want to loop all the cart type from the entity class


                                }
                            }
                            
                        }  

    Wednesday, December 10, 2014 8:15 AM

Answers

  • User-484054684 posted

    Hi,

    Try something similar to below - assuming the property name is CartType both the sides:

    cartCollection[j].CartType == category.CartType

    Entity_CategoryCollection cartCollection = new Entity_CategoryCollection();
    
              if (cartCollection.Count == 0)
                        {
                            cartCollection.Add(category);
                        }
                        else
                        {
                            bool isFound = false;
                            for (int j = 0; j < cartCollection.Count; j++)
                            {
     
                                if (cartCollection[j].CategoryName == category.CategoryName &&
                                    cartCollection[j].CartType == category.CartType)
                                {
                                      isFound = true;
                                      break;
                                }
                            } // End of forloop
    
                           if(isFound == false)
                           {
                              // insert related functionality here
                           }       
    
                           
                        }  // End of else condition
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 10, 2014 9:18 AM