コード例 #1
0
        public async Task <IActionResult> EditTitle(int id, EditNoteTitleViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            var note = await _context.Notes
                       .FirstOrDefaultAsync(m => m.Id == id && m.Owner == GetUserId());

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

            if (ModelState.IsValid)
            {
                try
                {
                    note.Title           = model.Title;
                    note.LastUpdatedBy   = GetUserId();
                    note.LastUpdatedDate = DateTime.UtcNow;
                    _context.Update(note);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }

                return(RedirectToAction(nameof(Details), new { id = id }));
            }
            return(View(note));
        }
コード例 #2
0
        public async Task <IActionResult> EditTitle(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var note = await _context.Notes
                       .FirstOrDefaultAsync(m => m.Id == id && m.Owner == GetUserId());

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

            var model = new EditNoteTitleViewModel()
            {
                Id    = note.Id,
                Title = note.Title
            };

            return(View(model));
        }