Fix: Import concurrency errors + Add sales data cleanup
- Fix optimistic concurrency errors in product import by using ExecuteSqlRaw instead of EF tracking - Add DeleteAllOrdersAndSalesDataAsync() method to clear orders, payments, customers, and messages - Add DeleteAllSalesData endpoint to ProductsController for admin access - Proper deletion order to avoid foreign key violations - Enhanced logging for troubleshooting data cleanup operations Resolves: Import errors with 'database operation expected to affect 1 row(s)'
This commit is contained in:
@@ -306,4 +306,21 @@ public class ProductsController : Controller
|
||||
}
|
||||
return Json(collection);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> DeleteAllSalesData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var deletedCount = await _importService.DeleteAllOrdersAndSalesDataAsync();
|
||||
TempData["SuccessMessage"] = $"✅ Successfully deleted {deletedCount} sales records (orders, payments, customers, messages)";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TempData["ErrorMessage"] = $"Failed to delete sales data: {ex.Message}";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user