public bool SaveTransaction(string employeeEmail, string transactionType, decimal transactionAmount, decimal newBalance, int productId) { var employee = _context.Employees.Find(employeeEmail); employee.Balance = newBalance; _context.Update(employee); var transaction = new Transaction { DateTime = DateTime.UtcNow, Amount = transactionAmount, ProductId = productId, TransactionType = transactionType, Employee = employee }; try { _context.Add(transaction); _context.SaveChanges(); return(true); } catch (System.Data.SqlClient.SqlException error) { _logger.LogError("While running this error showed up:", error); return(false); } }
public void SaveNewCard(string cardUid, string scannedAt) { bool scannedBefore = ScannedBefore(cardUid); var newCard = new NewCards { ScanTime = DateTime.UtcNow, NewCardUid = cardUid, ScannedAt = scannedAt }; try { if (scannedBefore == true) { _context.Update(newCard); } else { _context.Add(newCard); } _context.SaveChanges(); } catch (Exception e) { _logger.LogInformation("can't connect to sql DB:" + e); } }