AlanMoonbase 003d01fe4e Implement Store Frontend
Implement Profile Cosmetics
2025-07-10 17:18:54 -07:00

76 lines
2.4 KiB
C#

using Microsoft.AspNetCore.Mvc.TagHelpers;
using QtCNETAPI.Dtos.User;
using QtCNETAPI.Services.ApiService;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace qtc_net_client_2.Forms
{
public partial class ProfileEdit : Form
{
IApiService _apiService;
public ProfileEdit(IApiService apiService)
{
_apiService = apiService;
InitializeComponent();
}
private async void frmProfileEdit_Load(object sender, EventArgs e)
{
tbUsername.Text = _apiService.CurrentUser.Username;
rtxtBio.Text = _apiService.CurrentUser.Bio;
// get all owned cosmetics
var boughtItems = await _apiService.GetOwnedStoreItems();
if(boughtItems != null && boughtItems.Success && boughtItems.Data != null)
{
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);
}
}
}
cbCosmetic.SelectedIndex = _apiService.CurrentUser.ActiveProfileCosmetic;
}
private async void btnSave_Click(object sender, EventArgs e)
{
// update user info
UserUpdateInformationDto userUpdateInformationDto = new UserUpdateInformationDto
{
Id = _apiService.CurrentUser.Id,
Username = tbUsername.Text,
Bio = rtxtBio.Text,
DateOfBirth = _apiService.CurrentUser.DateOfBirth,
ProfileCosmeticId = cbCosmetic.SelectedIndex
};
var res = await _apiService.UpdateUserInformationAsync(userUpdateInformationDto);
if (res.Success)
{
DialogResult = DialogResult.OK;
Close();
}
else
{
MessageBox.Show(res.Message, "Info Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.Cancel;
Close();
}
}
}
}