public static Model.MedicNotePatchInfo Convert(Guid id, string medicName, Client.MedicNotePatchInfo clientPatchInfo) { if (clientPatchInfo == null) { throw new ArgumentNullException(nameof(clientPatchInfo)); } Permission?permission = null; if (Enum.TryParse(clientPatchInfo.Permission, out Permission perm)) { permission = perm; } var modelPatchInfo = new Model.MedicNotePatchInfo(id, clientPatchInfo.Complaints, clientPatchInfo.Temperature, clientPatchInfo.Pressure, clientPatchInfo.Pulse, clientPatchInfo.AlcoholIntoxication, clientPatchInfo.DrugIntoxication, medicName, permission); return(modelPatchInfo); }
public async Task <IActionResult> PatchMedicNoteAsync([FromRoute] string id, [FromBody] Client.MedicNotePatchInfo patchInfo, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (patchInfo == null) { var error = ErrorResponsesService.BodyIsMissing(nameof(patchInfo)); return(BadRequest(error)); } if (!Guid.TryParse(id, out var guid)) { var error = ErrorResponsesService.NotFoundError(Target, $"MedicNote with id '{id}' not found."); return(NotFound(error)); } var userName = HttpContext.User.Identity.Name; var user = await userManager.FindByNameAsync(userName); var modelPatchInfo = Converter.MedicNotePatchInfoConverter.Convert(guid, user.Name, patchInfo); Model.MedicNote modelMedicNote; try { modelMedicNote = await repository.PatchAsync(modelPatchInfo, cancellationToken).ConfigureAwait(false); } catch (MedicNoteNotFoundException ex) { var error = ErrorResponsesService.NotFoundError(Target, ex.Message); return(NotFound(error)); } var clientMedicNote = Converter.MedicNoteConverter.Convert(modelMedicNote); return(Ok(clientMedicNote)); }