/// <summary> /// update a todo item Update a todo to the system /// </summary> /// <exception cref="Todos.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id">The todo item id</param> /// <param name="updateTodoItem">Inventory todo to update (optional)</param> /// <returns>ApiResponse of Object(void)</returns> public Todos.Client.ApiResponse <Object> UpdateTodoWithHttpInfo(decimal id, UpdateTodoItem updateTodoItem = null) { // verify the required parameter 'id' is set if (id == null) { throw new Todos.Client.ApiException(400, "Missing required parameter 'id' when calling TodosApi->UpdateTodo"); } Todos.Client.RequestOptions requestOptions = new Todos.Client.RequestOptions(); String[] @contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] @accepts = new String[] { }; var localVarContentType = Todos.Client.ClientUtils.SelectHeaderContentType(@contentTypes); if (localVarContentType != null) { requestOptions.HeaderParameters.Add("Content-Type", localVarContentType); } var localVarAccept = Todos.Client.ClientUtils.SelectHeaderAccept(@accepts); if (localVarAccept != null) { requestOptions.HeaderParameters.Add("Accept", localVarAccept); } if (id != null) { requestOptions.PathParameters.Add("id", Todos.Client.ClientUtils.ParameterToString(id)); // path parameter } requestOptions.Data = updateTodoItem; // make the HTTP request var response = this.Client.Put <Object>("/api/todos/{id}", requestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception exception = this.ExceptionFactory("UpdateTodo", response); if (exception != null) { throw exception; } } return(response); }
public void Handle(UpdateTodoItem command) { var id = command.Id; var item = (from i in context.TodoItems where i.Id == id select i).First(); item.Description = command.Description; item.IsDone = command.IsDone; context.SaveChanges(); }
public void Put(Guid id, [FromBody] TodoItem value) { var command = new UpdateTodoItem { Id = id, Description = value.Description, IsDone = value.IsDone, }; var service = new UpdateTodoItemService(context); service.Handle(command); }
public async Task <ActionResult <TodoItem> > Put(UpdateTodoItem request) { var validationResult = updateTodoItemValidator.Validate(request); if (!validationResult.IsValid) { throw new ValidationException(validationResult.ToString()); } var todoItem = await mediator.Send(request); return(todoItem); }
public async Task Put(int id, [FromBody] UpdateTodoItem viewModel) { TodoItem itemToUpdate = await _database.Query <TodoItem>().FirstOrDefaultAsync(i => i.Id == id); if (itemToUpdate == null) { return; } itemToUpdate.IsCompleted = viewModel.IsCompleted; _database.Update(itemToUpdate); await _database.SaveChangesAsync(); }
public async Task <ActionResult> Edit([ Bind(Include = "Id,Description")] TodoItemCommandModel model, CancellationToken cancellationToken) { if (ModelState.IsValid) { var command = new UpdateTodoItem(model.Id, model.Description); var envelope = new Envelope(command); await MessageBus.Send(envelope, cancellationToken); return(RedirectToAction("Index")); } return(View(model)); }
/// <summary> /// adds a todo item Adds a todo to the system /// </summary> /// <exception cref="Todos.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="updateTodoItem">Inventory todo to add (optional)</param> /// <returns>ApiResponse of Object(void)</returns> public Todos.Client.ApiResponse <Object> AddTodoWithHttpInfo(UpdateTodoItem updateTodoItem = null) { Todos.Client.RequestOptions requestOptions = new Todos.Client.RequestOptions(); String[] @contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] @accepts = new String[] { }; var localVarContentType = Todos.Client.ClientUtils.SelectHeaderContentType(@contentTypes); if (localVarContentType != null) { requestOptions.HeaderParameters.Add("Content-Type", localVarContentType); } var localVarAccept = Todos.Client.ClientUtils.SelectHeaderAccept(@accepts); if (localVarAccept != null) { requestOptions.HeaderParameters.Add("Accept", localVarAccept); } requestOptions.Data = updateTodoItem; // make the HTTP request var response = this.Client.Post <Object>("/api/todos", requestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception exception = this.ExceptionFactory("AddTodo", response); if (exception != null) { throw exception; } } return(response); }
public async Task Handle( Envelope <UpdateTodoItem> envelope, CancellationToken cancellationToken) { UpdateTodoItem command = envelope.Message; Guid messageId = envelope.MessageId; TodoItem todoItem = await _repository.Find(command.TodoItemId, cancellationToken); if (todoItem == null) { throw new InvalidOperationException( $"Cannot find todo item with id '{command.TodoItemId}'."); } todoItem.Update(command.Description); await _repository.Save(todoItem, messageId, cancellationToken); }
/// <summary> /// adds a todo item Adds a todo to the system /// </summary> /// <exception cref="Todos.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="updateTodoItem">Inventory todo to add (optional)</param> /// <returns></returns> public void AddTodo(UpdateTodoItem updateTodoItem = null) { AddTodoWithHttpInfo(updateTodoItem); }
/// <summary> /// adds an Todo item /// </summary> /// <remarks> /// Adds an item to the system /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='todoItem'> /// Todo item to add /// </param> public static void AddTodo(this ISimpleTodoAPI operations, UpdateTodoItem todoItem = default(UpdateTodoItem)) { operations.AddTodoAsync(todoItem).GetAwaiter().GetResult(); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// Todo item id /// </param> /// <param name='todoItem'> /// Todo item to update /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task UpdateTodoAsync(this ISimpleTodoAPI operations, double id, UpdateTodoItem todoItem = default(UpdateTodoItem), CancellationToken cancellationToken = default(CancellationToken)) { (await operations.UpdateTodoWithHttpMessagesAsync(id, todoItem, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// Todo item id /// </param> /// <param name='todoItem'> /// Todo item to update /// </param> public static void UpdateTodo(this ISimpleTodoAPI operations, double id, UpdateTodoItem todoItem = default(UpdateTodoItem)) { operations.UpdateTodoAsync(id, todoItem).GetAwaiter().GetResult(); }
/// <param name='id'> /// Todo item id /// </param> /// <param name='todoItem'> /// Todo item to update /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="HttpOperationException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <HttpOperationResponse> UpdateTodoWithHttpMessagesAsync(double id, UpdateTodoItem todoItem = default(UpdateTodoItem), Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (todoItem != null) { todoItem.Validate(); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("id", id); tracingParameters.Add("todoItem", todoItem); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "UpdateTodo", tracingParameters); } // Construct URL var _baseUrl = BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/todos/{id}").ToString(); _url = _url.Replace("{id}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(id, SerializationSettings).Trim('"'))); // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("PUT"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (todoItem != null) { _requestContent = SafeJsonConvert.SerializeObject(todoItem, SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 202 && (int)_statusCode != 404) { var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); if (_httpResponse.Content != null) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); } else { _responseContent = string.Empty; } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
/// <summary> /// update a todo item Update a todo to the system /// </summary> /// <exception cref="Todos.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id">The todo item id</param> /// <param name="updateTodoItem">Inventory todo to update (optional)</param> /// <returns>Task of ApiResponse</returns> public async System.Threading.Tasks.Task <Todos.Client.ApiResponse <Object> > UpdateTodoAsyncWithHttpInfo(decimal id, UpdateTodoItem updateTodoItem = null) { // verify the required parameter 'id' is set if (id == null) { throw new Todos.Client.ApiException(400, "Missing required parameter 'id' when calling TodosApi->UpdateTodo"); } Todos.Client.RequestOptions requestOptions = new Todos.Client.RequestOptions(); String[] @contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] @accepts = new String[] { }; foreach (var contentType in @contentTypes) { requestOptions.HeaderParameters.Add("Content-Type", contentType); } foreach (var accept in @accepts) { requestOptions.HeaderParameters.Add("Accept", accept); } if (id != null) { requestOptions.PathParameters.Add("id", Todos.Client.ClientUtils.ParameterToString(id)); // path parameter } requestOptions.Data = updateTodoItem; // make the HTTP request var response = await this.AsynchronousClient.PutAsync <Object>("/api/todos/{id}", requestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception exception = this.ExceptionFactory("UpdateTodo", response); if (exception != null) { throw exception; } } return(response); }
/// <summary> /// update a todo item Update a todo to the system /// </summary> /// <exception cref="Todos.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id">The todo item id</param> /// <param name="updateTodoItem">Inventory todo to update (optional)</param> /// <returns>Task of void</returns> public async System.Threading.Tasks.Task UpdateTodoAsync(decimal id, UpdateTodoItem updateTodoItem = null) { await UpdateTodoAsyncWithHttpInfo(id, updateTodoItem); }
/// <summary> /// adds a todo item Adds a todo to the system /// </summary> /// <exception cref="Todos.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="updateTodoItem">Inventory todo to add (optional)</param> /// <returns>Task of void</returns> public async System.Threading.Tasks.Task AddTodoAsync(UpdateTodoItem updateTodoItem = null) { await AddTodoAsyncWithHttpInfo(updateTodoItem); }
/// <summary> /// update a todo item Update a todo to the system /// </summary> /// <exception cref="Todos.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id">The todo item id</param> /// <param name="updateTodoItem">Inventory todo to update (optional)</param> /// <returns></returns> public void UpdateTodo(decimal id, UpdateTodoItem updateTodoItem = null) { UpdateTodoWithHttpInfo(id, updateTodoItem); }
/// <summary> /// adds a todo item Adds a todo to the system /// </summary> /// <exception cref="Todos.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="updateTodoItem">Inventory todo to add (optional)</param> /// <returns>Task of ApiResponse</returns> public async System.Threading.Tasks.Task <Todos.Client.ApiResponse <Object> > AddTodoAsyncWithHttpInfo(UpdateTodoItem updateTodoItem = null) { Todos.Client.RequestOptions requestOptions = new Todos.Client.RequestOptions(); String[] @contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] @accepts = new String[] { }; foreach (var contentType in @contentTypes) { requestOptions.HeaderParameters.Add("Content-Type", contentType); } foreach (var accept in @accepts) { requestOptions.HeaderParameters.Add("Accept", accept); } requestOptions.Data = updateTodoItem; // make the HTTP request var response = await this.AsynchronousClient.PostAsync <Object>("/api/todos", requestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception exception = this.ExceptionFactory("AddTodo", response); if (exception != null) { throw exception; } } return(response); }