public async Task <IActionResult> DeleteById(Guid userId, Guid interestId)
        {
            var command = new DeleteUserInterestByIdCommand(userId, interestId);
            var result  = await Mediator.Send(command);

            return(await ResponseBase(result));
        }
예제 #2
0
        public async Task <BaseResponse <string> > Handle(DeleteUserInterestByIdCommand request, CancellationToken cancellationToken)
        {
            var userInterestToDelete = await _applicationDbContext.UserInterests.FirstOrDefaultAsync(userInt =>
                                                                                                     userInt.UserId == request.UserId && userInt.InterestId == request.InterestId, cancellationToken : cancellationToken);

            var response = new BaseResponse <string>();

            if (userInterestToDelete == null)
            {
                response.SetValidationErrors(new [] { "UserInterest not found!" });
                return(response);
            }

            _applicationDbContext.UserInterests.Remove(userInterestToDelete);
            await _applicationDbContext.SaveChangesAsync(cancellationToken);

            response.SetIsOk("User interest has been deleted!");
            return(response);
        }