Пример #1
0
        public DeactivatePaymentLevelStatus GetDeactivatePaymentLevelStatus(Guid id)
        {
            var paymentLevel = _repository.PaymentLevels.Single(x => x.Id == id);

            if (paymentLevel.Status == PaymentLevelStatus.Inactive)
            {
                return(DeactivatePaymentLevelStatus.CannotDeactivateStatusInactive);
            }

            var isInUse = _playerQueries.GetPlayersByPaymentLevel(id).Any();
            var defaultPaymentLevelId = _brandQueries.GetDefaultPaymentLevelId(paymentLevel.BrandId, paymentLevel.CurrencyCode);
            var replacementRequired   = paymentLevel.Id == defaultPaymentLevelId || isInUse;

            if (!replacementRequired)
            {
                return(DeactivatePaymentLevelStatus.CanDeactivate);
            }

            var isReplacementAvailable = _repository.PaymentLevels.Any(x =>
                                                                       x.Id != id &&
                                                                       x.BrandId == paymentLevel.BrandId &&
                                                                       x.CurrencyCode == paymentLevel.CurrencyCode &&
                                                                       x.Status == PaymentLevelStatus.Active);

            if (!isReplacementAvailable)
            {
                return(DeactivatePaymentLevelStatus.CannotDeactivateNoReplacement);
            }

            return(paymentLevel.Id == defaultPaymentLevelId
                ? DeactivatePaymentLevelStatus.CanDeactivateIsDefault
                : DeactivatePaymentLevelStatus.CanDeactivateIsAssigned);
        }