Beispiel #1
0
        private void AddMessage(ChatMessageForm form)
        {
            var newMessage = Mapper.Map<ChatMessage>(form);

            var chatId = form.ChatId ?? Session[SessionKey.ChatId] as int?;
            Chat chat = null;

            if (chatId != null)
                chat = Repository.Chat.Get(chatId.Value);

            if (chat != null && !chat.IsClosed)
            {
                if (!AuthenticationHelper.IsModerator && chat.Owner != AuthenticationHelper.CurrentUser)
                    return;

                if (chat.Moderator == null && chat.Owner != AuthenticationHelper.CurrentUser && AuthenticationHelper.CurrentUser.IsModerator)
                    chat.Moderator = AuthenticationHelper.CurrentUser;

                if (AuthenticationHelper.CurrentUser == chat.Owner)
                {
                    chat.LastReadTime = DateTime.Now;
                    newMessage.Context = GetContext();
                }

                chat.Messages.Add(newMessage);
                Repository.Chat.Update(chat);
            }
            else
            {
                chat = new Chat
                           {
                               Messages = new Collection<ChatMessage>(),
                               Owner = AuthenticationHelper.CurrentUser,
                               OwnerEmail = Session[SessionKey.ChatEmail] as string
                           };

                newMessage.Context = GetContext();
                chat.Messages.Add(newMessage);

                Repository.Chat.Add(chat);

                EventLog.Event<NewChatEvent>(chat.Owner);

                Session[SessionKey.ChatId] = chat.Id;
            }
        }
Beispiel #2
0
 public virtual ActionResult SendMessage(ChatMessageForm form)
 {
     AddMessage(form);
     return null;
 }