Beispiel #1
0
        public async Task <Address> UpdateAsync(Address address, VirtualBankDbContext dbContext = null)
        {
            if (dbContext != null)
            {
                var existingAddress = await dbContext.Addresses
                                      .FirstOrDefaultAsync(a => a.Id == address.Id && a.Disabled == false);

                if (existingAddress != null)
                {
                    dbContext.Entry(existingAddress).State = EntityState.Detached;
                }

                dbContext.Entry(address).State = EntityState.Modified;
                await SaveAsync(dbContext);
            }

            else
            {
                var existingAddress = await _dbContext.Addresses
                                      .FirstOrDefaultAsync(a => a.Id == address.Id && a.Disabled == false);

                if (existingAddress != null)
                {
                    _dbContext.Entry(existingAddress).State = EntityState.Detached;
                }

                _dbContext.Entry(address).State = EntityState.Modified;
                await SaveAsync();
            }


            return(address);
        }
Beispiel #2
0
        public async Task <City> UpdateAsync(City city)
        {
            var existingCity = await _dbContext.Cities.FirstOrDefaultAsync(c => c.Id == city.Id && city.Disabled == false);

            if (existingCity != null)
            {
                _dbContext.Entry(existingCity).State = EntityState.Detached;
            }

            _dbContext.Entry(city).State = EntityState.Modified;
            await SaveAsync();

            return(city);
        }
Beispiel #3
0
        public async Task <Loan> UpdateAsync(Loan loan)
        {
            var existingLoan = await _dbContext.Loans.FirstOrDefaultAsync(l => l.Id == loan.Id && loan.Disabled == false);

            if (existingLoan != null)
            {
                _dbContext.Entry(existingLoan).State = EntityState.Detached;
            }

            _dbContext.Entry(loan).State = EntityState.Modified;
            await SaveAsync();

            return(loan);
        }
Beispiel #4
0
        public async Task <DebitCard> UpdateAsync(DebitCard debitCard)
        {
            var existingDebitCard = await _dbContext.DebitCards.Where(c => c.Id == debitCard.Id && c.Disabled == false)
                                    .FirstOrDefaultAsync();

            if (existingDebitCard != null)
            {
                _dbContext.Entry(existingDebitCard).State = EntityState.Detached;
            }

            _dbContext.Entry(debitCard).State = EntityState.Modified;
            await SaveAsync();

            return(debitCard);
        }
Beispiel #5
0
        public async Task <Customer> UpdateAsync(Customer customer)
        {
            var existingCustomer = await _dbContext.Customers.Where(c => c.Id == customer.Id && c.Disabled == false)
                                   .FirstOrDefaultAsync();

            if (existingCustomer != null)
            {
                _dbContext.Entry(existingCustomer).State = EntityState.Detached;
            }

            _dbContext.Entry(customer).State = EntityState.Modified;
            await SaveAsync();

            return(customer);
        }
        public async Task <CashTransaction> UpdateAsync(CashTransaction transaction)
        {
            var existingCashTransaction = await _dbContext.CashTransactions.Where(c => c.Id == transaction.Id && transaction.Disabled == false)
                                          .FirstOrDefaultAsync();

            if (existingCashTransaction != null)
            {
                _dbContext.Entry(existingCashTransaction).State = EntityState.Detached;
            }

            _dbContext.Entry(transaction).State = EntityState.Modified;
            await SaveAsync();

            return(transaction);
        }
        public async Task <District> UpdateAsync(District district)
        {
            var existingDistrict = await _dbContext.Districts.FirstOrDefaultAsync(d => d.Id == district.Id &&
                                                                                  district.Disabled == false);

            if (existingDistrict != null)
            {
                _dbContext.Entry(existingDistrict).State = EntityState.Detached;
            }

            _dbContext.Entry(district).State = EntityState.Modified;
            await SaveAsync();

            return(district);
        }
Beispiel #8
0
        public async Task <Country> UpdateAsync(Country country)
        {
            var existingCountry = await _dbContext.Countries.FirstOrDefaultAsync(country => country.Id == country.Id &&
                                                                                 country.Disabled == false);

            if (existingCountry != null)
            {
                _dbContext.Entry(existingCountry).State = EntityState.Detached;
            }

            _dbContext.Entry(country).State = EntityState.Modified;
            await SaveAsync();

            return(country);
        }
        public async Task <Branch> UpdateAsync(VirtualBankDbContext dbContext, Branch branch)
        {
            var existingBranch = await dbContext.Branches
                                 .FirstOrDefaultAsync(b => b.Id == branch.Id && b.Disabled == false);

            if (existingBranch != null)
            {
                dbContext.Entry(existingBranch).State = EntityState.Detached;
            }

            dbContext.Entry(branch).State = EntityState.Modified;
            await SaveAsync(dbContext);

            return(branch);
        }
Beispiel #10
0
        public async Task <BankAccount> UpdateAsync(BankAccount bankAccount)
        {
            var existingBankAccount = await _dbContext.BankAccounts
                                      .FirstOrDefaultAsync(b => b.Id == bankAccount.Id && b.Disabled == false);

            if (existingBankAccount != null)
            {
                _dbContext.Entry(existingBankAccount).State = EntityState.Detached;
            }

            _dbContext.Entry(bankAccount).State = EntityState.Modified;
            await SaveAsync();

            return(bankAccount);
        }
Beispiel #11
0
        public async Task <TEntity> UpdateAsync(TEntity entity, object key)
        {
            if (entity == null)
            {
                return(null);
            }

            TEntity existingEntity = _dbSet.Find(key);

            if (existingEntity != null)
            {
                _dbContext.Entry(entity).State = EntityState.Modified;
                _dbContext.Entry(existingEntity).CurrentValues.SetValues(entity);

                await SaveAsync();
            }

            return(existingEntity);
        }