Exemple #1
0
        public JsonResult AddConverstion(string recipientId)
        {
            try
            {
                var conversation = new Conversation
                {
                    RecipientId = recipientId,
                    SenderId = User.Identity.GetUserId()
                };

                _conversationService.AddConversation(conversation);

                if (conversation.Id != default(int))
                {
                    conversation = _conversationService.GetConversation(conversation.Id);
                    var conversationViewModel = TypeAdapter.Adapt<Conversation, ConversationViewModel>(conversation);
                    ChatMonitor.Instance.AddConversation(conversationViewModel);
                }

                return Json(new { success = true });
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return Json(new { success = false });
            }
        }
        public void AddConversation(Conversation conversation)
        {
            if (!_exchangeContext.Users.Any(u => u.Id.Equals(conversation.RecipientId)))
                return;

            bool conversationExist = _exchangeContext.Conversations.Any(c =>
                (c.RecipientId.Equals(conversation.RecipientId) && c.SenderId.Equals(conversation.SenderId))
                || (c.RecipientId.Equals(conversation.SenderId) && c.SenderId.Equals(conversation.RecipientId)));

            if (conversationExist)
                return;

            _exchangeContext.Conversations.Add(conversation);
            _exchangeContext.SaveChanges();
        }