public ValidationResponse CreateTodo(CreateTodoRequest request) { ValidationResponse response = new ValidationResponse(); if (request == null || string.IsNullOrWhiteSpace(request.Username) || string.IsNullOrWhiteSpace(request.Token)) { response.Error = "Need to login"; return(response); } User user = context.Users.FirstOrDefault(u => u.Name == request.Username && u.Token == request.Token); if (user == null) { response.Error = "Need to login"; return(response); } var todo = new ToDo(); todo.User = user; todo.Text = request.TodoText; context.Entry(todo).State = EntityState.Added; context.SaveChanges(); return(response); }
public async Task <IActionResult> CreateTodo(CreateTodoRequest createTodoRequest) { try { _logger.LogInformation($"Creating a new to-do"); Todo todo = new Todo { Id = Guid.NewGuid().ToString(), Name = createTodoRequest.Name, Description = createTodoRequest.Description, IsComplete = createTodoRequest.IsComplete }; await _todoRepository.AddItemAsync(todo); return(Ok()); } catch (Exception ex) { _logger.LogError(ex, "Exception caught!"); return(BadRequest(new ApiResult { Error = "An error has occured" })); } }
private async Task CreateTodo() { // Given: var client = Factory.CreateClient(); // And: var createTodoRequest = new CreateTodoRequest() { Name = "Water Plants" }; // And: HttpContent httpContent = new StringContent( JsonConvert.SerializeObject(createTodoRequest), Encoding.UTF8, "application/json" ); // When: var response = await client.PostAsync("/api/Todos", httpContent); var responseBody = await response.Content.ReadAsStringAsync(); var responseDTO = JsonConvert.DeserializeObject <TodoDTO>(responseBody); // Then: Assert.Equal(1, responseDTO.Id); Assert.Equal("Water Plants", responseDTO.Name); Assert.Equal(false, responseDTO.Completed); }
public override Task <CreateTodoResponse> Create(CreateTodoRequest request, ServerCallContext context) { return(Task.FromResult(new CreateTodoResponse { Id = 1, })); }
public async Task <TodoItem> Post( [FromBody] CreateTodoRequest request, [FromServices] CreateTodoHandler handler) { var result = await handler.HandleAsync(request); return(result); }
public async Task <IActionResult> Create([FromBody] CreateTodoRequest createTodoRequest) { if (!ModelState.IsValid) { } Todos newTodos = new Todos { Name = createTodoRequest.TodoName, UserId = HttpContext.GetUserId() }; return(Ok(await _todosService.getAllTodosAsync())); }
public async Task <ActionResult <TodoDTO> > PostTodo(CreateTodoRequest request) { var result = await TodoService.CreateTodoAsync( new Core.Models.Todo() { Name = request.Name, Completed = false }); var translatedResult = TodoTranslator.Translate(result); return(CreatedAtAction(nameof(GetTodo), new { translatedResult.Id }, translatedResult)); }
public async Task <TodoItem> HandleAsync(CreateTodoRequest request) { var todo = new TodoItem { Title = request.Title, Done = false, CreateDate = DateTime.Now, LastUpdateDate = DateTime.Now }; await _repository.CreateAsync(todo); return(todo); }
protected override async Task <bool> InsertTodosAsync(int todosCount) { var request = new CreateTodoRequest { Request = JsonConvert.SerializeObject(new { ActionTitle = "ActionTitle", ActionDescription = "ActionDescription", }) }; await Task.WhenAll( Task.Run(async() => { for (int i = 0; i < todosCount; i++) { await _client.CreateAsync(request); } }), Task.Run(async() => { for (int i = 0; i < todosCount; i++) { await _client.CreateAsync(request); } }), Task.Run(async() => { for (int i = 0; i < todosCount; i++) { await _client.CreateAsync(request); } }) ); return(true); }
public async Task <IActionResult> Create([FromBody] CreateTodoRequest todoRequest) { if (string.IsNullOrEmpty(todoRequest.Name)) { return(BadRequest()); } var newTodoId = Guid.NewGuid(); var todo = new Todo { Id = newTodoId, Name = todoRequest.Name, IsCompleted = todoRequest.IsCompleted }; await _todoService.CreateTodoAsync(todo); var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; var locationUri = baseUrl + "/" + ApiRoutes.Todos.Get.Replace("{todoId}", newTodoId.ToString()); return(Created(locationUri, _mapper.Map <TodoResponse>(todo))); }
public ValidationResponse CreateTodo([FromBody] CreateTodoRequest request) { return(toDoService.CreateTodo(request)); }
public Task <IActionResult> Create(CreateTodoRequest request) { return(Task.FromResult <IActionResult>(Created(nameof(Create), 1))); }
public Task <int> Handle(CreateTodoRequest request, CancellationToken cancellationToken) { return(TodoStorageService.CreateAsync(request.Content)); }
public async Task <ActionResult <Guid> > Create([FromBody] CreateTodoRequest request) { return(await _mediator.Send(request)); }