Exemple #1
0
        public async Task DeleteProduct(int id)
        {
            try
            {
                var selectedProduct = _context.Products.AsNoTracking()
                                      .Where(product => product.ProductId == id);
                Product remProduct = new Product
                {
                    ProductId = selectedProduct.First().ProductId
                };

                var terminals = _context.Terminals
                                .Where(b => b.ProductId == id)
                                .ToList();

                foreach (Terminal terminal in terminals)
                {
                    terminal.ProductId = null;
                    _context.Terminals.Update(terminal);
                }

                await _context.SaveChangesAsync();

                _context.Products.Remove(remProduct);
                await _context.SaveChangesAsync();
            }
            catch (SqlException error)
            {
                _logger.LogError("While running this error showed up:", error);
            }
        }
Exemple #2
0
        public async Task <bool> SaveOfflineTopUpTransaction(string employeeEmail, decimal topUpAmount)
        {
            var employee = _context.Employees.Find(employeeEmail);

            employee.Balance = employee.Balance + topUpAmount;

            var newTransaction = new Transaction
            {
                DateTime        = DateTime.UtcNow,
                Amount          = topUpAmount,
                TransactionType = "OPEN",
                Employee        = employee
            };

            try
            {
                _context.Add(newTransaction);
                _context.Update(employee);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (SqlException error)
            {
                _logger.LogError("While running this error showed up:", error);
                return(false);
            }
        }
Exemple #3
0
 public async Task CreateNewTerminal(Terminal terminal)
 {
     try
     {
         _context.Add(terminal);
         await _context.SaveChangesAsync();
     }
     catch (SqlException error)
     {
         _logger.LogError("While running this error showed up:", error);
     }
 }
Exemple #4
0
 public async Task CreateNewProduct(Product product)
 {
     try
     {
         _context.Add(product);
         await _context.SaveChangesAsync();
     }
     catch (SqlException error)
     {
         _logger.LogError("While running this error showed up:", error);
     }
 }
 public async Task EditTerminal(Terminal terminal)
 {
     try
     {
         _context.Update(terminal);
         await _context.SaveChangesAsync();
     }
     catch (Exception error)
     {
         _logger.LogError("While running this error showed up:", error);
     }
 }
Exemple #6
0
        public async Task <string> ExecutePayment(string paymentId, string token, string payerId, string email)
        {
            var environment = new SandboxEnvironment("AV8B5CBqWFqiUEBdhbe2rBVqX0RwNjY74nORYSEI3P8WZ-rRzRxXd1H0pA_qrywn0MCZuXzg3x-WwDeY", "EL-1QQduQKljgE0uHFs6WKAM4JtYrbf8CzOisxNCczPvdnkQYQDT1-rCM1W1dYM3Dhu8L9AcwqwhKdZH");
            var client      = new PayPalHttpClient(environment);
            PaymentExecuteRequest request = new PaymentExecuteRequest(paymentId);

            request.RequestBody(new PaymentExecution()
            {
                PayerId = payerId
            });


            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();

                //PayerId en payment opslaan in DB
                var employee = _context.Employees.Find(email);
                employee.Balance = employee.Balance + 10;
                Models.Transaction transaction = new Models.Transaction()
                {
                    Amount                = 10,
                    DateTime              = DateTime.UtcNow,
                    Employee              = employee,
                    employeeEmail         = email,
                    ProviderName          = "PayPal",
                    ProviderTransactionId = paymentId,
                    TransactionType       = "ExternalTopUp"
                };
                try
                {
                    _context.Add(transaction);
                    _context.Update(employee);
                    await _context.SaveChangesAsync();

                    return("Complete");
                }
                catch (SqlException error)
                {
                    _logger.LogError("While running this error showed up:", error);
                    return("Failed");
                }
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return("Failed");
            }
        }
Exemple #7
0
 public async Task EditTransaction(int transactionId, string newType)
 {
     try
     {
         var transaction = _context.Find <Transaction>(transactionId);
         transaction.TransactionType = newType;
         _context.Update(transaction);
         await _context.SaveChangesAsync();
     }
     catch (Exception error)
     {
         _logger.LogError("While running this error showed up:", error);
     }
 }
Exemple #8
0
        public async Task DeleteTerminal(string id)
        {
            try
            {
                var selectedTerminal = _context.Terminals.AsNoTracking()
                                       .Where(terminal => terminal.TerminalId == id);

                Terminal remTerminal = new Terminal
                {
                    TerminalId = selectedTerminal.First().TerminalId
                };

                _context.Terminals.Remove(remTerminal);
                await _context.SaveChangesAsync();
            }
            catch (SqlException error)
            {
                _logger.LogError("While running this error showed up:", error);
            }
        }
 public async void SaveEmployeeEdits(Employee employee)
 {
     _context.Update(employee);
     await _context.SaveChangesAsync();
 }
Exemple #10
0
 public async void SaveProductEdit(Product product)
 {
     _context.Update(product);
     await _context.SaveChangesAsync();
 }