public ActionResult <ContentDto> UpdateContent(ContentUpdateDto content, [FromHeader] string key) { if (!authService.Authorize(key)) { return(StatusCode(StatusCodes.Status401Unauthorized, "The user is not authorized!")); } if (objectForSaleMockRepository.GetObjectForSaleByID(content.ItemForSaleID) == null) { return(StatusCode(StatusCodes.Status400BadRequest, "Object for sale with that id does not exist!")); } try { var oldContent = contentRepository.GetContentById(content.ContentId); if (oldContent == null) { return(NotFound()); } Content contentEntity = mapper.Map <Content>(content); mapper.Map(contentEntity, oldContent); contentRepository.SaveChanges(); fakeLoggerRepository.Log(LogLevel.Information, contextAccessor.HttpContext.TraceIdentifier, "", "Content updated", null); return(Ok(mapper.Map <ContentDto>(oldContent))); } catch (Exception) { fakeLoggerRepository.Log(LogLevel.Error, contextAccessor.HttpContext.TraceIdentifier, "", "Error with updating content", null); return(StatusCode(StatusCodes.Status500InternalServerError, "Update error")); } }
public async Task ShouldUpdateAsync() { string newValue = "Newly created fresh value"; var updateDto = new ContentUpdateDto { Value = newValue }; await _service.UpdateAsync(_data.Content_1_Id, updateDto); var content = await _service.GetAsync(_data.Content_1_Id); content.ShouldNotBeNull(); content.Value.ShouldBe(newValue); }