C# - Object Orientation Question

Hello Friends,

I have a class file which will have an event info object with lot of properties. I am trying to add couple of list of objects with the event info object.

After I assign the value to List<EventFeedLocation> and tried adding the list to the event info. It is not happening.
My Main method()
------------

if (eventTransaction != null)
			{
				EventFeedInfo eventFeedInfo = new EventFeedInfo();
				eventFeedInfo = AssignEventFeedDetails(eventTransaction);

				List<EventFeedLocation> eventFeedLocations = new List<EventFeedLocation>();				
				eventFeedLocations = AssignEventFeedLocation(eventTransaction, eventFeedInfo.GroupEventID);
				//eventFeedInfo.EventFeedLocation.Add(eventFeedLocations);

				EventFeedOrderLineItem eventFeedOrderLineItem = new EventFeedOrderLineItem();
				eventFeedOrderLineItem = AssignEventFeedOrderLineItem(eventTransaction);
				eventFeedInfo.EventFeedOrderLineItem.Add(eventFeedOrderLineItem);

				EventFeedPersonAddress eventFeedPersonAddress = new EventFeedPersonAddress();
				eventFeedPersonAddress = AssignFeedPersonAddress(eventTransaction);
				eventFeedInfo.EventFeedPersonAddress.Add(eventFeedPersonAddress);
							
			}


Function
---------

public List<EventFeedLocation> AssignEventFeedLocation(EventTransaction eventTransaction, int GroupEventID)
		{
			
			List<EventFeedLocation> eventFeedLocations = new List<EventFeedLocation>();
			EventFeedLocation eventFeedLocation = new EventFeedLocation();
			foreach (DateItem dateItem in eventTransaction.Dates)
				{
					eventFeedLocation = new EventFeedLocation();
					DateTime currentDateTime = DateTime.Now;
					eventFeedLocation.LocationStartDate = dateItem.EventDateTimeStart;
					eventFeedLocation.LocationEndDate = dateItem.EventDateTimeEnd;
					eventFeedLocation.LocationCreatedDateTime = dateItem.CreatedOn;
					eventFeedLocation.Location = dateItem.Location;
					eventFeedLocation.GroupEventID = GroupEventID;
					eventFeedLocation.ApplicationUserID = "Subbu_Devloper";

				}

			return eventFeedLocations;
		}

Open in new window

SubbuUSAAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
Well, for starters, you're not adding your EventFeedLocation objects to your List. Start by changing your method to:
public List<EventFeedLocation> AssignEventFeedLocation(EventTransaction eventTransaction, int GroupEventID)
		{
			
			List<EventFeedLocation> eventFeedLocations = new List<EventFeedLocation>();
			EventFeedLocation eventFeedLocation = new EventFeedLocation();
			foreach (DateItem dateItem in eventTransaction.Dates)
				{
					eventFeedLocation = new EventFeedLocation();
					DateTime currentDateTime = DateTime.Now;
					eventFeedLocation.LocationStartDate = dateItem.EventDateTimeStart;
					eventFeedLocation.LocationEndDate = dateItem.EventDateTimeEnd;
					eventFeedLocation.LocationCreatedDateTime = dateItem.CreatedOn;
					eventFeedLocation.Location = dateItem.Location;
					eventFeedLocation.GroupEventID = GroupEventID;
					eventFeedLocation.ApplicationUserID = "Subbu_Devloper";
                                        evetnFeedLocations.Add(eventFeedLocation);
				}

			return eventFeedLocations;
		}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SubbuUSAAuthor Commented:
@Carl_tawn,

