private async void ReceivedEvent(object sender, BasicDeliverEventArgs e) { if (e.RoutingKey == "find") { var message = Encoding.UTF8.GetString(e.Body); JObject receivedObj = JsonConvert.DeserializeObject <JObject>(message); DateTime from = receivedObj["From"].Value <DateTime>(); DateTime to = receivedObj["To"].Value <DateTime>(); string requestId = receivedObj["RequestId"].Value <string>(); if (Db.Connection.State != System.Data.ConnectionState.Open) { await Db.Connection.OpenAsync(); } var query = new ApplicationQuery(Db); var result = await query.FindAvailableDrivers(from, to); JObject reply = new JObject(); reply.Add("RequestId", requestId); reply.Add("Command", "driverFound"); reply.Add("Drivers", JToken.FromObject(result)); Booking booking = new Booking(Db); booking.ApplicationId = result[0].ApplicationID; booking.FromTime = from; booking.ToTime = to; await booking.InsertAsync(); PublishFoundDrivers("driver", "found", reply.ToString()); } }