public async Task <IActionResult> UpdateTemplateData([FromRoute] int id, [FromBody] TemplateUpdateInput newTemplateData) { LogBeginOfRequest(); if (!ModelState.IsValid) { LogEndOfRequest("Failed Bad Request", 400); return(BadRequest(ModelState)); } try { var command = new UpdateTemplateDataCommand(id, newTemplateData); await templateService.UpdateTemplateDataCommand.HandleAsync(command); LogEndOfRequest("Success", 204); return(NoContent()); } catch (KeyNotFoundException) { LogEndOfRequest($"Failed template with id {id} not found", 404); return(NotFound()); } catch (DbUpdateConcurrencyException) { if (!await repository.Templates.Exists(id)) { LogEndOfRequest($"Failed template with id {id} not found", 404); return(NotFound()); } else { LogWarning("Database concurency exception", 500); return(StatusCode(500)); } } }
public UpdateTemplateDataCommand(int id, TemplateUpdateInput templateUpdateInput) { TemplateId = id; TemplateUpdate = templateUpdateInput; }