コード例 #1
0
            /// <summary>
            /// Create an assignment.
            /// </summary>
            /// <param name="assignment">assignment to create</param>
            /// <returns>Created assignment</returns>
            private async Task <Assignment> CreateAssignment(AssignmentNew assignment)
            {
                var request  = new CreateAssignmentRequest(assignment);
                var response = await base.ExecuteRequestAsync(request);

                return(response.Content);
            }
コード例 #2
0
        //Shared methods
        public static async Task <string> CreateAssignment(AssignmentNew assignment)
        {
            var createRequest  = new CreateAssignmentRequest(assignment);
            var createResponse = await SkyManager.ApiClient.ExecuteRequestAsync(createRequest);

            return(createResponse.Content.Id);
        }
コード例 #3
0
        /// <inheritdoc />
        public async Task <CreateAssignmentResult?> CreateAsync(CreateAssignmentRequest createItem, CancellationToken cancellationToken = default)
        {
            var response = await this.requestExecutor
                           .ReceiveResponse(this.options.TargetUrlWithWorkspace, "/api/v1/assignments", this.options.Credentials, createItem, cancellationToken, "POST")
                           .ConfigureAwait(false);

            string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (response.StatusCode == HttpStatusCode.BadRequest)
            {
                if ("text/json".Equals(response.Content.Headers.ContentType.MediaType, StringComparison.OrdinalIgnoreCase) ||
                    "application/json".Equals(response.Content.Headers.ContentType.MediaType, StringComparison.OrdinalIgnoreCase))
                {
                    var createAssignmentResult = JsonSerializer.Deserialize <CreateAssignmentResult>(responseBody);
                    throw new AssignmentCreationException("Assignment was not created", createAssignmentResult);
                }
            }

            if (!response.IsSuccessStatusCode || responseBody == null)
            {
                throw new ApiCallException("Assignment was not created", responseBody, response);
            }

            return(JsonSerializer.Deserialize <CreateAssignmentResult>(responseBody));
        }
コード例 #4
0
 /// <summary>Snippet for CreateAssignment</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void CreateAssignmentRequestObject()
 {
     // Create client
     ReservationServiceClient reservationServiceClient = ReservationServiceClient.Create();
     // Initialize request argument(s)
     CreateAssignmentRequest request = new CreateAssignmentRequest
     {
         ParentAsReservationName = ReservationName.FromProjectLocationReservation("[PROJECT]", "[LOCATION]", "[RESERVATION]"),
         Assignment = new Assignment(),
     };
     // Make the request
     Assignment response = reservationServiceClient.CreateAssignment(request);
 }
コード例 #5
0
        public async Task <ActionResult> Post([FromBody] CreateAssignmentRequest request)
        {
            try {
                var command = _mapper.Map <CreateAssignmentCommand>(request);
                var id      = await _commandHandler.HandleAsync(command);

                var query = new GetAssignmentDetailQuery {
                    Id = id
                };
                var assignment = await _queryHandler.HandleAsync(query);

                return(CreatedAtAction(nameof(Get), new { id = assignment.Id }, assignment));
            } catch (Exception) {
                return(BadRequest());
            }
        }