Exemple #1
0
        public async Task UpdateMessage(UpdateMessageDto updateMessageDto, string userId)
        {
            var message = await _unitOfWork.MessageRepository.GetByIdAsync(updateMessageDto.MessageID);

            if (message == null)
            {
                throw new Exception("Message doesn't exist");
            }

            if (message.SenderId != userId || message.DeletedForAll || message.DeletedForSender)
            {
                throw new Exception("You can't update this message");
            }

            if (string.IsNullOrEmpty(updateMessageDto.Message))
            {
                throw new ArgumentException("You message text is incorrect");
            }

            using (var transaction = await _unitOfWork.BeginTransactionAsync())
            {
                message.MessageData = updateMessageDto.Message;
                await _unitOfWork.CommitAsync();

                await transaction.CommitAsync();
            }
        }
        public async Task <IActionResult> Update(Guid userID, Guid messageID, UpdateMessageDto updateMessageInfo)
        {
            var message = new Message
            {
                ID       = messageID,
                SenderID = userID
            };

            #region [Authorization]
            var result = await this.AuthorizationService.AuthorizeAsync
                         (
                this.User, message, nameof(KindlyPolicies.AllowIfOwner)
                         );

            if (result.Succeeded == false)
            {
                return(this.Unauthorized());
            }
            #endregion

            this.Mapper.Map(updateMessageInfo, message);

            await this.Repository.Update(message);

            return(this.Ok());
        }
Exemple #3
0
        public async Task <ActionResult> UpdateMessage(UpdateMessageDto updateMessageDto)
        {
            try
            {
                var userId = this.User.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value;
                await _messagesService.UpdateMessage(updateMessageDto, userId);

                return(Ok(MessageControllerConstants.YouMessageIsUpdated));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Exemple #4
0
 public async Task UpdateMessage(string id, UpdateMessageDto input)
 {
     await _messagerespository.Update(input.Content, id);
 }
Exemple #5
0
        public async Task <IActionResult> UpdateMessageAsync(Guid boardId, Guid topicId, Guid messageId, [FromBody] UpdateMessageDto message, [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!MediaTypeHeaderValue.TryParse(mediaType, out MediaTypeHeaderValue parsedMediaType))
            {
                return(BadRequest());
            }

            var messageDto = await _messageService.UpdateMessageAsync(boardId, topicId, messageId, message);

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

            var includeLinks = parsedMediaType.SubTypeWithoutSuffix.EndsWith("hateoas", StringComparison.InvariantCultureIgnoreCase);

            if (includeLinks)
            {
                IEnumerable <LinkDto> links = new List <LinkDto>();
                links = CreateMessageLinks(boardId, topicId, messageDto.Id);
                var messageWithLinks = _mapper.Map <ResponseMessageLinksDto>(messageDto);
                messageWithLinks.Links = links;

                return(Ok(messageWithLinks));
            }

            return(Ok(messageDto));
        }
Exemple #6
0
        public async Task <ResponseMessageDto> UpdateMessageAsync(Guid boardId, Guid topicId, Guid messageId, UpdateMessageDto message)
        {
            var existingTopic = await _messageRepository.GetMessageAsync(messageId);

            var updatedEntity = _mapper.Map(message, existingTopic);

            var returnedEntity = await _messageRepository.UpdateMessageAsync(updatedEntity);

            var responseDto = _mapper.Map <Message, ResponseMessageDto>(returnedEntity);

            return(responseDto);
        }
 public HttpResponseMessage PostSequenceState(UpdateMessageDto um)
 {
     ChainStart.Post(um);
     return(Request.CreateResponse(HttpStatusCode.Accepted));
 }
Exemple #8
0
        public async Task <IActionResult> UpdateMessage(string id, [FromBody] UpdateMessageDto input)
        {
            await _service.UpdateMessage(id, input);

            return(Ok());
        }