Beispiel #1
0
        public IHttpActionResult GetUser(int userId)
        {
            var user = UnitOfWork.UserRepository.GetById(userId);

            if (user == null)
            {
                return(NotFound());
            }
            UserReturnModel uModel = Mapper.Map <User, UserReturnModel>(user);

            if (OnlineWorker.IsOnline(user))
            {
                uModel.Online = true;
            }
            return(Ok(uModel));
        }
Beispiel #2
0
        public void GetConversations(int page)
        {
            var    principal    = JwtManager.GetPrincipal(Context.QueryString.Get("Bearer"));
            string thisUsername = principal.Identity.Name;
            var    thisUser     = UnitOfWork.UserRepository.GetByName(thisUsername);
            var    messages     = UnitOfWork.MessageRepository
                                  .GetLastMessages(thisUser.Id, ConversationsPerPage, page);

            messages.ForEach(m => UnitOfWork.UserRepository
                             .GetById(thisUser.Id != m.SenderId ? m.SenderId : m.ReceiverId));
            var conversations = messages.Select(m =>
            {
                //get other user
                var user = UnitOfWork.UserRepository
                           .GetById(thisUser.Id != m.SenderId ? m.SenderId : m.ReceiverId);
                var newMessagesCount = UnitOfWork.MessageRepository
                                       .GetNewMessagesCount(user.Id, thisUser.Id);
                bool userIsOnline = OnlineWorker.IsOnline(user);
                ConversationReturnModel conversation = Mapper
                                                       .Map <Message, ConversationReturnModel>(m, opt =>
                {
                    opt.Items["User"]             = user;
                    opt.Items["NewMessagesCount"] = newMessagesCount;
                    opt.Items["Online"]           = userIsOnline;
                });
                return(conversation);
            });
            var pageCount = UnitOfWork.MessageRepository.
                            GetLastMessagesPageCount(thisUser.Id, MessagesPerPage);

            Clients.Caller.OnGetConversations(conversations, pageCount);
        }