How to call parameterized method inside method in c#?

I write method but method 2.I couldn't call in method 1. I take Convert long to STUDENTS model error.How to solve call parameters function.

METHOD1

[HttpPost]
[Route("AddSchools")]       
public string AddSchools(SCHOOLS model)
{
    try
    {
        using (DbContext db= new DbContext ())
        {

            STUDENT st = new STUDENT();
            long studNo= Convert.ToInt64(st.studNo);
            long recordId= Convert.ToInt64(st.recordId);
        if (model.ID == 0)
        {
            //mycode
        }
        else
        {
            

            db.SaveChanges();

            AddStudent();
       

        }
    }
}
catch (Exception ex)
{
  return false;
}
return "";

}

METHOD2

[HttpPost]
[Route("AddStudent")]
public bool AddStudent(List<STUDENT> studNo,long recordId)
{
    
    try
    {
        foreach (var item in studNo)
        {
            if (item.ID != 0)
            {
               //mycode
            }
            else 
            {
                //mycode
            }

        }
        _db.SaveChanges();

        return true;
    }
    catch (Exception e)
    {
        return false;
    }
    #endregion

}

I wrote the following codes in method 1 to call it, but it was incorrect. How can I call method 2 in method 1.

         STUDENT st = new STUDENT();
        long studNo= Convert.ToInt64(st.studNo);
        long recordId= Convert.ToInt64(st.recordId);
        AddStudent();
        

studNo and recordId type is long.

 public long? recordId { get; set; }
 public long? studNo { get; set; }

1 answer

  • answered 2021-01-16 18:23 Emilis Kiškis

    You just seem to have missed to pass the parameters to method AddStudent. Your code block should look like this then:

    st = new STUDENT();
    studNo = Convert.ToInt64(st.studNo);
    recordId = Convert.ToInt64(st.recordId);
    AddStudent(studNo, recordId);
    

    The studNo parameter is described as List<STUDENT>. Maybe you wanted to have it as long?