예제 #1
0
        void LoadMessages()
        {
            if (game == null)
                return;

            using (var db = new DBConnection())
            {
                ViewBag.Messages = new List<Message>();

                using (var messages = db.OpenQuery(String.Format("select m.id as id, to_id, from_id, fromAccount.name fromName, text, time from message as m join account as fromAccount on m.from_id = fromAccount.id where to_id = {0} order by id desc limit 150", -game.Id)))
                {
                    while (messages.Read())
                    {
                        var newMessage = new Message() { Id = (int)messages["id"], SourceId = (int)messages["from_id"], SourceName = (string)messages["fromName"], Text = messages["text"].ToString(), Sent = Utility.FromUnixTimestamp((int)messages["time"]) };
                        ViewBag.Messages.Add(newMessage);
                    }
                }
            }
        }
예제 #2
0
        List<Message> LoadMessages(DBConnection db, int toId)
        {
            var result = new List<Message>();

            using (var messages = db.OpenQuery(String.Format("select m.id as id, to_id, from_id, fromAccount.name fromName, toAccount.name toName, text, time from message as m join account as fromAccount on m.from_id = fromAccount.id join account as toAccount on m.to_id = toAccount.id where to_id = {0} or from_id = {0} order by id desc limit 150", toId)))
            {
                var count = 0;
                while (messages.Read())
                {
                    var destinationId = (int)messages["to_id"];
                    if (destinationId > 0)
                    {
                        var newMessage = new Message() { Id = (int)messages["id"], SourceId = (int)messages["from_id"], SourceName = (string)messages["fromName"], DestinationId = destinationId, DestinationName = (string)messages["toName"], Text = messages["text"].ToString(), Sent = Utility.FromUnixTimestamp((int)messages["time"]) };
                        result.Add(newMessage);

                        count++;
                        if (count >= 100)
                            break;
                    }
                }
            }
            return result;
        }