예제 #1
0
        private PaymentStatus Pay(TransferInformation data)
        {
            if (!IsArgumentsCorrect(data))
            {
                return(PaymentStatus.PaymentFailed);
            }

            string[] names   = data.FullName.Split(' ');
            Account  account = _accountRepository.Get(data.CardNumber);

            if (account == null || account.Owner.Name != names[0] || account.Owner.Surname != names[1])
            {
                return(PaymentStatus.CardDoesNotExist);
            }

            if (account.AmountOfMoney < data.AmountOfPayment)
            {
                return(PaymentStatus.NotEnoughMoney);
            }

            account.AmountOfMoney -= data.AmountOfPayment;
            _accountRepository.Update(account);

            LogTransfer(data);

            return(PaymentStatus.SuccessfulPayment);
        }
예제 #2
0
        /// <summary>
        /// 查看单条航班变动通知信息
        /// </summary>
        /// <param name="purchaserId"></param>
        /// <returns></returns>
        public TransferInformation QuerySingleTransferInfomation(Guid purchaserId)
        {
            TransferInformation result = null;
            var sql = @"select OrderCount,FlgitCount,[Login] as PurchaserAccount,
            Com.AbbreviateName as PurchaserName,Contact.Cellphone,PurchaserId
          from (select PurchaserId,Count(1) as OrderCount,Count(1) as FlgitCount
          from T_FlightTransfer where InformStatus = 0 and PurchaserId = @PurchaserID group by PurchaserId
             ) as FlightMain
             join T_Employee Emp on FlightMain.PurchaserId = Emp.[Owner] and IsAdministrator = 1
             join T_Company Com on FlightMain.PurchaserId = Com.Id
             join T_Contact Contact on Com.Contact = Contact.Id";

            AddParameter("@PurchaserId", purchaserId);
            using (var reader = ExecuteReader(sql))
            {
                if (reader.Read())
                {
                    result = new TransferInformation()
                    {
                        PurchaserName    = reader.GetString(3),
                        ContractPhone    = reader.GetString(4),
                        PurchaserAccount = reader.GetString(2),
                        OrderCount       = reader.GetInt32(0),
                        FlightCount      = reader.GetInt32(1),
                        PurchaserId      = reader.GetGuid(5)
                    };
                }
            }
            return(result);
        }
예제 #3
0
        /// <summary>
        /// 查看航班变动通知信息
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public IEnumerable <TransferInformation> QueryTransferInformation(Pagination pagination)
        {
            ClearParameters();
            List <TransferInformation> result = null;

            AddParameter("@iPagesize", pagination.PageSize);
            AddParameter("@iPageIndex", pagination.PageIndex);
            AddParameter("@iGetCount", pagination.GetRowCount);
            var totalCount = AddParameter("@oTotalCount");

            totalCount.DbType    = System.Data.DbType.Int32;
            totalCount.Direction = System.Data.ParameterDirection.Output;
            using (var reader = ExecuteReader("dbo.P_QueryFlightTransferInformation", System.Data.CommandType.StoredProcedure))
            {
                result = new List <TransferInformation>();
                while (reader.Read())
                {
                    var item = new TransferInformation()
                    {
                        PurchaserName    = reader.GetString(3),
                        ContractPhone    = reader.GetString(4),
                        PurchaserAccount = reader.GetString(2),
                        OrderCount       = reader.GetInt32(0),
                        FlightCount      = reader.GetInt32(1),
                        PurchaserId      = reader.GetGuid(5)
                    };
                    result.Add(item);
                }
            }
            if (pagination.GetRowCount)
            {
                pagination.RowCount = (int)totalCount.Value;
            }
            return(result);
        }
예제 #4
0
        public virtual TransferInformation Create(string source, string destination)
        {
            var transferInformation = TransferInformation.New();

            transferInformation.Destination = destination;
            transferInformation.Source      = source;
            return(transferInformation);
        }
예제 #5
0
        private bool IsArgumentsCorrect(TransferInformation data)
        {
            if (data.ExpirationYear < 100 && data.ExpirationYear > 0)
            {
                data.ExpirationYear += 2000;
            }

            return(Validator.TryValidateObject(data, new ValidationContext(data), new List <ValidationResult>(), true));
        }
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/>
        /// </summary>
        /// <param name="transferInformation"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param>
        public void PerformBankTransfer(TransferInformation transferInformation)
        {
            try
            {
                using (IBankingManagementService bankingManagement = IoCFactory.Instance.CurrentContainer.Resolve <IBankingManagementService>())
                {
                    bankingManagement.PerformTransfer(transferInformation.OriginAccountNumber,
                                                      transferInformation.DestinationAccountNumber,
                                                      transferInformation.Amount);
                }
            }
            catch (InvalidOperationException ex)
            {
                //trace data for internal health system and return specific FaultException here!
                //Log and throw is a knowed anti-pattern but in this point ( entry point for clients this is admited!)

                //log exception for manage health system
                ITraceManager traceManager = IoCFactory.Instance.CurrentContainer.Resolve <ITraceManager>();
                traceManager.TraceError(ex.Message);

                //propagate bussines exception to client
                ServiceError detailedError = new ServiceError()
                {
                    ErrorMessage = Resources.Messages.exception_InvalidBankAccountForTransfer
                };

                throw new FaultException <ServiceError>(detailedError);
            }
            catch (ArgumentException ex)
            {
                //trace data for internal health system and return specific FaultException here!
                //Log and throw is a knowed anti-pattern but in this point ( entry point for clients this is admited!)

                //log exception for manage health system
                ITraceManager traceManager = IoCFactory.Instance.CurrentContainer.Resolve <ITraceManager>();
                traceManager.TraceError(ex.Message);

                //propagate bussines exception to client
                ServiceError detailedError = new ServiceError()
                {
                    ErrorMessage = Resources.Messages.exception_InvalidArguments
                };

                throw new FaultException <ServiceError>(detailedError);
            }
        }
예제 #7
0
        private void LogTransfer(TransferInformation data)
        {
            ILogger _logger = LogManager.GetLogger("TransfersLogger");

            _logger.Info($"Card number: {data.CardNumber}, full name: {data.FullName}, purpose: {data.Purpose}, amount of payment: {data.AmountOfPayment}");
        }