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); }
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))); }
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); } }