Beispiel #1
0
        public async Task <long> AddCustomerAsync(Customer customer)
        {
            dbContext.Customers.Add(customer);
            await dbContext.SaveChangesAsync();

            return(customer.Id);
        }
        public Task AddCredit(decimal credit, int customerId)
        {
            if (credit <= 0)
            {
                throw new Exception($"Credit value must be a positive value!");
            }
            var customer = dbContext.Customers.FirstOrDefault(x => x.Id == customerId);

            if (customer == null)
            {
                throw new Exception($"Customer wit {customerId} identifier not found!");
            }

            customer.Credit += credit;
            return(dbContext.SaveChangesAsync());
        }