Exemple #1
0
        public IActionResult Edit(string title)
        {
            NoteRepository repository = new NoteRepository();
            Note           note       = repository.FindById(title);

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

            return(View(note));
        }
Exemple #2
0
        // [ValidateAntiForgeryToken]
        public IActionResult Edit(string old_title, Note note, string category = "", string btnSubmit = "")
        {
            NoteRepository noteRepository = new NoteRepository();
            Note           oldNote        = noteRepository.FindById(old_title);

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

            category = category ?? "";
            category = category.Trim();

            switch (btnSubmit)
            {
            case "Add":
                if (category.Length > 0)
                {
                    note.categories.Add(category);
                    ModelState.Clear();
                }
                return(View(note));

            case "Remove":
                if (note.categories.Contains(category))
                {
                    note.categories.Remove(category);
                    ModelState.Clear();
                }
                return(View(note));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    noteRepository.Update(oldNote, note);
                }
                catch (Z01.Repositories.DuplicatedNoteTitleException e)
                {
                    ModelState.AddModelError("title", e.Message);
                    return(View(note));
                }
                return(returnToIndex());
            }
            return(View(note));
        }