public JsonResult EditUserPassword([FromBody] EditableUserInfo newUser) { User user = _context.Users.Where(x => x.ID == newUser.ID && x.Password == newUser.OldPassword)?.SingleOrDefault(); if (user != null) { user.Password = newUser.Password; } try { _context.Users.Update(user); _context.SaveChanges(); return(Json(Ok())); } catch (Exception e) { return(Json(BadRequest(e.Message))); } }
public JsonResult EditUserInfo([FromBody] EditableUserInfo newUser) { User user = _context.Users.Where(x => x.ID == newUser.ID)?.SingleOrDefault(); if (user != null) { user.Name = newUser.Name; user.Details = newUser.Details; } try { _context.Users.Update(user); _context.SaveChanges(); return(Json(Ok())); } catch (Exception e) { return(Json(BadRequest(e.Message))); } }