Ejemplo n.º 1
0
        public bool CreateWalletTransaction(WalletTransactionCreate model)
        {
            var entity =
                new WalletTransaction()
            {
                TransactionAmount = model.TransactionAmount,
                WalletId          = _walletId,
                TransactionDate   = DateTimeOffset.UtcNow
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.WalletTransactions.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 2
0
        //POST /api/wallettransaction
        public IHttpActionResult Post(WalletTransactionCreate walletTransaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateWalletTransactionService();

            if (!service.CreateWalletTransaction(walletTransaction))
            {
                return(InternalServerError());
            }

            var userId        = Guid.Parse(User.Identity.GetUserId());
            var walletService = new WalletService(userId);

            if (!walletService.UpdateWalletBalance(walletTransaction.TransactionAmount))
            {
                return(InternalServerError(new Exception("Could not update balance for wallet")));
            }

            return(Ok());
        }