Ejemplo n.º 1
0
        private void MockData()
        {
            _messages = new List <SuggestionMessage>
            {
                new SuggestionMessage()
                {
                    Id      = 1,
                    Summary = "Error",
                    Text    = "Some text",
                    State   = MessageState.Read,
                },
                new SuggestionMessage()
                {
                    Id      = 2,
                    Summary = "Suggest",
                    Text    = "Some text 2",
                    State   = MessageState.Unread,
                },
            };

            _messagesDto = _messages.Select(message => new SuggestionMessageDto
            {
                Id      = message.Id,
                Summary = message.Summary,
                Text    = message.Text,
                State   = message.State
            });

            _messagesQueryableMock = _messages.AsQueryable().BuildMock();
            _message    = _messages.FirstOrDefault();
            _messageDto = _messagesDto.FirstOrDefault();
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <SuggestionMessageDto> > PostMessage([FromBody] SuggestionMessageDto messageDto)
        {
            _logger.LogInformation($"Post message {messageDto}", messageDto);
            var insertedMessage = await _messageService.Add(messageDto);

            return(Created("GetMessage", insertedMessage));
        }
Ejemplo n.º 3
0
        public async Task <bool> Update(SuggestionMessageDto messageDto)
        {
            var message = _mapper.Map <SuggestionMessage>(messageDto);

            _messageRepository.Update(message);
            var affectedRows = await _messageRepository.SaveChangesAsync();

            return(affectedRows > 0);
        }
Ejemplo n.º 4
0
        public async Task <int> Add(SuggestionMessageDto messageDto)
        {
            var message = _mapper.Map <SuggestionMessage>(messageDto);

            _messageRepository.Add(message);
            await _messageRepository.SaveChangesAsync();

            return(message.Id);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutMessage(SuggestionMessageDto messageDto)
        {
            _logger.LogInformation($"Update message {messageDto}", messageDto);
            var updated = await _messageService.Update(messageDto);

            if (!updated)
            {
                _logger.LogWarning($"Update message ({messageDto}) NOT FOUND", messageDto);

                return(NotFound());
            }

            return(NoContent());
        }