-2

I am still learning so I don't even know if I am explaining this correctly.

Method

public static bool eventSave()

This method can take around 50 parameters. Listing them all in there sounds like a really ineffective way to do things so I am guessing you can do this an easier way.

This method is just doing a SQL UPDATE to save the event information. I already have an eventRead which pulls all the data and uses a model that has all 50 parameters already defined.

public class eventRead
{
    public int event_id { get; set; }
    //etc.
}

Now I would love to just be able to throw that class in the parameters and it knows that it can accept any or all of those 50 parameters, but apparently you can't.

My question is what is the easiest way to pass in 50 or so parameters without putting them all between the ()?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Aaron N
  • 9
  • 5
  • 1
    You already have the `eventRead` class, can't you just re-use that? – DavidG Aug 22 '17 at 16:32
  • How is my question I guess. I tried doing - public static bool eventSave(eventRead eventRead ) - but that didn't work. – Aaron N Aug 22 '17 at 16:37
  • _that didn't work_ doesn't help us. In what way didn't it work? Did it have an error? You could look into using an ORM like Entity Framework. – Chris Dunaway Aug 22 '17 at 18:11
  • I use Dapper. My problem is passing data from the controller to the the function. It allows me to put the class in the parameters in the method, but tin the controller it just doesn't like it. Not sure why yet. I'm pretty new at this so I don't even know how to explain it I guess. – Aaron N Aug 22 '17 at 19:00

3 Answers3

4

You could create an class with all these parameters as properties and pass an instance of this class as parameter in your method

Dimos K
  • 152
  • 8
0

Create a model class and pass it in as the parameter to eventSave().

For example:

public class Event()
{
    public string Param1 {get; set;}
    public string Param2 {get; set;}
    ...
}

Method:

public static bool eventSave(Event event)
logix
  • 622
  • 5
  • 18
0

Since you have the eventRead class available, you could send an instance of the eventRead class as a parameter of your eventSave method.

public static bool eventSave(eventRead _eventRead)

...eventSave(eventReadInstance);