feat: add Save(ListingDraft) overload capturing aspects and shipping
This commit is contained in:
@@ -78,6 +78,76 @@ public class SavedListingsService
|
||||
return (listing, sources.Count - photoPaths.Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a fully-posted listing draft, preserving aspects, postage, and shipping cost.
|
||||
/// </summary>
|
||||
public (SavedListing Listing, int SkippedPhotos) Save(ListingDraft draft)
|
||||
{
|
||||
return SaveFull(
|
||||
draft.Title,
|
||||
draft.Description,
|
||||
draft.Price,
|
||||
draft.CategoryName,
|
||||
draft.CategoryId,
|
||||
draft.Condition,
|
||||
draft.Postage,
|
||||
draft.ShippingCost,
|
||||
draft.Aspects,
|
||||
draft.Description,
|
||||
draft.PhotoPaths
|
||||
);
|
||||
}
|
||||
|
||||
private (SavedListing Listing, int SkippedPhotos) SaveFull(
|
||||
string title, string description, decimal price,
|
||||
string category, string categoryId,
|
||||
ItemCondition condition, PostageOption postage, decimal shippingCost,
|
||||
Dictionary<string, string> aspects,
|
||||
string conditionNotes,
|
||||
IEnumerable<string> sourcePaths)
|
||||
{
|
||||
var safeName = MakeSafeFilename(title);
|
||||
var exportDir = UniqueDir(Path.Combine(ExportsDir, safeName));
|
||||
Directory.CreateDirectory(exportDir);
|
||||
|
||||
var photoPaths = new List<string>();
|
||||
var sources = sourcePaths.ToList();
|
||||
for (int i = 0; i < sources.Count; i++)
|
||||
{
|
||||
var src = sources[i];
|
||||
if (!File.Exists(src)) continue;
|
||||
var ext = Path.GetExtension(src);
|
||||
var dest = i == 0
|
||||
? Path.Combine(exportDir, $"{safeName}{ext}")
|
||||
: Path.Combine(exportDir, $"{safeName}_{i + 1}{ext}");
|
||||
File.Copy(src, dest, overwrite: true);
|
||||
photoPaths.Add(dest);
|
||||
}
|
||||
|
||||
var textFile = Path.Combine(exportDir, $"{safeName}.txt");
|
||||
File.WriteAllText(textFile, BuildTextExport(title, description, price, category, conditionNotes));
|
||||
|
||||
var listing = new SavedListing
|
||||
{
|
||||
Title = title,
|
||||
Description = description,
|
||||
Price = price,
|
||||
Category = category,
|
||||
CategoryId = categoryId,
|
||||
Condition = condition,
|
||||
Postage = postage,
|
||||
ShippingCost = shippingCost,
|
||||
Aspects = new Dictionary<string, string>(aspects),
|
||||
ConditionNotes = conditionNotes,
|
||||
ExportFolder = exportDir,
|
||||
PhotoPaths = photoPaths
|
||||
};
|
||||
|
||||
_listings.Insert(0, listing);
|
||||
Persist();
|
||||
return (listing, sources.Count - photoPaths.Count);
|
||||
}
|
||||
|
||||
public void Delete(SavedListing listing)
|
||||
{
|
||||
_listings.Remove(listing);
|
||||
|
||||
Reference in New Issue
Block a user