コード例 #1
0
        /// <summary>
        /// Edit user function.
        /// </summary>
        /// <param name="id">Desiring User's Id.</param>
        /// <param name="newUser">New user object.</param>
        async Task EditUser(string id, User newUser)
        {
            // check if id is empty.
            if (!string.IsNullOrEmpty(id))
            {
                // Show loading panal.
                LoadingPanal.Show();

                // Send the request and wait for result.
                string result = await Controller.EditUser(id, newUser);

                // Hide loading panal.
                LoadingPanal.Hide();
                if (!string.IsNullOrEmpty(result))
                {
                    // If the result is not empty the somthing went wrong in the request, So display the error.
                    NotificationPanal.Show(NotificationType.Error, result, true, $"Can't Edit '{newUser.Username}'!");
                }
                else
                {
                    // If everything goes right, Replace old user object with the new one..
                    int oldUserIndex = UsersList.FindIndex((x) => x.Id == id);
                    if (oldUserIndex > -1)
                    {
                        UsersList[oldUserIndex] = newUser;

                        // Force layout to refreshing component again.
                        StateHasChanged();
                    }
                }
            }
            else
            {
                NotificationPanal.Show(NotificationType.Error, "Invalid Id format!", true);
            }
        }