Exemplo n.º 1
0
        public IQueryable <MessageModel> GetAllMessages(string sessionKey)
        {
            //Find the user
            UserRepository userRepository = data.GetUserRepository();
            int            userId         = userRepository.LoginUser(sessionKey);

            if (userId == 0)
            {
                HttpResponseMessage response = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User not found");
                throw new HttpResponseException(response);
            }

            //Retrive his messages
            MessagesRepository        messagesRepository = data.GetMessagesRepository();
            IQueryable <MessageModel> messages           = messagesRepository.GetMessagesByUserId(userId).Select(MessageModel.FromMessage);

            if (messages == null)
            {
                HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.BadRequest, "Bad request");
                throw new HttpResponseException(response);
            }

            return(messages);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get all messages
        /// for logged user.
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <MessageResponse> GetUserMessages(string userId)
        {
            var userMessages = await _repository.GetMessagesByUserId(userId);

            return(MessageResponse.Successfull(userMessages));
        }