Example #1
0
        public async Task <IResponse> ToggleActivePaymentMethodAsync(int paymentMethodId, bool active)
        {
            var response = new Response();

            try
            {
                var paymentMethodFromDB = await PaymentMethodRepository.GetSinglePaymentMethodByIDAsync(paymentMethodId);

                if (paymentMethodFromDB == null)
                {
                    response.Message = ResponseMessageDisplay.NotFound;
                    // Throw exception if duplicate existed
                    throw new FamilyHubException(string.Format(PaymentMessageDisplay.PaymentMethodNotFoundMessage));
                }
                else
                {
                    if (active)
                    {
                        await PaymentMethodRepository.ActivatePaymentMethodAsync(paymentMethodFromDB);
                    }
                    else
                    {
                        await PaymentMethodRepository.DeactivatePaymentMethodAsync(paymentMethodFromDB);
                    }

                    response.Message = ResponseMessageDisplay.Success;
                }
            }
            catch (Exception ex)
            {
                response.SetError(ex);
            }

            return(response);
        }