Пример #1
0
        public async Task <CardDbModel> GetACardDetails(long cardNumber)
        {
            CardDbModel card  = null;
            string      query = @"select * from card where CardNumber=@cardNumber";

            using (IDbConnection conn = _connection)
            {
                conn.Open();
                card = await conn.QueryFirstOrDefaultAsync <CardDbModel>(query, new { cardNumber });
            }
            return(card);
        }
Пример #2
0
        public async Task <Models.CardContract> RegisterNewCard(Models.CardContract card)
        {
            string[]    formats     = { "dd/MM/yyyy" };
            CardDbModel cardDbModel = new CardDbModel()
            {
                CardGuid   = Guid.NewGuid().ToString(),
                CardNumber = long.Parse(card.CardNumber),
                Expiry     = DateTime.ParseExact(card.Expiry, formats, new CultureInfo("en-US"), DateTimeStyles.None),
                Name       = card.Name
            };

            return(_mapper.Map <Models.CardContract>(await _cardRepository.RegisterNewCard(cardDbModel)));
        }
Пример #3
0
        public async Task <CardDbModel> RegisterNewCard(CardDbModel card)
        {
            var count = 0;

            using (var transactionScope = new TransactionScope())
            {
                string query = @"insert into card (CardNumber, CardGuid, Expiry, Name) values (@CardNumber, @CardGuid, @Expiry, @Name)";
                using (IDbConnection conn = _connection)
                {
                    conn.Open();
                    count = await conn.ExecuteAsync(query, card);
                }
                transactionScope.Complete();
                return(count > 0 ? card : null);
            }
        }