public async Task <IActionResult> Create(TodoItemCreateFields fields)
        {
            if (!ModelState.IsValid)
            {
                return(View(fields));
            }

            await _todoItemRepository.CreateAsync(fields);

            return(RedirectToListDetail(fields.TodoListId));
        }
예제 #2
0
        public async Task <TodoItemGetViewModel> CreateAsync(TodoItemCreateViewModel value)
        {
            TodoItem item = new TodoItem
            {
                Content   = value.Content,
                CreatedAt = DateTime.Now
            };
            var model = await _repository.CreateAsync(item);

            var viewmodel = _mapper.Map <TodoItemGetViewModel>(model);

            return(viewmodel);
        }
예제 #3
0
        public async Task <ActionResult <TodoItemModel> > Save(
            [FromBody] TodoItemModel model
            )
        {
            try {
                var user = await userMgr.FindByNameAsync(User.Identity.Name);

                model.UserId   = user.Id;
                model.UserName = user.UserName;
                await repo.CreateAsync(model);

                return(model);
            }
            catch (Exception ex) {
                logger.LogError(ex, "Can not save todo items.");
                return(StatusCode(500));
            }
        }