public IHttpActionResult ManageParentTask([FromBody] ParentTaskModel parentTask) { if (!ModelState.IsValid) { return(BadRequest("Not a valid data")); } try { TaskManagerRepository parentTaskRep = new TaskManagerRepository(); Parent_Task_Tbl parentTaskDb = parentTaskRep.getParent(parentTask.ParentTaskID); if (parentTaskDb != null) { parentTaskDb.Parent_Task = parentTask.ParentTaskName; string result = "{'ParentTaskID': " + parentTaskRep.EditParentTask(parentTaskDb) + "}"; JObject json = JObject.Parse(result); return(Ok <JObject>(json)); } else { Parent_Task_Tbl parentTaskNewDb = new Parent_Task_Tbl { Parent_Task = parentTask.ParentTaskName, }; string result = "{'ParentTaskID': " + parentTaskRep.CreateParentTask(parentTaskNewDb) + "}"; JObject json = JObject.Parse(result); return(Ok <JObject>(json)); } } catch (Exception ex) { return(BadRequest("Error occurred in CreateParentTask :" + ex.StackTrace)); } }