示例#1
0
        /// <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);
            }
        }
示例#2
0
        public static void Delete(StudentFinanceAcct acct)
        {
            using (var context = new StudentContext())
            {
                context.Database.Log = Console.WriteLine;

                context.Entry(acct).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
示例#3
0
        /// <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);
            }
        }
示例#4
0
        /// <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);
            }
        }
示例#5
0
        /// <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();
            }
        }