Esempio n. 1
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);
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdatePaymentMethodAsync(int paymentMethodId, [FromBody] vmPaymentMethodUpdateRequest updateRequest)
        {
            // Get response from business logic
            var response = await _paymentService.UpdatePaymentMethodAsync(paymentMethodId, updateRequest);

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