public IActionResult Create(Note note) { note.Id = Guid.NewGuid(); note.UserId = Guid.Parse(User.GetUserId()); note.Done = false; _context.Notes.Add(note); _context.SaveChanges(); return RedirectToAction("Index"); }
// GET: Home public IActionResult Index(string option, string search, Note note) { Guid userId; Guid.TryParse(User.GetUserId(), out userId); if (userId == Guid.Empty) return Redirect("/Account/Login"); var notes = _context.Notes.Where(a => a.UserId == userId).AsQueryable(); if (search == null) return View(notes); if (option == "Date") return View(notes.Where(a => a.Date.ToString("dd.MM.yyyy").StartsWith(search)).ToList()); else if (option == "Body") return View(notes.Where(a => a.Body.StartsWith(search)).ToList()); else if (option == "Importance") return View(notes.Where(a => a.Importance.ToString() == search).ToList()); else return View(notes.Where(a => a.Name.StartsWith(search)).ToList()); }
public IActionResult Edit(Note note) { note.UserId = Guid.Parse(User.GetUserId()); _context.Update(note); _context.SaveChanges(); return RedirectToAction("Index"); }