Example #1
0
        /// <summary>
        /// Response to user updating their note
        /// </summary>
        /// <param name="id">ID of note the user wants to update</param>
        /// <returns>page with updated note or error</returns>
        public IActionResult OnPostUpdate(int id)
        {
            var user = _userManager.GetUserAsync(User).Result;

            UserName  = user.UserName;
            FirstName = user.FirstName;
            LastName  = user.LastName;
            Bio       = user.Bio;
            Email     = user.Email;
            Notes     = _notes.GetNotesByUserID(user.Id).Result;
            try
            {
                Note note = _notes.GetNoteByID(id).Result;
                if (!Notes.Contains(note))
                {
                    throw new Exception("You are not the owner of that note");
                }
                note.Title = Ncvm.Title;
                _notes.UpdateNote(note, id);
                _blob.UpdateText(note, Ncvm.Text);
            }
            catch (Exception)
            {
                TempData["Error"] = "You are not the owner of that note";
                return(Page());
            }

            return(RedirectToPage());
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID, CustomerID, UserID, Comment, Date")] Note note)
        {
            if (id != note.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _context.UpdateNote(note);
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }

                //return RedirectToAction(nameof(Index));
                return(LocalRedirect($"~/Customers/Customer/{note.CustomerID}"));
            }

            return(View(note));
        }