public async Task <IHttpActionResult> SendAMessage(int groupID, int senderID, string content, string attachmentPath = null, int?messageToReplayID = null) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (string.IsNullOrWhiteSpace(content)) { return(BadRequest()); } string attachmentName = string.Empty; if (!string.IsNullOrWhiteSpace(attachmentPath)) { attachmentName = attachmentPath.Substring(attachmentPath.LastIndexOf('/'), attachmentPath.Length - 1); } var sentTime = DateTime.Now; await db.SendMessage(groupID, senderID, content, attachmentPath, attachmentName, messageToReplayID, sentTime); var messageID = await db.GroupMessages.Where(g => g.GroupID == groupID).Where(u => u.SenderID == senderID).Where(m => m.Message.SentTime == sentTime).FirstOrDefaultAsync(); return(Json(messageID)); }