public async Task <IActionResult> CreateElement([FromBody] CoreElementViewModel element) { if (!_healthService.IsStateHealthy) { return(StatusCode(StatusCodes.Status500InternalServerError)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var newElement = await _persistentStorageService.CreateAsync(element); return(CreatedAtRoute("GetElementId", new CoreElementViewModel { Id = newElement }, newElement.ToString())); } catch { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <IActionResult> UpdateElement(string id, [FromBody] CoreElementViewModel element) { if (!_healthService.IsStateHealthy) { return(StatusCode(StatusCodes.Status500InternalServerError)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!Guid.TryParse(id, out var elementId)) { return(BadRequest()); } if (element.Id != elementId) { return(BadRequest()); } try { await _persistentStorageService.UpdateAsync(element); return(Ok()); } catch { return(StatusCode(StatusCodes.Status500InternalServerError)); } }