Ejemplo n.º 1
0
        public void TestGetCreate()
        {
            var entity = new Chat();

            entity.Id = "testId";

            _repository.Create(entity);

            Assert.Equal(entity, _repository.GetById("testId"));
        }
Ejemplo n.º 2
0
        public async Task <Message> PostMessage(Message sendMessage)
        {
            Message message = new Message
            {
                SenderId   = sendMessage.SenderId,
                Content    = sendMessage.Content,
                ReceiverId = sendMessage.ReceiverId
            };

            message.ContactId = HashUsers(message.SenderId, message.ReceiverId);
            message.Timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            return(await _ChatRepository.Create(message));
        }
Ejemplo n.º 3
0
        public IHttpActionResult LoadData()
        {
            User user1 = new User();

            user1.id       = 1;
            user1.name     = "Andre";
            user1.email    = "*****@*****.**";
            user1.password = "******";
            _users.Register(user1);
            User user2 = new User();

            user2.id       = 2;
            user2.name     = "Dan";
            user2.email    = "*****@*****.**";
            user2.password = "******";
            _users.Register(user2);
            Chat chat1 = new Chat();

            chat1.id      = 1;
            chat1.user_id = 1;
            chat1.name    = "A chat";
            chat1.created = new DateTime(2016, 07, 12, 4, 30, 21);
            _chats.Create(user1, chat1);
            Chat chat2 = new Chat();

            chat2.id      = 1;
            chat2.user_id = 1;
            chat2.name    = "A chat 2";
            chat2.created = new DateTime(2016, 07, 14, 12, 30, 21);
            _chats.Create(user2, chat2);
            Message message1 = new Message();

            message1.id      = 1;
            message1.chat_id = 1;
            message1.user_id = 1;
            message1.message = "Hey there!";
            message1.created = new DateTime(2016, 07, 12, 04, 32, 21);
            _messages.Create(chat1, message1);
            Message message2 = new Message();

            message2.id      = 2;
            message2.chat_id = 1;
            message2.user_id = 2;
            message2.message = "Oh hey!";
            message2.created = new DateTime(2016, 07, 12, 06, 30, 21);
            _messages.Create(chat1, message2);
            return(Ok());
        }
Ejemplo n.º 4
0
        public HttpResponseMessage Post(int userId, Chat chat)
        {
            chatRepository.Create(userId, chat);
            chat.Created = DateTime.Now;
            chatRepository.Save();
            var response = Request.CreateResponse <Chat>(HttpStatusCode.Created, chat);

            return(response);
        }
        public async Task <Chat> InitializeChat(InitializeModel initModel)
        {
            var newChat = new Chat()
            {
                Buyer    = initModel.Buyer,
                Seller   = initModel.Seller,
                Messages = new List <Message>()
            };
            var chatExists = await _repository.FindChat(newChat.Buyer, newChat.Seller);

            if (chatExists != null)
            {
                throw new ChatAlreadyExistsException(chatExists.Id);
            }

            return(await _repository.Create(newChat));
        }
Ejemplo n.º 6
0
        public async Task <ChatDto> Handle(CreateChatCommand request, CancellationToken cancellationToken)
        {
            var chatExists = _context.Chats
                             .AsQueryable()
                             .Any(chat => chat.Name == request.Name && chat.OwnerId == request.OwnerId);

            if (chatExists)
            {
                throw new ChatApiException("Could not create chat",
                                           new[] { $"Chat with name {request.Name} already exists for user {request.OwnerId}" });
            }

            var owner = await _usersApiClient.GetUserById(request.OwnerId);

            var chatEntity = new Chat(request.Name, new User(owner.Id, owner.UserName), request.Capacity);

            _chatRepository.Create(chatEntity);
            await _chatRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(_mapper.Map <ChatDto>(chatEntity));
        }
Ejemplo n.º 7
0
 public void Create(ChatCreateRequest chatCreateRequest)
 {
     _chatRepository.Create(chatCreateRequest);
     List(true);
 }