コード例 #1
0
        // The buyer deposited the coin into the coin acceptor (deposit)
        public async Task AddAmountDepositAsync(CoinDTO coin, Guid userId)
        {
            if (coin == null)
            {
                throw new NullReferenceException("Coin is null");
            }

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    // Increase the amount of the user's deposit
                    await _userDepositRepository.AddAmountDepositAsync((int)coin.TypeCoin, userId);

                    // we take a coin from the user
                    await _purseRepository.RemoveCoinAsync(userId, coin.TypeCoin);

                    // TODO: To verify a transaction, you need to uncomment this line ->
                    // throw new Exception("To verify a transaction, you need to uncomment this line.");

                    // give a coin to VM
                    await _vendingMachineService.AddCoinAsync(coin.TypeCoin);

                    // Commit transaction if all commands succeed, transaction will auto-rollback
                    // when disposed if either commands fails
                    scope.Complete();
                }
                catch (System.Exception)
                {
                    // TODO: Handle failure
                    throw new ApplicationException("The problem of adding a user deposit amount!");
                }
            };
        }
コード例 #2
0
        public void UpdateCoin(CoinDTO dto)
        {
            Coin entity = dbContext.Coins.FirstOrDefault(t => t.Id == dto.Id);

            entity.Count = dto.Count;
            entity.Lock  = dto.Lock;

            dbContext.SaveChanges();
        }
コード例 #3
0
        public ActionResult Coin(long id)
        {
            CoinDTO   dto   = adminService.GetCoin(id);
            CoinModel model = new CoinModel
            {
                Id           = dto.Id,
                Count        = dto.Count,
                Denomination = dto.Denomination,
                Lock         = dto.Lock
            };

            return(View(model));
        }
コード例 #4
0
ファイル: OrderService.cs プロジェクト: harlov-va/MachineV2
 public void SaveCoinDTO(CoinDTO coin)
 {
     if (coin.iCountCoin <= 0)
     {
         coin.iCountCoin = 0;
         coin.BDontCoin  = true;
     }
     Database.SaveCoin(new Coin
     {
         CoinID          = coin.CoinID,
         SNameCoin       = coin.SNameCoin,
         SNameNumberCoin = coin.SNameNumberCoin,
         iCountCoin      = coin.iCountCoin,
         BDontCoin       = coin.BDontCoin
     });
 }
コード例 #5
0
        public CoinDTO Patch(int id, [FromBody] JsonPatchDocument <CoinDTO> coinPatch)
        {
            //get original coin object from the database
            Coin originCoin = coinRepository.GetCoinByID(id);
            //use automapper to map that to DTO object
            CoinDTO coinDTO = _mapper.Map <CoinDTO>(originCoin);

            //apply the patch to that DTO
            coinPatch.ApplyTo(coinDTO);
            //use automapper to map the DTO back ontop of the database object
            _mapper.Map(coinDTO, originCoin);
            //update coin in the database
            _context.Update(originCoin);
            _context.SaveChanges();
            return(coinDTO);
        }
コード例 #6
0
        public VMCoinDetails(INavigation navigation, CoinDTO coin)
        {
            Navigation  = navigation;
            _Coin       = coin;
            _CoinId     = _Coin.Id;
            _Name       = String.Format("{0} ({1})", _Coin.Name, _Coin.Symbol);
            _LogoSource = _Coin.Logo;

            _PercentageChanged24h = String.Format("{0} % {1}", _Coin.PercentChange24h, _Coin.PercentChange24h > 0 ? Symbols.ARROW_UP : Symbols.ARROW_DOWN);

            _PlusIconTapCommand = new Command(OnPlusIconTap);

            ItemsLoaded = false;
            IsLoading   = true;

            LoadInvestments();
        }
コード例 #7
0
        public VMInvestment(INavigation navigation, CoinDTO coin)
        {
            this.Coin               = coin;
            this.Navigation         = navigation;
            strings                 = DependencyService.Get <IVM>().GetLanguageManager().GetStringsForDefaultLanguage();
            _CancelCommand          = new Command(OnCancelClick);
            _SaveCommand            = new Command(OnSaveClick);
            _TransactionDate        = DateTime.Today;
            _SelectedInvestmentMode = strings[CryptoFolioStrings.INVESTMENDMODE_BUY];

            // TODO add fiat currency, remove currently selected currency
            String defaultCurrencyId = DependencyService.Get <IVM>().GetFiatCurrencyManager().GetDefaultFiatCurrency().ID;
            List <AggregatedInvestment> tempInvestments = DependencyService.Get <IVM>().GetLiteDbManager().LoadAggregatedInvestments(defaultCurrencyId);

            _SpendableCurrencies       = tempInvestments.Select(x => x.CryptoCurrencySymbol).ToArray();
            _SelectedSpendableCurrency = _SpendableCurrencies[0];
        }
コード例 #8
0
        public async Task <ActionResult> AddAmountDeposit(CoinDTO coin)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (userId == null)
            {
                BadRequest();
            }

            try
            {
                await _paymentService.AddAmountDepositAsync(coin, Guid.Parse(userId));

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #9
0
        public ActionResult Coin(CoinModel model)
        {
            CoinDTO dto = new CoinDTO
            {
                Id           = model.Id,
                Count        = model.Count,
                Lock         = model.Lock,
                Denomination = model.Denomination
            };

            if (execute(delegate()
            {
                adminService.UpdateCoin(dto);
            }))
            {
                return(View("Index", getAdminModel()));
            }
            else
            {
                return(View(model));
            };
        }
コード例 #10
0
 public InvestmentPage(CoinDTO Coin)
 {
     InitializeComponent();
     BindingContext = new VMInvestment(Navigation, Coin);
 }
コード例 #11
0
 public CoinDetailPage(CoinDTO Coin)
 {
     InitializeComponent();
     BindingContext = new VMCoinDetails(Navigation, Coin);
 }