예제 #1
0
        public ActionResult PatchTag(long id, JsonPatchDocument <TagUpdateDto> jsonPatchDocument)
        {
            _logger.LogInformation("Consultando a tag de Id: {id}", id);
            Tag tag = _repository.GetTagById(id);

            if (tag == null)
            {
                _logger.LogWarning("A tag de Id: {id} não existe", id);
                return(NotFound());
            }

            _logger.LogInformation("Aplicando a alteração na classe de DTO");
            TagUpdateDto tagUpdateDto = _mapper.Map <TagUpdateDto>(tag);

            jsonPatchDocument.ApplyTo(tagUpdateDto, ModelState);

            _logger.LogInformation("Validando a alteração na classe de DTO");
            if (!TryValidateModel(tagUpdateDto))
            {
                return(ValidationProblem(ModelState));
            }

            _logger.LogInformation("Alterando a tag de Id: {id}", id);
            _mapper.Map(tagUpdateDto, tag);
            _repository.SaveChanges();

            return(NoContent());
        }
예제 #2
0
 public virtual async Task <TagDto> UpdateAsync(Guid id, TagUpdateDto input)
 {
     return(await RequestAsync <TagDto>(nameof(UpdateAsync), new ClientProxyRequestTypeValue
     {
         { typeof(Guid), id },
         { typeof(TagUpdateDto), input }
     }));
 }
예제 #3
0
    public async Task <TagDto> UpdateAsync(Guid id, TagUpdateDto input)
    {
        var tag = await TagManager.UpdateAsync(
            id,
            input.Name);

        tag.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);

        await Repository.UpdateAsync(tag);

        return(ObjectMapper.Map <Tag, TagDto>(tag));
    }
예제 #4
0
        public void PutTag_ValidIdPassed_ReturnsNoContent()
        {
            _mockRepository.Setup(r => r.GetTagById(It.IsAny <long>())).Returns(new Tag());

            TagUpdateDto tagUpdateDto = new TagUpdateDto()
            {
                Name = "estudos"
            };

            var noContentResult = _controller.PutTag(5, tagUpdateDto);

            Assert.IsType <NoContentResult>(noContentResult);
        }
예제 #5
0
        public void PutTag_UnknownIdPassed_ReturnsNotFound()
        {
            _mockRepository.Setup(r => r.GetTagById(It.IsAny <long>())).Returns((Tag)null);

            TagUpdateDto tagUpdateDto = new TagUpdateDto()
            {
                Name = "estudos"
            };

            var notFoundResult = _controller.PutTag(5, tagUpdateDto);

            Assert.IsType <NotFoundResult>(notFoundResult);
        }
예제 #6
0
        public ActionResult UpdateTag(TagUpdateDto tagUpdateDto)
        {
            var tagModel = _repository.GetTagById(tagUpdateDto.TagID);

            if (tagModel == null)
            {
                return(NotFound());
            }
            _mapper.Map(tagUpdateDto, tagModel);
            _repository.UpdateTag(tagModel);
            _repository.SaveChanges();
            return(NoContent());
        }
예제 #7
0
        public ActionResult PutTag(long id, TagUpdateDto tagUpdateDto)
        {
            _logger.LogInformation("Consultando a tag de Id: {id}", id);
            Tag tag = _repository.GetTagById(id);

            if (tag == null)
            {
                _logger.LogWarning("A tag de Id: {id} não existe", id);
                return(NotFound());
            }

            _logger.LogInformation("Editando a tag de Id: {id}", id);
            _mapper.Map(tagUpdateDto, tag);
            _repository.SaveChanges();

            return(NoContent());
        }
예제 #8
0
        public async Task <TagDto> UpdateAsync(TagUpdateDto dto)
        {
            if (dto.Id == Guid.Empty)
            {
                throw new ArticleException(ArticleErrorCodes.TagIdCannotBeNull, "Tag Id field is mandatory.", dto);
            }

            var entity = await _tagRepository.GetByIdAsync(dto.Id);

            if (entity == null)
            {
                throw new ArticleException(ArticleErrorCodes.TagCouldNotBeFound, "Tag could not be found.", dto);
            }

            entity.Name = dto.Name;

            entity = await _tagRepository.UpdateAsync(entity);

            return(entity.Adapt <TagDto>());
        }
예제 #9
0
        public void TestUpdate()
        {
            //arrange
            var Api             = new APIService();
            var tagToBeInserted = new TagCreateDto {
                Title = "this tag has just been inserted"
            };

            //act
            var tagList        = Api.GetTable <TagReadDto>("tags");
            var tagToBeUpdated = tagList.Find(x => x.TagID == tagList.Max(t => t.TagID));
            var updatingTag    = new TagUpdateDto
            {
                TagID = tagToBeUpdated.TagID,
                Title = "this just updated the title"
            };
            var tagUpdateResponse = Api.Update("tags", updatingTag);

            //assert
            Assert.IsNotNull(tagUpdateResponse);
        }
예제 #10
0
        public async Task <IActionResult> UpdateTag([FromBody] TagUpdateDto model)
        {
            var result = await _tagService.UpdateAsync(model);

            return(CreatedAtAction(nameof(GetTagById), new { id = result.Id }, null));
        }
예제 #11
0
 public Task <TagDto> UpdateAsync(Guid id, [FromBody] TagUpdateDto input)
 {
     return(TagAdminAppService.UpdateAsync(id, input));
 }
예제 #12
0
        public async Task OnGetAsync()
        {
            var tag = await _tagAppService.GetAsync(Id);

            Tag = ObjectMapper.Map <TagDto, TagUpdateDto>(tag);
        }