Beispiel #1
0
        public IHttpActionResult GetTestChats(int?count = 40)
        {
            var filter = new AppChatMessageSearchFilter();

            //add search filter for GetAppChatMessages
            if (AuthHelper.CurrentUser.Type == UserSecurity.UserType.Customer)
            {
                filter.CustomerId = AuthHelper.CurrentUser.Id;
            }
            if (AuthHelper.CurrentUser.Type == UserSecurity.UserType.Admin)
            {
                filter.AdminId = AuthHelper.CurrentUser.Id;
            }
            var relatedUserIds = GetRelatedUserIds(AuthHelper.CurrentUser.Id, AuthHelper.CurrentUser.Type);

            if (!relatedUserIds.Any())
            {
                return(Content(HttpStatusCode.NotFound, "No related users found"));
            }

            //TODO implement get message from db like so:
            // var message = AppChatManager.GetAppChatMessages();
            var query = new List <ChatMessageModel> ();

            if (!query.Any())
            {
                return(NotFound());
            }

            var result = new List <ChatMessageResponseModel>();

            foreach (var id in relatedUserIds)
            {
                var messageList = (from m in query
                                   where (m.SenderId == AuthHelper.CurrentUser.Id && m.ReceiverId == id || m.SenderId == id && m.ReceiverId == AuthHelper.CurrentUser.Id)
                                   select new ChatMessageModel
                {
                    Id = m.Id,
                    SenderId = m.SenderId,
                    ReceiverId = m.ReceiverId,
                    DateCreated = m.DateCreated,
                    DateRead = m.DateRead,
                    Message = m.Message
                }).ToList();
                result.Add(new ChatMessageResponseModel
                {
                    RelatedUserId = id,
                    Messages      = messageList
                });
            }

            return(Ok(result));
        }
Beispiel #2
0
        public IHttpActionResult Get()
        {
            //add search filter for GetAppChatMessages
            var filter = new AppChatMessageSearchFilter
            {
                CustomerId = AuthHelper.CurrentUser.Id,
            };

            if (AuthHelper.CurrentUser.Type == UserSecurity.UserType.Admin)
            {
                filter.CustomerId = null;
                filter.AdminId    = AuthHelper.CurrentUser.Id;
            }

            //TODO implement get message from db like so:
            // var message = AppChatManager.GetAppChatMessages(filter);
            var query = new List <ChatMessageModel>();

            if (!query.Any())
            {
                return(NotFound());
            }

            var result = (from m in query
                          //where m.SenderID == AuthHelper.CurrentUser.Id || m.ReceiverID == AuthHelper.CurrentUser.Id
                          select new ChatMessageModel
            {
                Id = m.Id,
                SenderId = m.SenderId,
                ReceiverId = m.ReceiverId,
                DateCreated = m.DateCreated,
                DateRead = m.DateRead,
                Message = m.Message
            }).ToList();

            return(Ok(result));
        }