Exemplo n.º 1
0
        public IActionResult Add()
        {
            TodoItemIndexModel model = new TodoItemIndexModel();

            model.TemplateItem       = new TodoItem();
            model.DropdownCategories = new List <Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>();
            foreach (String s in this.context.Categories)
            {
                model.DropdownCategories.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem()
                {
                    Text  = s,
                    Value = s
                });
            }
            return(this.View(model));
        }
Exemplo n.º 2
0
        public TodoItemIndexModel GetTodoItems()
        {
            TodoItemIndexModel model = new TodoItemIndexModel();

            model.TemplateItem       = new TodoItem();
            model.TodoItems          = this.context.TodoItems.ToList();
            model.DropdownCategories = new List <Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>();
            foreach (String s in context.Categories)
            {
                model.DropdownCategories.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem()
                {
                    Text  = s,
                    Value = s
                });
            }
            return(model);
        }
Exemplo n.º 3
0
 public IActionResult Add(TodoItemIndexModel item)
 {
     if (ModelState.IsValid)
     {
         this.context.TodoItems.Add(item.TemplateItem);
         return(RedirectToAction("Index"));
     }
     else
     {
         item.DropdownCategories = new List <Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>();
         foreach (String s in this.context.Categories)
         {
             item.DropdownCategories.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem()
             {
                 Text  = s,
                 Value = s
             });
         }
         return(this.View(item));
     }
 }
Exemplo n.º 4
0
        public IActionResult Index()
        {
            TodoItemIndexModel model = GetTodoItems();

            return(this.View(model));
        }