Пример #1
0
        public async Task <IActionResult> Create(NotebookFormObject nfo)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                var notebook = nfo.CreateNotebook(user);
                _context.Add(notebook);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["ParentId"] = new SelectList(_context.Notebooks, "Id", "ApplicationUserId", nfo.ParentId);
            return(View(nfo));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, NotebookFormObject nfo)
        {
            if (ModelState.IsValid)
            {
                var notebook = await _context.Notebooks.SingleOrDefaultAsync(n => n.Id == id);

                if (notebook == null)
                {
                    return(NotFound());
                }

                nfo.UpdateNotebook(notebook);
                _context.Update(notebook);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", new { Id = notebook.Id }));
            }
            return(View(nfo));
        }