Esempio n. 1
0
        /// <summary>
        /// Public method that queries the enrollment table from the data base to get the record
        /// that matches the enrollment id.
        /// </summary>
        /// <param name="idEnrrolment"> Enrollment ID, Type INT </param>

        public void UpdateDBData(int idEnrrolment, Persistence.Enrollment enrollmentmData)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var enrollment = connection.Enrollments
                                     .Where(classr => classr.Enroll_ID == idEnrrolment)
                                     .FirstOrDefault();
                    enrollment.Date_Enroll  = enrollmentmData.Date_Enroll;
                    enrollment.User_ID      = enrollmentmData.User_ID;
                    enrollment.Classroom_ID = enrollmentmData.Classroom_ID;
                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Public method that adds a record to the Enrollment table.
        /// </summary>
        public void CreateEnrollment(int userID, int classID)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var enroll = new Persistence.Enrollment
                    {
                        Date_Enroll  = DateTime.Today,
                        User_ID      = userID,
                        Classroom_ID = classID,
                    };
                    connection.Enrollments.Add(enroll);

                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (DbUpdateException e)
            {
                var exception = Util.HandleDbUpdateException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }/// <summary>