I want to delete according to the AdvertId
in it, not according to the ID. I find AdvertId
but I'm stuck on deletion. I am using CQRS structure. My Repository
and IRepository
folders are located separately. In the controller part, I am doing the transaction by finding the advertId
.
public class Advert_CategoryPropertyDetailJunctionDeleteHandler :
IRequestHandler<Advert_CategoryPropertyDetailJunctionDelete, ApiResponse>
{
private readonly IUnitOfWork _repo;
public Advert_CategoryPropertyDetailJunctionDeleteHandler(IUnitOfWork repo)
{
_repo = repo;
}
public async Task<ApiResponse> Handle(Advert_CategoryPropertyDetailJunctionDelete
request, CancellationToken cancellationToken)
{
var mapped = await
_repo.AdvertCategoryPropertyDetailJunctions.GetAllAsync(request.predicate);
if (mapped == null)
return new ErrorApiResponse(ResultMessage.NotDeletedUser);
await _repo.AdvertCategoryPropertyDetailJunctions.DeleteAllAsync((Advert_CategoryPropertyDetailJunction) mapped);
return new SuccessApiResponse();
}
}
IRrepository:
Task<IEnumerable> DeleteAllAsync(T entity);
Repository;
public async Task<IEnumerable> DeleteAllAsync(T entity)
{
Context.Set<T>().Remove(entity);
Context.Entry(entity).State = EntityState.Deleted;
await Context.SaveChangesAsync();
return (IEnumerable)entity;
}