示例#1
0
        public async Task <BaseResponseMassTransit> AddTransaction(User user,
                                                                   Transaction transaction)
        {
            await CheckUserIsCreate(user);

            var customer = await _context.Customers.FirstOrDefaultAsync(item => item.CustomerId == user.Id);

            customer.Transactions.Add(transaction.ToTransactionContext());
            await _context.SaveChangesAsync();

            var response = new BaseResponseMassTransit();

            return(response);
        }
示例#2
0
        public async Task <BaseResponseMassTransit> UpdateTransaction(User user,
                                                                      UpdateTransaction transaction)
        {
            await CheckUserIsCreate(user);

            var customer = await _context.Customers
                           .Include(item => item.Transactions)
                           .ThenInclude(item => item.Products)
                           .FirstOrDefaultAsync(item => item.CustomerId == user.Id);

            var currentTransaction = customer?.Transactions.FirstOrDefault(item => item.Id == transaction.Id);

            if (currentTransaction is null)
            {
                throw new NotFoundException("Transaction that is being updated was not found");
            }

            await UpdateTransaction(currentTransaction, transaction);

            var response = new BaseResponseMassTransit();

            return(response);
        }