public async Task <IActionResult> Put([FromRoute] Guid id, [FromBody] MetaHumanMutateModel metaMutate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MetaHuman metahuman = await this.metasRepository.GetOne(id); if (metahuman == null || id != metahuman.Id) { return(BadRequest()); } if (!string.IsNullOrEmpty(metaMutate.Name)) { metahuman.Name = metaMutate.Name; } if (metaMutate.Description != null) { metahuman.Description = metaMutate.Description; } if (metaMutate.AlterEgo != null) { metahuman.AlterEgo = metaMutate.AlterEgo; } metahuman.UpdatedAt = metaMutate.UpdatedAt; try { await this.metasRepository.UpdateAsync(metahuman); } catch (DbUpdateConcurrencyException) { if (!await this.metasRepository.EntityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task Test4Put() { MetaHumanMutateModel mutateModel = new MetaHumanMutateModel { Name = "TestMetaUpdated", Description = "This is a meta created by the unit test", AlterEgo = "Unit test", Status = 0 }; MetaHumansController controller = new MetaHumansController(_context, null); IActionResult result = await controller.Put(this.id, mutateModel); NoContentResult ok = result as NoContentResult; Assert.NotNull(ok); Assert.Equal(204, ok.StatusCode); }