Created
December 8, 2019 11:07
-
-
Save mortezadalil/b797b97a75cbc2724be864395a3ca78f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Cms.Core.Dtos.Generals; | |
using Cms.Core.Dtos.UseCaseDtos; | |
using Cms.Core.Exceptions; | |
using Cms.Core.IRepositories; | |
using Cms.Core.IUseCases; | |
namespace Cms.Core.UseCases | |
{ | |
public class DeletePostUseCase : IDeletePostUseCase | |
{ | |
private readonly IPostRepository _postRepository; | |
public DeletePostUseCase(IPostRepository postRepository) | |
{ | |
_postRepository = postRepository; | |
} | |
public async Task HandleAsync(DeletePostRequest message, IOutputPort<GenericResponse<bool>> outputPort) | |
{ | |
try | |
{ | |
var isExist = await _postRepository.IsPostExist(message.Id); | |
if (!isExist) | |
{ | |
throw new ItemNotFoundException(); | |
} | |
await _postRepository.RemoveById(message.Id); | |
outputPort.Handle(new GenericResponse<bool>(true,"")); | |
} | |
catch (Exception ex) | |
{ | |
if (ex is ItemNotFoundException) | |
{ | |
outputPort.Handle(new GenericResponse<bool>(new[] { | |
new Error(ex.HResult.ToString(), ex.Message) | |
})); | |
} | |
else | |
{ | |
outputPort.Handle(new GenericResponse<bool>(new[] { | |
new Error("0", "خطا در دریافت اطلاعات",ex.ToString()) | |
})); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment