public void SaveEvent(String title, String location, DateTime date, String category, String occurrence, String user) { myFinanceDbFileEntities db = new myFinanceDbFileEntities(); Event newEvent = new Event(); var query = from id in db.Users select id; var userRow = query.ToList(); newEvent.title = title; newEvent.location = location; newEvent.date = date; if (category == "Task") { newEvent.category = 1; } else { newEvent.category = 2; } newEvent.occurrence = occurrence; newEvent.UserId = userRow[0].Id; db.Events.AddObject(newEvent); try { db.SaveChanges(); } catch (Exception) { throw new Exception(); } }
public void SaveTransaction(List <Transaction> transactionList) { myFinanceDbFileEntities db = new myFinanceDbFileEntities(); foreach (Transaction tx in transactionList) { var userQuery = from id in db.Users select id; var userRow = userQuery.ToList(); //var contactQuery = (from c in db.Contacts where c.Id == tx.ContactId select c).FirstOrDefault<Contact>(); Transaction newTransaction = new Transaction(); newTransaction.date = tx.date; newTransaction.amount = tx.amount; newTransaction.type = tx.type; newTransaction.occurrence = tx.occurrence; newTransaction.description = tx.description; newTransaction.UserId = userRow[0].Id; db.Transactions.AddObject(newTransaction); } try { db.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex); throw new Exception(); } }
private void onFormLoad(object sender, EventArgs e) { myFinanceDbFileEntities db = new myFinanceDbFileEntities(); var query = from username in db.Users select username; var user = query.ToList(); this.user.Text = user[0].username; }
private static void insertIntoDatabase(Contact contact) { myFinanceDbFileEntities db = new myFinanceDbFileEntities(); db.Contacts.AddObject(contact); try { db.SaveChanges(); Thread.Sleep(500); } catch (Exception) { throw new Exception(); } }
private void login(object sender, EventArgs e) { myFinanceDbFileEntities db = new myFinanceDbFileEntities(); var count = db.Users.Where(element => element.username == inputUsername.Text && element.password == inputPassword.Text).Count(); if (count.ToString() == "1") { this.Hide(); Dashboard myDashboard = new Dashboard(); myDashboard.Activate(); myDashboard.Show(); } else { MessageBox.Show("Invalid username or password"); } }