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);
        }
Example #2
0
        public async Task <IResponse> UpdatePaymentMethodAsync(int paymentMethodID, vmPaymentMethodUpdateRequest updatePaymentMethodRequest)
        {
            var response = new Response();

            try
            {
                var duplicatePaymentMethod = await PaymentMethodRepository.GetSinglePaymentMethodByNameAsync(updatePaymentMethodRequest.PaymentMethodName);

                if (duplicatePaymentMethod != null && duplicatePaymentMethod.PaymentMethodID != paymentMethodID)
                {
                    response.Message = ResponseMessageDisplay.Duplicate;
                    // Throw exception if duplicate existed
                    throw new FamilyHubException(string.Format(PaymentMessageDisplay.PaymentMethodAlreadyExistedMessage, updatePaymentMethodRequest.PaymentMethodName));
                }
                else
                {
                    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
                    {
                        _mapper.Map <vmPaymentMethodUpdateRequest, PaymentMethod>(updatePaymentMethodRequest, paymentMethodFromDB);
                        await PaymentMethodRepository.UpdatePaymentMethodAsync(paymentMethodFromDB);

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

            return(response);
        }