public async Task <IActionResult> Put(int id, [FromBody] User userUpdateValue) { try { userUpdateValue.EntryTime = DateTime.Now; var userToEdit = await _context.User .AsNoTracking() .SingleOrDefaultAsync(m => m.ID == id); if (userToEdit == null) { return(NotFound("Could not update user as it was not Found")); } else { _context.Update(userUpdateValue); await _context.SaveChangesAsync(); return(Json("Updated user - " + userUpdateValue.Name)); } } catch (DbUpdateException) { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); return(NotFound("User not Found")); } }
public async Task <IActionResult> Put(int id, [FromBody] Leaf leafUpdateValue) { try { leafUpdateValue.ItemCreatedDate = DateTime.Now; var leafToEdit = await _context.Leaf .AsNoTracking() .SingleOrDefaultAsync(m => m.ID == id); if (leafToEdit == null) { return(NotFound("Could not update leaf as it was not Found")); } else { _context.Update(leafUpdateValue); await _context.SaveChangesAsync(); return(Ok("Updated leaf - " + leafUpdateValue.ItemName)); } } catch (DbUpdateException) { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); return(NotFound("Leaf not Found")); } }
public async Task <IActionResult> Update([Bind("ID,Name")] Users userUpdateValue) { try { userUpdateValue.EntryTime = DateTime.Now; _context.Update(userUpdateValue); await _context.SaveChangesAsync(); return(Ok(userUpdateValue)); } catch (DbUpdateException) { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); return(NotFound("User not Found")); } }