//Create - return bool to use in if/else endpoint - flow to tables public bool CreateChargeforChips(RevisedChargeModel chargeModel) { // make a charge // use charge method //// if successful, make entry into charge table var entityChips = new ChargeForChips() { PlayerId = _playerGuid, ChargeTime = DateTimeOffset.Now, ChargeAmount = chargeModel.Value / 100 }; using (var ctx = new ApplicationDbContext()) { ctx.ChargesForChips.Add(entityChips); // add entry to charges and if successful add entry to bank table if (ctx.SaveChanges() != 0) { var bankModel = new BankTransactionCreate(); bankModel.PlayerId = entityChips.PlayerId; bankModel.BankTransactionAmount = entityChips.ChargeAmount; var bankService = new BankTransactionService(); if (!bankService.CreateBankTransactionCharge(bankModel)) { return(false); } return(true); } return(false); } }
public IHttpActionResult Charge(RevisedChargeModel charge) { var newCharge = MakeChargeService.Charge(charge.CardNumber, charge.Month, charge.Year, charge.Cvc, charge.Zip, charge.Value); if (newCharge) { MakeChargeService chargeService = CreateMakeChargeServiceForGuid(); // adds entry to ChargeForChips table AND BankTransaction Table AND Player table's PlayerBalance chargeService.CreateChargeforChips(charge); return(Ok($"charge made: $ {charge.Value / 100} charged to your card, and ${charge.Value / 100} added to your player account")); // put in message } else { return(InternalServerError()); // put in message } }