コード例 #1
0
ファイル: LimitService.cs プロジェクト: ntsagliotis/TinyCard
        public async Task <Result <Limit> > RegisterCardLimitAsync(CardLimitOptions options)
        {
            // Validations done earlier
            decimal Balance = 0;

            if (options.TrsansactionType == CardTransactionType.CardPresent)
            {
                Balance = Constants.AmountLimits.CardPresent;
            }
            else if (options.TrsansactionType == CardTransactionType.ECommerce)
            {
                Balance = Constants.AmountLimits.ECommerce;
            }

            var limit = new Limit()
            {
                CardNumber       = options.CardNumber,
                AvailableBalance = Balance,
                TrsansactionType = options.TrsansactionType,
                ReferenceDate    = DateTime.Now.Date
            };

            _dbContext.Add(limit);

            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(new Result <Limit>()
                {
                    Code = Constants.ResultCode.InternalServerError,
                    Message = "Card limit could not be saved"
                });
            }

            return(new Result <Limit>()
            {
                Code = Constants.ResultCode.Success,
                Data = limit
            });
        }
コード例 #2
0
ファイル: CardService.cs プロジェクト: ntsagliotis/TinyCard
        public async Task <Result <Card> > RegisterCardAsync(CardOptions options)
        {
            if (CardExists(options.CardNumber).Result.Data == true)
            {
                return(new Result <Card>()
                {
                    Message = "Card number already exists",
                    Code = Constants.ResultCode.BadRequest
                });
            }

            if (string.IsNullOrWhiteSpace(options?.CardNumber))
            {
                return(new Result <Card>()
                {
                    Message = "Card number is empty",
                    Code = Constants.ResultCode.BadRequest
                });
            }

            if (options.CardNumber.Length != 16)
            {
                return(new Result <Card>()
                {
                    Message = "Card number requires 16 digits",
                    Code = Constants.ResultCode.BadRequest
                });
            }

            if (string.IsNullOrWhiteSpace(options.CardHolderName) ||
                string.IsNullOrWhiteSpace(options.CardHolderSurname))
            {
                return(new Result <Card>()
                {
                    Message = "Name & Surname should not be empty",
                    Code = Constants.ResultCode.BadRequest
                });
            }

            var customer = new Card()
            {
                CardNumber        = options.CardNumber,
                CardHolderName    = options.CardHolderName,
                CardHolderSurname = options.CardHolderSurname
            };

            _dbContext.Add(customer);

            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(new Result <Card>()
                {
                    Code = Constants.ResultCode.InternalServerError,
                    Message = "Card could not be saved"
                });
            }

            return(new Result <Card>()
            {
                Code = Constants.ResultCode.Success,
                Data = customer
            });
        }