public IActionResult Patch(string id, [FromBody] User user) { if (user == null) { return(BadRequest()); } if (ModelState.IsValid) { User userToUpdate = _context.Find <User>(int.Parse(id)); if (userToUpdate != null) { user.UserId = int.Parse(id); // TODO need to figure out how to update just the values offered by the user? or maybe just figure out a way of validating that // TODO on the client side _context.Entry(userToUpdate).CurrentValues.SetValues(user); _context.Update(userToUpdate); _context.SaveChanges(); return(CreatedAtRoute("GetById", new { id = userToUpdate.UserId }, userToUpdate)); } return(NotFound()); } return(null); }
public async Task <IActionResult> Edit(int id, [Bind("Id,isbn,title,authorId")] Book book) { if (id != book.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(book); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(book.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["authorId"] = new SelectList(_context.authors, "authorId", "authorId", book.authorId); return(View(book)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,fName,lName,mName")] Person person) { if (id != person.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(person); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(person.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(person)); }
public async Task <IActionResult> Edit(int id, [Bind("tagName,description")] Tag tag) { if (id != tag.tagName) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tag); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TagExists(tag.tagName)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tag)); }
public async Task <IActionResult> Edit(int id, [Bind("authorId,bio")] Author author) { if (id != author.authorId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(author); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(author.authorId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(author)); }
public void BulkUpdate(Employee[] updatedEmployees) { foreach (var employee in updatedEmployees) { _context.Update(employee); } _context.SaveChanges(); }