/// <summary> /// This method saves the information entered into the textboxes on form /// and enters the information into the database and populates the list on the form /// </summary> /// <param name="stuName">String variable that connects with AccountName</param> /// <param name="stuBalance">Int variable that connects with AccountBalance</param> /// <param name="stuDesc">String variable that connects with AccountDescription</param> /// <returns></returns> private Boolean Save(string stuName, int stuBalance, string stuDesc) { try { // Creates a new context if none it found if (context == null) { context = new StudentContext(); } // Makes a flexible student object to be entered into the database // Instead of multiple hard coded student data var studentFinanceObject = new StudentFinanceAcct() { AccountName = stuName, AccountBalance = stuBalance, AccountDescription = stuDesc }; context.StudentFinanceAccts.Add(studentFinanceObject); context.SaveChanges(); Fill_ListView(context.StudentFinanceAccts.ToList()); return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } }
public static void Delete(StudentFinanceAcct acct) { using (var context = new StudentContext()) { context.Database.Log = Console.WriteLine; context.Entry(acct).State = EntityState.Deleted; context.SaveChanges(); } }
/// <summary> /// Adds a Student's financial account to the DB /// </summary> public static StudentFinanceAcct Add(StudentFinanceAcct acct) { using (var context = new StudentContext()) { context.StudentFinanceAccts.Add(acct); context.SaveChanges(); return(acct); } }
/// <summary> /// Updates/Edits all financial account data on student's account /// </summary> public static StudentFinanceAcct Update(StudentFinanceAcct acct) { using (var context = new StudentContext()) { context.Database.Log = Console.WriteLine; context.Entry(acct).State = EntityState.Modified; context.SaveChanges(); return(acct); } }
/// <summary> /// Deletes student financial account from DB /// </summary> /// <param name="id"></param> public static void Delete(int id) { using (var context = new StudentContext()) { StudentFinanceAcct stuToDelete = (from p in context.StudentFinanceAccts where p.AccountId == id select p).Single(); context.Entry(stuToDelete).State = EntityState.Deleted; context.SaveChanges(); } }