Esempio n. 1
0
        public async Task <DeleteOptionsResponse> Handle(
            DeleteOptionsRequest request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                _notificationConext.AddNotification("Request", "Request não pode ser vazio");
                return(null);
            }
            var optionsIds = request.OptionsIds;

            var options = await _optionRepository.GetByIdsAsync(optionsIds);

            if (options == null)
            {
                _notificationConext.AddNotification("Options", "nenhuma opção encontrada");
                return(null);
            }

            options.ForEach(o => o.RemoveItems());

            var deletedOptionsCount = await _optionRepository.RemoveRange(options);

            if (deletedOptionsCount == 0)
            {
                _notificationConext.AddNotification("Deleted count", "Nenhuma opção foi deletada");
                return(null);
            }

            return(new DeleteOptionsResponse(deletedOptionsCount));
        }