public async Task <IActionResult> AddNote() { int comp_id = Int32.Parse(HttpContext.User.FindFirst("CompanyID").Value); var noteCategories = await _context.NoteCategories.Where(n => n.CompanyID == comp_id).ToListAsync(); NotePlusCategoriesList notePlusCategories = new NotePlusCategoriesList(); notePlusCategories.NoteCategories = noteCategories; return(View(notePlusCategories)); }
public async Task <IActionResult> EditNote(NotePlusCategoriesList note) { if (ModelState.IsValid) { var db_note = await _context.Notes.FirstOrDefaultAsync(n => n.ID == note.ID); if (db_note != null) { db_note.Title = note.Title; db_note.Text = note.Text; db_note.NoteCategoryID = note.NoteCategoryID; await _context.SaveChangesAsync(); return(RedirectToAction("Notes")); } } ModelState.AddModelError("", "Некорректные данные"); return(View(note)); }
public async Task <IActionResult> EditNote(int?id) { int comp_id = Int32.Parse(HttpContext.User.FindFirst("CompanyID").Value); if (id != null) { Note note = await _context.Notes.FirstOrDefaultAsync(n => n.ID == id); if (note != null) { var noteCategories = await _context.NoteCategories.Where(n => n.CompanyID == comp_id).ToListAsync(); NotePlusCategoriesList notePlus = new NotePlusCategoriesList { Text = note.Text, Title = note.Title, ID = note.ID }; notePlus.NoteCategories = noteCategories; return(View(notePlus)); } } return(NotFound()); }
public async Task <IActionResult> AddNote(NotePlusCategoriesList noteplusList) { if (ModelState.IsValid) { int comp_id = Int32.Parse(HttpContext.User.FindFirst("CompanyID").Value); int user_id = Int32.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); Note note = new Note { CompanyID = comp_id, UserID = user_id, CreationDate = DateTime.Now, NoteCategoryID = noteplusList.NoteCategoryID, Title = noteplusList.Title, Text = noteplusList.Text }; _context.Notes.Add(note); await _context.SaveChangesAsync(); return(RedirectToAction("Notes")); } ModelState.AddModelError("", "Некорректные данные"); return(View(noteplusList)); }