public async Task <IHttpActionResult> CreateGroup(string groupName, int ownerID) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (string.IsNullOrWhiteSpace(groupName)) { return(BadRequest()); } var friend = await db.Users.FirstOrDefaultAsync(u => u.UserID == ownerID); if (friend == null) { NotFound(); } var createTime = DateTime.Now; await db.CreateAGroup(ownerID, groupName); var group = await db.Groups.Where(info => info.Owner == ownerID && info.GroupName == groupName && info.CreateTime >= createTime).FirstOrDefaultAsync(); return(Json <int>(group.GroupID)); }