Example #1
0
        public async Task <IResponse> AddPaymentMethodAsync(vmPaymentMethodCreateRequest newPaymentMethodRequest)
        {
            var response = new Response();

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

                if (duplicatePaymentMethod != null)
                {
                    response.Message = ResponseMessageDisplay.Duplicate;
                    // Throw exception if duplicate existed
                    throw new FamilyHubException(string.Format(PaymentMessageDisplay.PaymentMethodAlreadyExistedMessage, newPaymentMethodRequest.PaymentMethodName));
                }
                else
                {
                    var newPaymentMethod = _mapper.Map <vmPaymentMethodCreateRequest, PaymentMethod>(newPaymentMethodRequest);
                    // Create new payment method
                    await PaymentMethodRepository.AddPaymentMethodAsync(newPaymentMethod);

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

            return(response);
        }
Example #2
0
        public async Task <IActionResult> CreatePaymentMethodAsync([FromBody] vmPaymentMethodCreateRequest newRequest)
        {
            // Get response from business logic
            var response = await _paymentService.AddPaymentMethodAsync(newRequest);

            // Return as http response
            return(response.ToHttpResponse());
        }