0
0

Base Deleting

This commit is contained in:
Sergey Chebotar 2023-03-02 08:02:02 +03:00
parent 607d029030
commit cdd58a8f51
2 changed files with 147 additions and 126 deletions

View File

@ -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));

View File

@ -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");