I need to pass 3 parameters to my API DELETE request. Here is my code what I have try.
TaskModel
public class TaskModel
{
public int DeveloperID { get; set; }
public int ProjectID { get; set; }
public string WorkDate { get; set; }
}
This a controller class. called TaskController
[Route("api/Task")]
public void Delete(TaskModel value)
{
TaskPersistent tp = new TaskPersistent();
tp.deleteTask(value);
}
This is TaskPersistent.class
public void deleteTask(TaskModel task)
{
try
{
string sqlString = "DELETE from devproj WHERE (DeveloperID, ProjectID, WorkDate) = VALUES ('" + task.DeveloperID + "', '" + task.ProjectID + "', '" + task.WorkDate + "')"; // System.NullReferenceException throw
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(sqlString, conn);
cmd.ExecuteNonQuery();
long x = cmd.LastInsertedId;
}
catch (MySqlException x)
{
int errr = x.Number;
Console.WriteLine(errr);
}
}
I consume this API using ARC rest client like this,http://localhost:2731/api/Task?DeveloperID=1&ProjectID=2&WorkDate="2018-03-14"
But when I pass the parameters like this,API thrown exception: 'System.NullReferenceException' in DeleteAPI.dll
(I commented error occurred line in my code). What I did wrong here.