Exemplo n.º 1
0
        public void ControllerShouldCreateToDoListSucessfully()
        {
            this.FillDatabase();

            this.inputModel = new AddToDoListInputModel
            {
                Name      = "Test List",
                ListItems = new List <string>(),
            };

            this.inputModel.ListItems.Add("test ListItem 1");
            this.inputModel.ListItems.Add("test ListItem 2");

            var result = this.controller.Add(this.inputModel);

            Assert.Equal(4, this.db.ToDoLists.Count());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Add(AddToDoListInputModel input)
        {
            try
            {
                if (!this.ModelState.IsValid)
                {
                    return(this.View(input));
                }

                var user = await this.userManager.GetUserAsync(this.User);

                await this.toDoListsService.AddAsync(user.Id, input.Name, input.ListItems);

                return(this.Redirect("/ToDoLists/AllLists"));
            }
            catch (Exception ex)
            {
                return(this.Redirect($"/Home/Error?message={ex.Message}"));
            }
        }