Base Deleting
This commit is contained in:
parent
607d029030
commit
cdd58a8f51
@ -1,6 +1,5 @@
|
||||
using System.Data;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MyDarling.Models;
|
||||
|
||||
@ -119,6 +118,20 @@ namespace MyDarling.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
var bundleDirPath = String.Concat(environment.WebRootPath,
|
||||
"/Content/",
|
||||
bundleToDelete.Id);
|
||||
|
||||
if (Directory.Exists(bundleDirPath))
|
||||
{
|
||||
Directory.Delete(bundleDirPath, true);
|
||||
}
|
||||
// foreach (var figure in bundleToDelete.Figures)
|
||||
// {
|
||||
// using FigureController controller = new(context, environment);
|
||||
// await controller.Delete(figure.Id);
|
||||
// }
|
||||
|
||||
context.UnderwearBundles.Remove(bundleToDelete);
|
||||
await context.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Index));
|
||||
|
@ -8,9 +8,11 @@ namespace MyDarling.Controllers
|
||||
public class FigureController : Controller
|
||||
{
|
||||
private DataContext context;
|
||||
public FigureController(DataContext context)
|
||||
private IWebHostEnvironment environment;
|
||||
public FigureController(DataContext context, IWebHostEnvironment environment)
|
||||
{
|
||||
this.context = context;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Details(int id)
|
||||
@ -66,6 +68,12 @@ namespace MyDarling.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
FileInfo figureFile = new FileInfo(environment.WebRootPath + figureToDelete.FilePath);
|
||||
if (figureFile.Exists)
|
||||
{
|
||||
figureFile.Delete();
|
||||
}
|
||||
|
||||
context.Figures.Remove(figureToDelete);
|
||||
await context.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Index), "Bundle");
|
||||
|
Loading…
Reference in New Issue
Block a user