public async Task <IEnumerable <FireBaseDataModel> > GetMessages() { if (client == null) { client = new FireSharp.FirebaseClient(config); } List <FireBaseDataModel> resultList = new List <FireBaseDataModel>(); if (client != null) { var response = await client.GetTaskAsync("Messages"); var resultJson = response.Body; dynamic dynJson = JsonConvert.DeserializeObject(resultJson); foreach (var item in dynJson) { var nodeItem = item.Value; var data = new FireBaseDataModel { Id = nodeItem.Id, MessageContent = nodeItem.MessageContent, MessageUser = nodeItem.MessageUser, MessageDate = nodeItem.MessageDate }; resultList.Add(data); } } return(resultList.OrderByDescending(r => r.MessageDate).Take(10).AsEnumerable()); }
public async Task <FireBaseDataModel> SaveMessage(EventMessage message) { client = new FireSharp.FirebaseClient(config); FireBaseDataModel result = new FireBaseDataModel(); if (client == null) { log.Info($"Firebase RealTime DB connection is not established "); } else { var data = new FireBaseDataModel { Id = message.Id, MessageUser = "******", MessageContent = message.PublishMessage, MessageDate = message.SendTime }; SetResponse response = await client.SetTaskAsync("Messages/" + data.Id, data); result = response.ResultAs <FireBaseDataModel>(); } return(result); }