public IActionResult Update(UserApiModel model) { if (!ModelState.IsValid) { return(Json(new DataSourceResult { Errors = ModelState.SerializeErrors() })); } var userapi = _userApiService.GetUserById(model.Id); if (userapi == null) { throw new ArgumentException("No user api found with the specified id"); } if (ModelState.IsValid) { userapi = model.ToEntity(userapi); if (!string.IsNullOrEmpty(model.Password)) { var keys = HashPassword(model.Password); userapi.Password = keys.hashpassword; userapi.PrivateKey = keys.privatekey; } _userApiService.UpdateUserApi(userapi); return(new NullJsonResult()); } return(ErrorForKendoGridJson(ModelState)); }
public void HandleEvent(EntityInsertedEvent <User> eventMessage) { if (eventMessage.Entity.IsGuest()) { return; } var user = _userApiService.GetUserById(eventMessage.Entity.Id); NotifyRegisteredWebHooks(user, WebHookNames.UsersCreated).GetAwaiter().GetResult(); }
public async Task <IActionResult> GetUserById(int id, string fields = "") { if (id <= 0) { return(await Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var user = _userApiService.GetUserById(id); if (user == null) { return(await Error(HttpStatusCode.NotFound, "user", "not found")); } var usersRootObject = new UsersRootObject(); usersRootObject.Users.Add(user); var json = JsonFieldsSerializer.Serialize(usersRootObject, fields); return(new RawJsonActionResult(json)); }