public GetMessagesResponse GetMessages(GetMessagesRequest request)
        {
            RemoveMessages();
            var username      = HttpContext.Current.User.Identity.Name;
            var countMessages = Context.Messages.Count();

            if (request.CountLastMessages < 0)
            {
                request.CountLastMessages = countMessages;
            }
            if (request.CountLastMessages > countMessages)
            {
                request.CountLastMessages = countMessages;
            }
            var countSkipMessage = countMessages - request.CountLastMessages;

            if (countSkipMessage <= 0)
            {
                countSkipMessage = 0;
            }
            var messages = Context.Messages.OrderBy(m => m.TimeMessage).Skip(countSkipMessage)
                           .ToList()
                           .Select(m =>
            {
                var userMessage = new UserMessage
                {
                    UserName    = m.UserName,
                    TimeMessage = m.TimeMessage.ToString("f"),
                    Content     = m.Content
                };
                if (m.UserName == username)
                {
                    userMessage.InitSelf();
                }
                else
                {
                    userMessage.InitOthner();
                }
                return(userMessage);
            }).ToList();

            return(new GetMessagesResponse(messages));
        }
 public Task <HttpResponseMessage> GetMessages(GetMessagesRequest request)
 {
     return(ExecuteAction(request, Repository.GetMessages));
 }