public async Task <IActionResult> AddText(int?id, int?position, int?relItemId) { if (id == null) { return(NotFound()); } var note = await _context.Notes .FirstOrDefaultAsync(m => m.Id == (int)id && m.Owner == GetUserId()); if (note == null) { return(NotFound()); } var model = new NewTextNoteItemViewModel() { NoteId = note.Id, TextContent = "", Type = NoteItemType.Text, Position = position, RelativeItemId = relItemId }; return(View(model)); }
public async Task <IActionResult> AddText(int?id, NewTextNoteItemViewModel model) { if (id == null) { return(NotFound()); } if (id != model.NoteId) { return(NotFound()); } if (ModelState.IsValid) { var note = await _context.Notes .FirstOrDefaultAsync(m => m.Id == (int)id && m.Owner == GetUserId()); if (note == null) { return(NotFound()); } var noteItem = new NoteItem() { Content = model.TextContent, NoteId = (int)id, Type = NoteItemType.Text, Order = 1 }; _context.NoteItems.Add(noteItem); await _context.SaveChangesAsync(); await UpdateNoteItemsOrderAfterInsertAsync(note.Id, model.Position, model.RelativeItemId, noteItem.Id); return(RedirectToAction(nameof(Details), new { id = note.Id })); } return(View(model)); }