コード例 #1
0
        public IActionResult Create(NotebookViewModel notebookViewModel)
        {
            if (ModelState.IsValid)
            {
                Notebook notebook = new Notebook();
                notebook.Name = notebookViewModel.Name;
                notebook.Description = notebookViewModel.Description;
                notebook.CreatedDateUtc = DateTime.UtcNow;
                notebook.CreatorId = HttpContext.User.GetUserId();

                _context.Notebooks.Add(notebook);
                _context.SaveChanges();

                ViewData["CreatorId"] = new SelectList(_context.Users, "Id", "Creator", notebook.CreatorId);
                return RedirectToAction("View", new { notebookId = notebook.NotebookId });
            }

            return HttpBadRequest();
        }
コード例 #2
0
        public IActionResult Edit(NotebookViewModel notebookViewModel)
        {
            if (ModelState.IsValid)
            {
                Notebook notebook = _context.Notebooks.Single(n => n.NotebookId == notebookViewModel.NotebookId);
                notebook.Name = notebookViewModel.Name;
                notebook.Description = notebookViewModel.Description;

                _context.Update(notebook);
                _context.SaveChanges();

                ViewData["CreatorId"] = new SelectList(_context.Users, "Id", "Creator", notebook.CreatorId);
                return RedirectToAction("View", new { notebookId = notebook.NotebookId });
            }

            return HttpBadRequest();
        }