コード例 #1
0
ファイル: UserService.cs プロジェクト: mrtryhard/millebornes
        /// <summary>
        /// Récupère les messages globaux.
        /// </summary>
        /// <param name="limit"></param>
        /// <returns>Liste des messages.</returns>
        public List<Models.UserMessage> GetGlobalMessages(int limit)
        {
            List<Models.UserMessage> lstUMessages = new List<UserMessage>();

            try
            {
                using (MilleBornesEntities context = new MilleBornesEntities())
                {
                    var lstMessages = context.Message
                        .Where(p => p.Type == MessageType.GLOBAL)
                        .OrderByDescending(o => o.MessageId).ToList();

                    foreach (Message msg in lstMessages)
                    {
                        if (limit == 0)
                            break;

                        UserMessage uMsg = new UserMessage();
                        uMsg.Content = msg.Content;
                        uMsg.Date = msg.Date;
                        uMsg.Username = msg.User.Name;

                        lstUMessages.Add(uMsg);

                        limit--;
                    }
                }
            }
            catch
            {
            }

            return lstUMessages;
        }
コード例 #2
0
ファイル: LobbyService.cs プロジェクト: mrtryhard/millebornes
        /// <summary>
        /// Obtient les nouveaux messages de name
        /// </summary>
        /// <param name="name">Utilisateur</param>
        /// <returns>Liste des nouveaux messages.</returns>
        public List<UserMessage> GetNewMessageFrom(Guid player, string name)
        {
            List<UserMessage> lstMessages = new List<UserMessage>();
            
            try
            {
                using (MilleBornesEntities context = new MilleBornesEntities())
                {
                    // Récupère les ids...
                    LoggedInUser receiver = context.LoggedInUser.First(p => p.Token == player);
                    User sender = context.User.First(p => p.Name.Trim() == name.Trim());

                    IQueryable<PrivateMessage> lstNewMessages = context.PrivateMessage.Where(p => p.ReceiverUserId == receiver.UserId
                                                                && p.SenderUserId == sender.UserId
                                                                && p.Read == false);

                    foreach (PrivateMessage pm in lstNewMessages)
                    {
                        UserMessage um = new UserMessage();
                        um.Content = pm.Message;
                        um.Date = pm.SentTime;
                        um.Username = name;

                        lstMessages.Add(um);
                        pm.Read = true;
                    }

                    context.SaveChanges();
                }
            }
            catch
            {
            }

            return lstMessages;
        }