public async Task UpdateWallet(string id, EditWalletDto wallet)
        {
            var result = _mapper.Map <EditWalletDto, Wallet>(wallet);

            result.Id = ObjectId.Parse(id);
            await _walletRepository.UpdateWalletAsync(result)
            .ConfigureAwait(false);
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(string id, [FromBody] EditWalletDto walletDto)
        {
            walletDto.Owner = Username;
            await _walletService.UpdateWallet(id, walletDto)
            .ConfigureAwait(false);

            return(NoContent());
        }
Beispiel #3
0
        public async Task <EditWalletDto> GetWalletInfoForEditAsync(string userId, int walletId)
        {
            var model = new EditWalletDto();

            var wallet = await this.dbContext.Wallets
                         .Where(x => x.Id == walletId)
                         .FirstOrDefaultAsync();

            var currency = await this.dbContext.Currencies.FirstOrDefaultAsync(c => c.Wallets.Any(x => x.Id == walletId));

            model.Currencies = await this.currenciesService.GetAllAsync();

            model.Amount              = wallet.MoneyAmount;
            model.CurrencyId          = wallet.CurrencyId;
            model.CurrentCurrencyCode = currency.Code;
            model.CurrentCurrencyName = currency.Name;
            model.Name = wallet.Name;
            model.Id   = wallet.Id;

            return(model);
        }
Beispiel #4
0
        public async Task EditAsync(string userId, int walletId, string name, decimal amount, int currencyId)
        {
            var model = new EditWalletDto();

            var currency = await this.dbContext.Currencies.FirstOrDefaultAsync(c => c.Id == currencyId);

            if (currency == null)
            {
                throw new ArgumentNullException(GlobalConstants.CurrencyNotExist);
            }

            var wallet = await this.dbContext.Wallets.FirstOrDefaultAsync(w => w.Id == walletId);

            wallet.ModifiedOn  = DateTime.UtcNow;
            wallet.MoneyAmount = amount;
            wallet.Name        = name;
            wallet.CurrencyId  = currencyId;

            /*
             * //This code change wallet amount with the sum of all records inside
             *
             * decimal sumOfRecordsAmount = 0m;
             *
             * var categories = this.dbContext.Categories.Include(c => c.Records)
             * .Where(c => c.WalletId == walletId);
             *
             * foreach (var category in categories)
             *  {
             *      foreach (var record in category.Records)
             *      {
             *          sumOfRecordsAmount += record.Amount;
             *      }
             *  }
             *
             * await this.recordsService.EditWalletAmountAsync(walletId, sumOfRecordsAmount);
             *
             */

            await this.dbContext.SaveChangesAsync();
        }