public async Task <object> Edit(JObject body) { try { User userRequest = body.Value <JObject>("User").ToObject <User>(); User userResponse = await userService.GetById(userRequest.IdUser); if (userResponse == null) { throw new NotFoundException("User dengan ID tersebut tidak ditemukan"); } if (userResponse.Username != userRequest.Username) { User newUsername = await userService.GetByUsername(userRequest.Username); if (newUsername != null) { throw new NotPermittedException("Username telah dipakai"); } } ExecuteResult result = await userService.InsertUpdate(userRequest); if (result.ReturnVariable <= 0) { throw new InternalServerErrorException("An error has occured"); } return(new { Status = Models.APIResult.ResultSuccessStatus, ReturnValue = result.ReturnVariable }); } catch (NotFoundException e) { throw e; } catch (NotPermittedException e) { throw e; } catch (Exception e) { throw new InternalServerErrorException(e.Message); } }