private bool PutProcessing(Bundle.EntryComponent PutEntry, int PutEntryIndex) { IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set(PutEntry.Request); RequestMeta.RequestHeader.Prefer = _RequestHeader.Prefer; IResourceServiceOutcome ResourceServiceOutcome = null; if (RequestMeta.SearchParameterGeneric.ParameterList.Count > 0) { ResourceServiceOutcome = IResourceServices.ConditionalPut(PutEntry.Resource, RequestMeta); } else { ResourceServiceOutcome = IResourceServices.Put(RequestMeta.PyroRequestUri.FhirRequestUri.ResourceId, PutEntry.Resource, RequestMeta); } if (ResourceServiceOutcome.SuccessfulTransaction) { PutEntry.FullUrl = CreateFullUrl(ResourceServiceOutcome); PutEntry.Response = new Bundle.ResponseComponent(); PutEntry.Response.Status = FormatHTTPStatusCodeAsString(ResourceServiceOutcome.HttpStatusCode); if (ResourceServiceOutcome.ResourceResult != null) { if (ResourceServiceOutcome.ResourceResult.ResourceType == ResourceType.OperationOutcome) { PutEntry.Response.Outcome = ResourceServiceOutcome.ResourceResult; } else { PutEntry.Resource = ResourceServiceOutcome.ResourceResult; } } if (ResourceServiceOutcome.LastModified != null) { PutEntry.Response.Etag = HttpHeaderSupport.GetEntityTagHeaderValueFromVersion(ResourceServiceOutcome.ResourceVersionNumber).ToString(); PutEntry.Response.LastModified = ResourceServiceOutcome.LastModified; PutEntry.Response.Location = FormatResponseLocation(RequestMeta.PyroRequestUri.FhirRequestUri.OriginalString, ResourceServiceOutcome.FhirResourceId, ResourceServiceOutcome.ResourceVersionNumber); } return(true); } else { if (ResourceServiceOutcome.ResourceResult != null && ResourceServiceOutcome.ResourceResult is OperationOutcome Op) { IdentifieBatchEntityToClient(Op, PutEntry.FullUrl, "PUT", PutEntryIndex); } _ServiceOperationOutcome = ResourceServiceOutcome; return(false); } }
public IResourceServiceOutcome ConditionalPut(string BaseRequestUri, HttpRequestMessage Request, string ResourceName, Resource resource) { using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction()) { try { IRequestServiceRootValidate.Validate(BaseRequestUri); IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set(Request); IResourceServiceOutcome ResourceServiceOutcome = IResourceApiServices.ConditionalPut(resource, RequestMeta); ResourceServiceOutcome.SummaryType = RequestMeta.SearchParameterGeneric.SummaryType; Transaction.Commit(); return(ResourceServiceOutcome); } catch (Exception Exec) { Transaction.Rollback(); ILog.Error(Exec, $"PyroService.ConditionalPut, Request: {Request.RequestUri.OriginalString}"); throw new PyroException(System.Net.HttpStatusCode.InternalServerError, Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Exception, Exec.Message), Exec.Message); } } }