コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] Category category)
        {
            if (id != category.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(long id, [Bind("ID,Title,Body")] Note note)
        {
            if (id != note.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(note);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NoteExists(note.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(note));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Owner,NoteTitle,NoteContent")] Notes notes)
        {
            if (id != notes.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(notes);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NotesExists(notes.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(notes));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Notes,CreatedOn,CategoryId,UserId,IsDeleted")] Note note)
        {
            if (id != note.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(note);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NoteExists(note.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "ID", "ID", note.CategoryId);
            ViewData["UserId"]     = new SelectList(_context.Users, "ID", "ID", note.UserId);
            return(View(note));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Text,Date_system,UrlNote,TagID,CategoryID")] Note note)
        {
            if (id != note.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(note);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NoteExists(note.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Category, "Id", "Name", note.CategoryID);

            ViewData["TagID"] = new SelectList(_context.Tag, "Id", "Name", note.TagID);
            return(View(note));
        }
コード例 #6
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Email,Name,CreatedOn")] User user)
        {
            if (id != user.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
コード例 #7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,UrlSlug,Description")] Tag tag)
        {
            if (id != tag.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tag);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TagExists(tag.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tag));
        }
コード例 #8
0
 public bool Salvar(Notes notes)
 {
     if (notes.Id != null)
     {
         _notesContext.Update(notes);
     }
     else
     {
         _notesContext.Add(notes);
     }
     _notesContext.SaveChanges();
     return(true);
 }
コード例 #9
0
 public bool Salvar(Users dados)
 {
     if (dados.Id > 0)
     {
         _notesContext.Update(dados);
     }
     else
     {
         _notesContext.Add(dados);
     }
     _notesContext.SaveChanges();
     return(true);
 }
コード例 #10
0
 public IActionResult Edit(Note note)
 {
     if (ModelState.IsValid)
     {
         bool orgNoteFinish = _context.Notes.Where(m => m.Id == note.Id).Select(m => m.Finished).FirstOrDefault();
         if (!orgNoteFinish && note.Finished)
         {
             note.FinishedDate = DateTime.Now;
         }
         _context.Update(note);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(BadRequest());
 }
コード例 #11
0
ファイル: NotesController.cs プロジェクト: d3c6e1/notes_api
        public async Task <ActionResult <Note> > Put(Note note)
        {
            if (note == null)
            {
                return(BadRequest());
            }
            if (!_context.Notes.Any(x => x.Id == note.Id))
            {
                return(NotFound());
            }

            _context.Update(note);
            await _context.SaveChangesAsync();

            return(Ok(note));
        }