public IActionResult Edit(int todoItemId)
        {
            var todoItem = dbContext.SingleTodoItem(todoItemId);
            var fields   = TodoItemEditFieldsFactory.Create(todoItem);

            return(View(fields));
        }
Beispiel #2
0
        public async Task <IActionResult> EditListItem([FromBody] TodoItemEditFields fields)
        {
            var responsibleParty = await dbContext.Users.FirstOrDefaultAsync(user => user.Id == fields.ResponsiblePartyId);

            if (responsibleParty == null)
            {
                ModelState.AddModelError(nameof(fields.ResponsiblePartyId), "Responsible party does not exist");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingTodoItem = await dbContext.TodoItems
                                   .Include(item => item.TodoList)
                                   .FirstOrDefaultAsync(item => item.TodoItemId == fields.TodoItemId);

            if (existingTodoItem == null)
            {
                return(NotFound());
            }

            TodoItemEditFieldsFactory.Update(fields, existingTodoItem);

            dbContext.Update(existingTodoItem);
            await dbContext.SaveChangesAsync();

            return(Ok(TodoItemEditFieldsFactory.Create(existingTodoItem)));
        }
        public WhenTodoItemIsConvertedToEditFields()
        {
            var todoList = new TestTodoListBuilder(new IdentityUser("*****@*****.**"), "shopping")
                           .WithItem("bread", Importance.High)
                           .Build();

            srcTodoItem = todoList.Items.First();

            resultFields = TodoItemEditFieldsFactory.Create(srcTodoItem);
        }
        public async Task <IActionResult> Edit(TodoItemEditFields fields)
        {
            if (!ModelState.IsValid)
            {
                return(View(fields));
            }

            var todoItem = dbContext.SingleTodoItem(fields.TodoItemId);

            TodoItemEditFieldsFactory.Update(fields, todoItem);

            dbContext.Update(todoItem);
            await dbContext.SaveChangesAsync();

            return(RedirectToListDetail(todoItem.TodoListId));
        }