Exemplo n.º 1
0
        public static List<Message> GetMessagesFromServer(string request, Method method)
        {
            var messages = new List<Message>();

            var results = Request(request, method);
            try
            {
                JArray ja = JsonConvert.DeserializeObject<JArray>(results);
                foreach (var r in ja)
                {
                    var c = (MessageApi)JsonConvert.DeserializeObject(r.ToString(), typeof(MessageApi));
                    var u = new Message(c);
                    messages.Add(u);
                }

            }
            catch (Exception ex1)
            {
                Console.WriteLine(ex1.ToString());

                try
                {
                    JObject r = JsonConvert.DeserializeObject<JObject>(results);
                    var c = (MessageApi)JsonConvert.DeserializeObject(r.ToString(), typeof(MessageApi));
                    var u = new Message(c);
                    messages.Add(u);
                }
                catch (Exception ex2)
                {
                    Console.WriteLine(ex2.ToString());
                }
            }
            
            return messages;
        }
Exemplo n.º 2
0
        public void SendMessage(string content, int senderId, int receiverId)
        {
            Message mess = new Message();
            mess.Content = content;
            mess.SenderId = senderId;
            mess.ReceiverId = receiverId;

            _db.Messages.Add(mess);
            _db.SaveChangesAsync();
        }