Add: CSV import with Replace All feature and auto-create categories

- Added Replace All checkbox to import UI for clean slate imports
- Implemented DeleteAllProductsAndCategoriesAsync for complete data wipe
- Added auto-creation of categories during CSV import
- Created products_import.csv with 13 products across 4 categories
- Added comprehensive IMPORT_INSTRUCTIONS.md documentation

Technical changes:
- ProductImportService: Added replaceAll parameter to all import methods
- ProductImportService: Categories now auto-created if missing from CSV
- ProductsController: Added replaceAll parameter to Import action
- Import.cshtml: Added Replace All checkbox with danger warnings

Categories: Flour, Cereal, Vitamins, Herbal
Products: 13 products with full variant pricing structures

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
sysadmin
2025-10-08 14:22:13 +01:00
parent be91b3efd7
commit 6c8106ff90
5 changed files with 331 additions and 10 deletions

View File

@@ -199,7 +199,7 @@ public class ProductsController : Controller
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Import(IFormFile file)
public async Task<IActionResult> Import(IFormFile file, bool replaceAll = false)
{
if (file == null || file.Length == 0)
{
@@ -216,7 +216,7 @@ public class ProductsController : Controller
try
{
using var stream = file.OpenReadStream();
var result = await _importService.ImportFromCsvAsync(stream);
var result = await _importService.ImportFromCsvAsync(stream, replaceAll);
ViewData["ImportResult"] = result;
return View("ImportResult", result);

View File

@@ -48,6 +48,18 @@
</div>
</div>
<div class="mb-3">
<div class="form-check">
<input type="checkbox" name="replaceAll" id="replaceAll" class="form-check-input" value="true" />
<label for="replaceAll" class="form-check-label">
<strong class="text-danger">Replace All</strong> - Delete all existing products, variants, and categories before import
</label>
</div>
<div class="form-text text-danger">
<i class="fas fa-exclamation-triangle"></i> <strong>Warning:</strong> This will permanently delete ALL existing product data! This action cannot be undone.
</div>
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary">
<i class="fas fa-upload"></i> Import Products