Exemplo n.º 1
0
        public async Task <bool> Handle(UpdateGdprCommand request, CancellationToken cancellationToken)
        {
            var commandIsValid = request.IsValid();

            if (!commandIsValid)
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var updatedDomain = _gdprDomainRepository.FindBy(request.Id);

            if (updatedDomain == null)
            {
                request.ValidationResult.Errors.Add(new FluentValidation.Results.ValidationFailure("DB Entry", "Record not found"));

                NotifyValidationErrors(request);
                return(false);
            }

            updatedDomain.UpdateFields(request.Id, request.Gdpr);

            var bcErrors = updatedDomain.GetBrokenRules();

            if (bcErrors.Count > 0)
            {
                foreach (var errBc in bcErrors)
                {
                    request.ValidationResult.Errors.Add(new FluentValidation.Results.ValidationFailure(errBc.Rule, errBc.Property));
                }

                NotifyValidationErrors(request);
                return(false);
            }

            _gdprDomainRepository.Update(updatedDomain);

            if (await Commit(cancellationToken))
            {
                // Raise Event
            }

            return(true);
        }
Exemplo n.º 2
0
        public async Task <BusinessResult <bool> > Handle(DeleteGdprCommand request, CancellationToken cancellationToken)
        {
            var result = new BusinessResult <bool>();

            var updatedDomain = _gdprDomainRepository.FindBy(request.Id);

            if (updatedDomain == null)
            {
                result.AddBrokenRule(new BusinessError("Record does not exist"));
                return(result);
            }

            _gdprDomainRepository.Remove(updatedDomain);

            await _unitOfWork.SaveChangesAsync(cancellationToken);

            result.Model = true;

            return(result);
        }