Files
EbayListingTool/EbayListingTool/Models/BulkImportRow.cs
Peter Foster d4dd11ed3e feat: pass item aspects to eBay and set shipping defaults on bulk import
- Task 8: Convert aspects Dictionary<string,string> to Dictionary<string,string[]> in CreateInventoryItemAsync
- Task 9: Set Postage to RoyalMailTracked48 and ShippingCost to 3.49m on BulkImportRow.ToListingDraft()
2026-04-15 09:39:11 +01:00

137 lines
3.7 KiB
C#

using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace EbayListingTool.Models;
public enum BulkRowStatus
{
Pending,
Enhancing,
Ready,
Posting,
Posted,
Failed
}
public class BulkImportRow : INotifyPropertyChanged
{
private string _title = "";
private string _description = "";
private string _price = "";
private string _condition = "Used";
private string _categoryKeyword = "";
private string _quantity = "1";
private string _photoPaths = "";
private BulkRowStatus _status = BulkRowStatus.Pending;
private string _statusMessage = "";
public string Title
{
get => _title;
set { _title = value; OnPropertyChanged(); }
}
public string Description
{
get => _description;
set { _description = value; OnPropertyChanged(); }
}
public string Price
{
get => _price;
set { _price = value; OnPropertyChanged(); }
}
public string Condition
{
get => _condition;
set { _condition = value; OnPropertyChanged(); }
}
public string CategoryKeyword
{
get => _categoryKeyword;
set { _categoryKeyword = value; OnPropertyChanged(); }
}
public string Quantity
{
get => _quantity;
set { _quantity = value; OnPropertyChanged(); }
}
public string PhotoPaths
{
get => _photoPaths;
set { _photoPaths = value; OnPropertyChanged(); }
}
public BulkRowStatus Status
{
get => _status;
set
{
_status = value;
OnPropertyChanged();
OnPropertyChanged(nameof(StatusIcon));
OnPropertyChanged(nameof(StatusBadge));
}
}
public string StatusMessage
{
get => _statusMessage;
set { _statusMessage = value; OnPropertyChanged(); }
}
public string StatusIcon => Status switch
{
BulkRowStatus.Pending => "⏳",
BulkRowStatus.Enhancing => "✨",
BulkRowStatus.Ready => "✅",
BulkRowStatus.Posting => "📤",
BulkRowStatus.Posted => "✅",
BulkRowStatus.Failed => "❌",
_ => ""
};
/// <summary>
/// String key used by XAML DataTriggers to apply colour-coded status badges.
/// Values: "Posted" | "Failed" | "Enhancing" | "Posting" | "Pending" | "Ready"
/// </summary>
public string StatusBadge => Status.ToString();
public ListingDraft ToListingDraft(string defaultPostcode)
{
var condition = Condition.ToLower() switch
{
"new" => ItemCondition.New,
"openbox" or "open box" => ItemCondition.OpenBox,
"refurbished" => ItemCondition.Refurbished,
"forparts" or "for parts" => ItemCondition.ForPartsOrNotWorking,
_ => ItemCondition.Used
};
return new ListingDraft
{
Title = Title,
Description = Description,
Price = decimal.TryParse(Price, out var p) ? p : 0,
Condition = condition,
Quantity = int.TryParse(Quantity, out var q) ? q : 1,
Postcode = defaultPostcode,
PhotoPaths = PhotoPaths.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim())
.Where(x => !string.IsNullOrEmpty(x))
.ToList(),
Postage = PostageOption.RoyalMailTracked48,
ShippingCost = 3.49m
};
}
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string? name = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}