Thanks for your reply. I added  evetnFeedLocations.Add(eventFeedLocation); your line and looks like it is working but I still have error in the commented line in my first method (//eventFeedInfo.EventFeedLocation.Add(eventFeedLocations);)

Do you have any suggestions for me..

The Errors are

Error 1
System.Collections.Generic.ICollection<sw.Bll.Events.EventFeedLocation>.Add(Smartworks.Bll.Events.EventFeedLocation)' has some invalid arguments      

Error 2

cannot convert from 'System.Collections.Generic.List<sw.Bll.Events.EventFeedLocation>' to 'sw.Bll.Events.EventFeedLocation'
Carl TawnSystems and Integration DeveloperCommented:
What is the type for your EventFeedLocation property?
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

SubbuUSAAuthor Commented:
@carl_tawn,

public IList<EventFeedLocation> EventFeedLocation { get; set; }

EventFeedLocation.cs will have this property

public class EventFeedLocation
      {
            //Stored Procedure Used - dbo.usp_InsertGroupEventLocation

            public int GroupEventID { get; set; }
            public string Location { get; set; }
            public DateTime LocationStartDate { get; set; }
            public DateTime LocationEndDate { get; set; }
            public DateTime LocationCreatedDateTime { get; set; }
            public string ApplicationUserID { get; set; }
            
      }
ericpeckhamCommented:
You can't use Add to add another list to your existing list.  Try this instead:

    eventFeedInfo.EventFeedLocation.AddRange(eventFeedLocations);

SubbuUSAAuthor Commented:
Adding AddRange failed

Error      4      'System.Collections.Generic.IList<sw.Bll.Events.EventFeedLocation>' does not contain a definition for 'AddRange' and no extension method 'AddRange' accepting a first argument of type 'System.Collections.Generic.IList<sw.Bll.Events.EventFeedLocation>' could be found (are you missing a using directive or an assembly reference?
Carl TawnSystems and Integration DeveloperCommented:
You can't just throw a List at AddRange either, try the following:
eventFeedInfo.EventFeedLocation.AddRange(eventFeedLocations.ToArray());

Open in new window

SubbuUSAAuthor Commented:
@carl_tawn

No luck. The type of eventfeedlocation property is
IList<EventFeedLocation> eventFeedLocations = new List<EventFeedLocation>();

Tried following code but no luck

public IList<EventFeedLocation> AssignEventFeedLocation(EventTransaction eventTransaction, int GroupEventID)
            {

                  IList<EventFeedLocation> eventFeedLocations = new List<EventFeedLocation>();
                  EventFeedLocation eventFeedLocation = new EventFeedLocation();
                  DateItem dateItem = new DateItem();
                  dateItem.EventDateTimeStart = DateTime.Now;
                  dateItem.EventDateTimeEnd = DateTime.Now;
                  dateItem.CreatedOn = DateTime.Now;
                  
                  if(true)

                  //foreach (DateItem dateItem in eventTransaction.Dates)
                  {
                        eventFeedLocation = new EventFeedLocation();
                        DateTime currentDateTime = DateTime.Now;
                        eventFeedLocation.LocationStartDate = dateItem.EventDateTimeStart;
                        eventFeedLocation.LocationEndDate = dateItem.EventDateTimeEnd;
                        eventFeedLocation.LocationCreatedDateTime = dateItem.CreatedOn;
                        eventFeedLocation.Location = dateItem.Location;
                        eventFeedLocation.GroupEventID = GroupEventID;
                        eventFeedLocation.ApplicationUserID = "Subbu_Devloper";
                        eventFeedLocations.Add(eventFeedLocation);
                        
                  }
                  

                  return eventFeedLocations;
            }
if (eventTransaction != null)
			{
				EventFeedInfo eventFeedInfo = new EventFeedInfo();
				eventFeedInfo = AssignEventFeedDetails(eventTransaction);
				
				IList<EventFeedLocation> eventFeedLocations = new List<EventFeedLocation>();
				eventFeedLocations = AssignEventFeedLocation(eventTransaction, eventFeedInfo.GroupEventID);
				eventFeedInfo.EventFeedLocation.AddRange(eventFeedLocations.ToArray());
			
				EventFeedOrderLineItem eventFeedOrderLineItem = new EventFeedOrderLineItem();
				eventFeedOrderLineItem = AssignEventFeedOrderLineItem(eventTransaction);
				eventFeedInfo.EventFeedOrderLineItem.Add(eventFeedOrderLineItem);

				EventFeedPersonAddress eventFeedPersonAddress = new EventFeedPersonAddress();
				eventFeedPersonAddress = AssignFeedPersonAddress(eventTransaction);
				eventFeedInfo.EventFeedPersonAddress.Add(eventFeedPersonAddress);
							
			}


----------------

Open in new window

ericpeckhamCommented:
Ah, sorry - AddRange only works if you're adding a list of the same type.
ericpeckhamCommented:
Your original exception states that Add(...) is expecting a type of 'sw.Bll.Events.EventFeedLocation', which is a single instance of an object, not a collection, so I think the following will work in place of the commented-out line:

 
foreach (EventFeedLocation eventFeedLocation in eventFeedLocations)
{
  eventFeedInfo.EventFeedLocation.Add(eventFeedLocation);
}

Open in new window


This code will compile, but I'm still not sure what you're really trying to do by adding multiple instances of a type to a single instance of the same type.
SubbuUSAAuthor Commented:
Thank you both. appreciated
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.