コード例 #1
0
        public async Task <IActionResult> Create([Bind("CategoryId,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("UserId,UserName,LastLoggedIn")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("ToDoItemId,Item,DateDue,Done,CategoryId,UserId")] ToDoItem toDoItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(toDoItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryName", toDoItem.CategoryId);
            ViewData["UserId"]     = new SelectList(_context.Users, "UserId", "UserName", toDoItem.UserId);
            return(View(toDoItem));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("UserID,UserName,ToDoItemID,CategoryID")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "CategoryID", user.CategoryID);
            ViewData["ToDoItemID"] = new SelectList(_context.ToDoItems, "ToDoItemId", "ToDoItemId", user.ToDoItemID);
            return(View(user));
        }