public IActionResult Create([FromBody] NewTodoModel model) { var token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", string.Empty); if (_userService.Validate(token) != null) { var todo = _mapper.Map <NewTodo>(model); try { _newTodoRepository.AddTodo(todo); _newTodoRepository.Save(); IEnumerable <NewTodo> todoList = _newTodoRepository.GetAllTodosById(model.NewCategoryId); var todos = _mapper.Map <IEnumerable <NewTodo> >(todoList); return(Ok(new { todos })); } catch (Exception ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } } else { return(Unauthorized(new { message = "Invalid Token" })); } }
public async Task <IActionResult> Index(NewTodoModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else { var todo = new Domain.Entities.TodoItem() { CreateTime = DateTimeOffset.Now, ModifyTime = DateTimeOffset.Now, IsComplete = false, Name = model.Name }; var step1 = new Domain.Entities.TodoItemStep() { Index = 1, Name = "步骤1" }; todo.AddStep(step1); await _todoItemRepository.AddAsync(todo); } return(RedirectToAction(actionName: nameof(Index))); }
public async Task <TodoModel> CreateNewTask([FromBody] NewTodoModel model) { var command = new CreateNewTodoCommand { Title = model.Title, DueDate = model.DueDate }; return(await Mediator.Send(command)); }
public async Task <IActionResult> Post([FromBody] NewTodoModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var todo = new TodoItem() { Name = model.Name, IsComplete = false, CreateTime = DateTimeOffset.Now, ModifyTime = DateTimeOffset.Now }; await _todoItemRepository.AddAsync(todo); return(Ok(todo)); }