public async Task <IActionResult> CreateTodoItemAsync([FromBody] Client.TodoCreationInfo creationInfo, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (creationInfo == null) { var error = ServiceErrorResponses.BodyIsMissing("TodoCreationInfo"); return(BadRequest(error)); } if (!HttpContext.Items.TryGetValue("userId", out var userId) || !Guid.TryParse(userId.ToString(), out var userGuid)) { var error = ServiceErrorResponses.UnAuthorized(); return(BadRequest(error)); } var modelCreationInfo = Converter.TodoCreationInfoConverter.Convert(userGuid, creationInfo); var modelTodoItem = await repository.CreateAsync(modelCreationInfo, cancellationToken).ConfigureAwait(false); var clientTodoItem = Converter.TodoItemConverter.Convert(modelTodoItem); var routeParams = new Dictionary <string, object> { { "todoId", clientTodoItem.Id } }; return(CreatedAtRoute("GetTodoItem", routeParams, clientTodoItem)); }
public async Task CreateAsync(string title) { await _repository.CreateAsync(new Todo { Title = title, CreatedAt = DateTime.UtcNow }); }
public async Task <IActionResult> Post(TodoViewModel todoViewModel) { var todo = _mapper.Map <Todo>(todoViewModel); var id = await _todoRepository.CreateAsync(todo); todoViewModel.Id = id; return(Created("/todo/" + id, todoViewModel)); }
public async Task <IActionResult> Create(TodoItemModel model) { if (ModelState.IsValid) { var result = await _repository.CreateAsync(model); return(RedirectToAction(nameof(Index))); } return(BadRequest()); }
public async Task <IActionResult> Post([FromBody] TodoItemModel model) { try { var result = await _repository.CreateAsync(model); model.Id = result; return(Ok(model)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to create task!")); } }
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); }
public async Task TestAddDelete() { var item = new TodoItemModel() { IsCompleted = false, ItemName = "Test Item" }; var Id = await _repository.CreateAsync(item); var newItem = await _repository.GetAsync(Id); var deletedStatus = await _repository.DeleteAsync(Id); var deleted = await _repository.GetAsync(Id); Assert.AreEqual(Id, newItem.Id); Assert.IsNull(deleted); }
public async Task <GenericCommandResponseModel> Handle(CreateTodoRequestModel request, CancellationToken cancellationToken) { // Fail Fast Validation var validationResult = request.Validate(); if (!validationResult.IsValid) { return(new GenericCommandResponseModel(false, "Ops, parece que sua tarefa está errada!", validationResult.Errors)); } // Gera o TodoItem var todo = new TodoItem(request.Title, request.User, request.Date); // Salva no banco await _repository.CreateAsync(todo); // Retorna o resultado return(new GenericCommandResponseModel(true, "Tarefa salva", todo)); }
public async Task <IActionResult> Create([Bind("Name,Description,IsDone")] TodoViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _userManager.FindByNameAsync(User.Identity.Name); var entity = new Todo { CreatedDateTime = DateTime.Now, UserId = user.Id, Name = model.Name, Description = model.Description, IsDone = model.IsDone }; await _todoRepository.CreateAsync(entity); return(RedirectToAction(nameof(Index))); }
public Task <Api.Model.Todo> CreateOneTimeTodo(string summary, string description) { var todo = new Api.Model.Todo(summary, description, null); return(_todoRepository.CreateAsync(todo)); }
public async Task <TodoItemDto> CreateAsync(Todoitem toDoItem) { return(Mapper.Map <TodoItemDto>(await _dorepo.CreateAsync(toDoItem))); }
public async Task <TodoItem> CreateAsync(TodoItem todoItem) { return(await _todoRepository.CreateAsync(todoItem)); }