Exemple #1
0
        public async Task TransferBalance(int sourceId, TransferBalanceFilterViewModel filter)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var source = _mapper.Map <users>(await GetById(sourceId));
                    if (source.Balance - filter.Balance < 0)
                    {
                        throw new BitsaSourceBalanceInsufficientException();
                    }
                    await _adminService.SubstractBalance(sourceId, filter.Balance);

                    var target = _mapper.Map <users>(await GetByAlias(filter.Alias));
                    if (target == null)
                    {
                        throw new BitsaTargetEntityNotExistsException();
                    }
                    await _adminService.AddBalance(target.Id, filter.Balance);

                    transaction.Commit();
                    return;
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
        }
Exemple #2
0
        public async Task <IActionResult> AddBalance([FromBody] EditUserBalanceFilterViewModel filter)
        {
            try
            {
                await _adminService.AddBalance(filter.Id, filter.Balance);

                return(NoContent());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }