From 502dda64362a9a3f131b6fa20a265bdc2e79f595 Mon Sep 17 00:00:00 2001 From: AlanMoonbase Date: Fri, 11 Jul 2025 10:43:40 -0700 Subject: [PATCH] Profile Editing - Reworked Cosmetic Selection --- qtc-net-client-2/ClientModel/ComboBoxItem.cs | 19 ++++++++++++ qtc-net-client-2/Forms/ProfileEdit.cs | 32 +++++++++++++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 qtc-net-client-2/ClientModel/ComboBoxItem.cs diff --git a/qtc-net-client-2/ClientModel/ComboBoxItem.cs b/qtc-net-client-2/ClientModel/ComboBoxItem.cs new file mode 100644 index 0000000..0e05010 --- /dev/null +++ b/qtc-net-client-2/ClientModel/ComboBoxItem.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace qtc_net_client_2.ClientModel +{ + public class ComboBoxItem + { + public string? Name { get; set; } + public object? Value { get; set; } + + public override string ToString() + { + return Name ?? string.Empty; + } + } +} diff --git a/qtc-net-client-2/Forms/ProfileEdit.cs b/qtc-net-client-2/Forms/ProfileEdit.cs index 85ea872..e11f60e 100644 --- a/qtc-net-client-2/Forms/ProfileEdit.cs +++ b/qtc-net-client-2/Forms/ProfileEdit.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc.TagHelpers; +using qtc_net_client_2.ClientModel; using QtCNETAPI.Dtos.User; using QtCNETAPI.Services.ApiService; using System; @@ -29,34 +30,55 @@ namespace qtc_net_client_2.Forms // get all owned cosmetics var boughtItems = await _apiService.GetOwnedStoreItems(); + List items = new List(); + if(boughtItems != null && boughtItems.Success && boughtItems.Data != null) { - foreach(var item in boughtItems.Data) + items.Add(new ComboBoxItem + { + Name = "(None)", + Value = 0 + }); + + foreach (var item in boughtItems.Data) { // get item from the store var storeItem = await _apiService.GetStoreItem(item.StoreItemId); if(storeItem != null && storeItem.Success && storeItem.Data != null) { - cbCosmetic.Items.Add(storeItem.Data.Name); + var cbi = new ComboBoxItem + { + Name = storeItem.Data.Name, + Value = storeItem.Data.Id + }; + items.Add(cbi); } } } - cbCosmetic.SelectedIndex = _apiService.CurrentUser.ActiveProfileCosmetic; + cbCosmetic.DataSource = items; + cbCosmetic.SelectedIndex = cbCosmetic.Items.IndexOf(items.FirstOrDefault(e => (int?)e.Value == _apiService.CurrentUser.ActiveProfileCosmetic)); } private async void btnSave_Click(object sender, EventArgs e) { + ComboBoxItem? selectedItem = (ComboBoxItem?)cbCosmetic.SelectedItem; + // update user info UserUpdateInformationDto userUpdateInformationDto = new UserUpdateInformationDto { Id = _apiService.CurrentUser.Id, Username = tbUsername.Text, Bio = rtxtBio.Text, - DateOfBirth = _apiService.CurrentUser.DateOfBirth, - ProfileCosmeticId = cbCosmetic.SelectedIndex + DateOfBirth = _apiService.CurrentUser.DateOfBirth }; + if (selectedItem != null) + { + int selectedItemId = (int?)selectedItem.Value ?? 0; + userUpdateInformationDto.ProfileCosmeticId = selectedItemId; + } + var res = await _apiService.UpdateUserInformationAsync(userUpdateInformationDto); if (res.Success)