public async Task <double> Deposit(string cardNumber, double amount) { ServiceValidator.IsInputStringEmptyOrNull(cardNumber); ServiceValidator.ValueIsBetween(amount, 0, double.MaxValue); var bankCardQuery = await this.dbContext.BankCards .FirstOrDefaultAsync(c => c.Id == cardNumber && c.IsDeleted == false); ServiceValidator.ObjectIsNotEqualNull(bankCardQuery); ServiceValidator.CheckCardExpirationDate(bankCardQuery.Expiration); bankCardQuery.MoneyAdded += amount; await this.dbContext.SaveChangesAsync(); return(amount); }
public async Task <BankCard> AddCard(string cardNumber, string userId, DateTime expiration) { ServiceValidator.IsInputStringEmptyOrNull(cardNumber); ServiceValidator.CheckStringLength(cardNumber, 16, 16); ServiceValidator.ValidateCardNumber(cardNumber); ServiceValidator.IsInputStringEmptyOrNull(userId); ServiceValidator.CheckCardExpirationDate(expiration); var bankCard = new BankCard() { CardNumber = cardNumber, UserId = userId, Expiration = expiration, IsDeleted = false, }; await this.dbContext.BankCards.AddAsync(bankCard); await this.dbContext.SaveChangesAsync(); return(bankCard); }