I have two methods, one in WebApi (Post()) and one in my data repo (Save()). Inside the Save method I call an async method with await. The Save method itself is async.
What I in the end want to accomplish is that after the function in the Save method completes to send 201 to the user.
Web api:
public HttpResponseMessage Post(JObject input)
{
Event postedEvent = new Event(// here be data //);
IEventRepo repo = new MongoDBRepo();
return repo.Save(postedEvent).Result;
}
Data repo:
public async Task<HttpResponseMessage> Save(Event e)
{
await _collection.InsertOneAsync(e);
return new HttpResponseMessage(HttpStatusCode.Created);
}
What happens now is that the Save will be done, but the HttpResponseMessage will never get sent. So the request to the server will hang.