Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrohim-qosimov committed Sep 8, 2024
1 parent 2827616 commit 88f680b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
Expand All @@ -9,16 +10,18 @@
using UrphaCapital.Application.Abstractions;
using UrphaCapital.Application.UseCases.Lessons.Commands;
using UrphaCapital.Application.ViewModels;
using UrphaCapital.Domain.Entities.Auth;

namespace UrphaCapital.Application.UseCases.Lessons.Handlers.CommandHandlers
{
public class DeleteLessonCommandHandler : IRequestHandler<DeleteLessonCommand, ResponseModel>
{
private readonly IApplicationDbContext _context;

public DeleteLessonCommandHandler(IApplicationDbContext context)
private readonly IWebHostEnvironment _webHostEnvironment;
public DeleteLessonCommandHandler(IApplicationDbContext context, IWebHostEnvironment webHostEnvironment)
{
_context = context;
_webHostEnvironment = webHostEnvironment;
}

public async Task<ResponseModel> Handle(DeleteLessonCommand request, CancellationToken cancellationToken)
Expand All @@ -34,6 +37,11 @@ public async Task<ResponseModel> Handle(DeleteLessonCommand request, Cancellatio
StatusCode = 404
};

var filePath = Path.Combine("wwwroot", _webHostEnvironment.WebRootPath, lesson.Video);
if (File.Exists(filePath))
{
File.Delete(filePath);
}
_context.Lessons.Remove(lesson);
await _context.SaveChangesAsync(cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using UrphaCapital.Application.Abstractions;
using UrphaCapital.Application.UseCases.Mentors.Commands;
using UrphaCapital.Application.ViewModels;
using UrphaCapital.Domain.Entities;

namespace UrphaCapital.Application.UseCases.Mentors.Handlers.CommandHandlers
{
Expand Down Expand Up @@ -37,7 +38,11 @@ public async Task<ResponseModel> Handle(DeleteMentorCommand request, Cancellatio
};
}

File.Delete(Path.Combine(_webHostEnvironment.WebRootPath, mentor.Picture));
var filePath = Path.Combine("wwwroot", _webHostEnvironment.WebRootPath, mentor.Picture);
if (File.Exists(filePath))
{
File.Delete(filePath);
}

_context.Mentors.Remove(mentor);
await _context.SaveChangesAsync(cancellationToken);
Expand Down

0 comments on commit 88f680b

Please sign in to comment.