Profile Editing - Reworked Cosmetic Selection
This commit is contained in:
parent
868f6fa067
commit
502dda6436
19
qtc-net-client-2/ClientModel/ComboBoxItem.cs
Normal file
19
qtc-net-client-2/ClientModel/ComboBoxItem.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Mvc.TagHelpers;
|
using Microsoft.AspNetCore.Mvc.TagHelpers;
|
||||||
|
using qtc_net_client_2.ClientModel;
|
||||||
using QtCNETAPI.Dtos.User;
|
using QtCNETAPI.Dtos.User;
|
||||||
using QtCNETAPI.Services.ApiService;
|
using QtCNETAPI.Services.ApiService;
|
||||||
using System;
|
using System;
|
||||||
@ -29,34 +30,55 @@ namespace qtc_net_client_2.Forms
|
|||||||
|
|
||||||
// get all owned cosmetics
|
// get all owned cosmetics
|
||||||
var boughtItems = await _apiService.GetOwnedStoreItems();
|
var boughtItems = await _apiService.GetOwnedStoreItems();
|
||||||
|
List<ComboBoxItem> items = new List<ComboBoxItem>();
|
||||||
|
|
||||||
if(boughtItems != null && boughtItems.Success && boughtItems.Data != null)
|
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
|
// get item from the store
|
||||||
var storeItem = await _apiService.GetStoreItem(item.StoreItemId);
|
var storeItem = await _apiService.GetStoreItem(item.StoreItemId);
|
||||||
if(storeItem != null && storeItem.Success && storeItem.Data != null)
|
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)
|
private async void btnSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
ComboBoxItem? selectedItem = (ComboBoxItem?)cbCosmetic.SelectedItem;
|
||||||
|
|
||||||
// update user info
|
// update user info
|
||||||
UserUpdateInformationDto userUpdateInformationDto = new UserUpdateInformationDto
|
UserUpdateInformationDto userUpdateInformationDto = new UserUpdateInformationDto
|
||||||
{
|
{
|
||||||
Id = _apiService.CurrentUser.Id,
|
Id = _apiService.CurrentUser.Id,
|
||||||
Username = tbUsername.Text,
|
Username = tbUsername.Text,
|
||||||
Bio = rtxtBio.Text,
|
Bio = rtxtBio.Text,
|
||||||
DateOfBirth = _apiService.CurrentUser.DateOfBirth,
|
DateOfBirth = _apiService.CurrentUser.DateOfBirth
|
||||||
ProfileCosmeticId = cbCosmetic.SelectedIndex
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (selectedItem != null)
|
||||||
|
{
|
||||||
|
int selectedItemId = (int?)selectedItem.Value ?? 0;
|
||||||
|
userUpdateInformationDto.ProfileCosmeticId = selectedItemId;
|
||||||
|
}
|
||||||
|
|
||||||
var res = await _apiService.UpdateUserInformationAsync(userUpdateInformationDto);
|
var res = await _apiService.UpdateUserInformationAsync(userUpdateInformationDto);
|
||||||
|
|
||||||
if (res.Success)
|
if (res.Success)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user