[HttpPost]
public IActionResult Post([FromBody]string value)
{
string customMessage = "";
int userId = GetUserIdFromUserInfo();
//Reconstruct a useful object from the input string value.
dynamic missionNewInput = JsonConvert.DeserializeObject<dynamic>(value);
MissionSynopsis newMission = new MissionSynopsis();
try
{
newMission.MissionSynopsisName = MissionNewInput.MissionSynopsisName.Value;
newMission.CreatedById = userId;
newMission.UpdatedById = userId;
Database.MissionSynopses.Add(newMission);
Database.SaveChanges();
}
catch (Exception exceptionObject)
{
if (exceptionObject.InnerException.Message
.Contains("MissionSynopsis_MissionSynopsisName_UniqueConstraint") == true)
{
customMessage = "Unable to save ";
object httpFailRequestResultMessage = new { message = customMessage };
return BadRequest(httpFailRequestResultMessage);
}
}
}
System.NullReferenceException: 'Object reference not set to an instance of an object.'
pops up at the if statement of the catch part. How do I solve this?