Exemplo n.º 1
0
        public void ListCreateInputModelShouldHaveTitle()
        {
            var list = new ListCreateInputModel()
            {
                Title       = null,
                Description = "ddd",
                Type        = ListType.ToDoList,
                DueDate     = DateTime.MaxValue,
                ListItems   = new List <ListItemViewModel>(),
            };

            var validatorResults = new List <ValidationResult>();
            var actual           = Validator.TryValidateObject(list, new ValidationContext(list), validatorResults, true);

            Assert.False(actual);
            Assert.Single(validatorResults);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(ListCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

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

            var listId = this.listsService.CreateAsync(model.Title, model.Description, model.Type, user.Id).Result;

            foreach (var item in model.ListItems)
            {
                await this.listsService.AddItemToList(listId, item.Text);
            }

            return(this.Redirect("/"));
        }