public async Task <IHttpActionResult> CreateConversation(int userID, int friendID) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await db.Users.FirstOrDefaultAsync((u) => u.UserID == userID); if (user == null) { NotFound(); } var friend = await db.Users.FirstOrDefaultAsync(u => u.UserID == friendID); if (friend == null) { NotFound(); } await Task.Run(() => db.CreateAConversation(userID, friendID)); var conversationFullInfo = await Task.Run(() => ( db.Participants .Where(u => u.UserID == userID) .Where(g => g.Group.GroupType == "CONVERSATION") .Intersect( db.Participants .Where(u => u.UserID == friendID) .Where(g => g.Group.GroupType == "CONVERSATION")) ).FirstOrDefaultAsync() ); var conversationID = conversationFullInfo.GroupID; return(Json <int?>(conversationID)); }