Пример #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);
        }
Пример #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);
        }