Jump to content

Dot Net Help In A Scenario


Recommended Posts

Posted

Hi Frndz,

I need some help in implementing a sol..

Scenario:

 

Object 1 is the base class/entity and Object 2 is property of Object 1 and Object 2 is a list property

 

Object 1:

               Name: Test
               Date: 2014-01-01

               Code: blank initially (array type)

               Id: 1

               Object2: (List of objects)

 

Object 2 (List object):

               Id: 1
               Name: Welcome 1

               Line: 0

               Code: 21
 

               Id: 1
               Name: Welcome 2

               Line: 1

               Code: 22

 

               Id: 1
               Name: Welcome 3

               Line: 2

               Code: 22

 

               Id: 1
               Name: Welcome 4

               Line: 3

               Code: 22

 

               Id: 1
               Name: Welcome 5

               Line: 4

               Code: 23

 

 

I have 2 objects of above data, and as mentioned the object 2 is property of object 1.

 

Now i need to do is i need to check the Code value in Object 2 and if it has same code repeated then i need to take the repeated code (i.e. 22 in this case) and add it in Code property of Object 1.  If there are multiple repetitions it should add all those to Code property in Object 1.  And it should set Code value to null in the list objects of Object 2 where the value is repeated.

 

For the value that is not repeated (i.e. 21, 23), leave them as it is.

 

 

Can you please guide or provide me best way to implement.

 

Posted

help

u shd be able to give the code..not help board man

Posted

hmm..may be wrong time for the thread??

 

no one to help??

Posted

nee code rasthe i can help u.. scratch nunchi rayalante mood ravatledu... opika ledu bayya

Posted

code PM chey

Posted
This is what i understood from your problem.
 
Here is something which you can play around with
 
List<Object2> object2List = new List<Object2>();
 
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 21, LineNo = 0 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 22, LineNo = 1 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 22, LineNo = 2 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 22, LineNo = 3 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 23, LineNo = 4 });
 
 
 
            Object1 obj1 = null;
            obj1 = new Object1() { Id = 1, Name = "Test", code = 0, Object2List = object2List };
 
 
            var duplicateItems = from x in obj1.Object2List
                                 group x by x.Code into grouped
                                 where grouped.Count() > 1
                                 select grouped.Key;
            //To hold the first occurence
            int init;
            //Dup values 22              
            foreach (var dupItem in duplicateItems)
            {
                init = 0;
                for (int i = 0; i < object2List.Count(); i++)
                {
                    if (object2List[i].Code == (int)dupItem && init == 0)
                    {
                        //First occurence of duplicate value, so ignore that line number
                        init++;
                    }
                    else if (object2List[i].Code == (int)dupItem)
                    {
                        //Add the dup value to obj 1 and remove from Obj2
                        obj1.code = obj1.code + dupItem;
                        //Remove the value from Obj2 list
                        object2List[i].Code = 0;
                    }
                }
            }
 
Email me if you need any help further help: [email protected]
Enjoy!!!!!!!!!!!!
Posted

 

This is what i understood from your problem.
 
Here is something which you can play around with
 
List<Object2> object2List = new List<Object2>();
 
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 21, LineNo = 0 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 22, LineNo = 1 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 22, LineNo = 2 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 22, LineNo = 3 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 23, LineNo = 4 });
 
 
 
            Object1 obj1 = null;
            obj1 = new Object1() { Id = 1, Name = "Test", code = 0, Object2List = object2List };
 
 
            var duplicateItems = from x in obj1.Object2List
                                 group x by x.Code into grouped
                                 where grouped.Count() > 1
                                 select grouped.Key;
            //To hold the first occurence
            int init;
            //Dup values 22              
            foreach (var dupItem in duplicateItems)
            {
                init = 0;
                for (int i = 0; i < object2List.Count(); i++)
                {
                    if (object2List[i].Code == (int)dupItem && init == 0)
                    {
                        //First occurence of duplicate value, so ignore that line number
                        init++;
                    }
                    else if (object2List[i].Code == (int)dupItem)
                    {
                        //Add the dup value to obj 1 and remove from Obj2
                        obj1.code = obj1.code + dupItem;
                        //Remove the value from Obj2 list
                        object2List[i].Code = 0;
                    }
                }
            }
 
Email me if you need any help further help: [email protected]
Enjoy!!!!!!!!!!!!

 

 

 

thanks Bhayaa....will try to implement...

Posted

 

This is what i understood from your problem.
 
Here is something which you can play around with
 
List<Object2> object2List = new List<Object2>();
 
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 21, LineNo = 0 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 22, LineNo = 1 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 22, LineNo = 2 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 22, LineNo = 3 });
            object2List.Add(new Object2() { Id = 1, Name = "Test", Code = 23, LineNo = 4 });
 
 
 
            Object1 obj1 = null;
            obj1 = new Object1() { Id = 1, Name = "Test", code = 0, Object2List = object2List };
 
 
            var duplicateItems = from x in obj1.Object2List
                                 group x by x.Code into grouped
                                 where grouped.Count() > 1
                                 select grouped.Key;
            //To hold the first occurence
            int init;
            //Dup values 22              
            foreach (var dupItem in duplicateItems)
            {
                init = 0;
                for (int i = 0; i < object2List.Count(); i++)
                {
                    if (object2List[i].Code == (int)dupItem && init == 0)
                    {
                        //First occurence of duplicate value, so ignore that line number
                        init++;
                    }
                    else if (object2List[i].Code == (int)dupItem)
                    {
                        //Add the dup value to obj 1 and remove from Obj2
                        obj1.code = obj1.code + dupItem;
                        //Remove the value from Obj2 list
                        object2List[i].Code = 0;
                    }
                }
            }
 
Email me if you need any help further help: [email protected]
Enjoy!!!!!!!!!!!!

 

I could able to implement using the linq query you gave.

I had little hard to implement for my scenario...since it had little complex data structure..

 

anyways..thanks a lot dude.........

×
×
  • Create New...