Exemple #1
0
        public async Task <ActionResult> DeleteMessage(int messageId, CancellationToken cancellationToken)
        {
            var user = await _usersService.GetUserByNameAsync(UserName);

            var message = await _messageService.GetMessageByIdAsync(messageId);

            if (user == null)
            {
                return(NotFound());
            }

            if (message == null)
            {
                return(NotFound());
            }

            if (!await _authorizationService.CanUserViewMessageAsync(user.UserId, messageId))
            {
                return(Unauthorized());
            }

            if (message.SendingUserId == UserId)
            {
                await _messageService.MarkMessageAsDeletedAsync(messageId, cancellationToken);
            }
            else
            {
                await _messageService.MarkMessageRecipientAsDeletedAsync(messageId, UserId, cancellationToken);
            }

            return(Ok());
        }