public StudentTermRegister Update(StudentTermRegister studentTermRegister, string modifiedBy, ref bool dbError)
        {
            try
            {
                var sql = @"UPDATE StudentTermRegister
                               SET IsPhoneSent = @IsPhoneSent
                                  ,IsEmailSent = @IsEmailSent
                                  ,IsAllowedSent = @IsAllowedSent
                                  ,CanParentViewExamData = @CanParentViewExamData
                                  ,LastModifiedBy = @modifiedBy
                            WHERE StudentTermRegisterID = @StudentTermRegisterID AND IsDeleted IS NULL";

                var id = GetConnection().Execute(sql, new
                {
                    StudentTermRegisterID = studentTermRegister.StudentTermRegisterID,
                    IsAllowedSent         = studentTermRegister.IsAllowedSent,
                    IsEmailSent           = studentTermRegister.IsEmailSent,
                    IsPhoneSent           = studentTermRegister.IsPhoneSent,
                    TermID = studentTermRegister.TermID,
                    CanParentViewExamData = studentTermRegister.CanParentViewExamData,
                    modifiedBy            = modifiedBy
                });
                return(studentTermRegister);
            }
            catch (Exception er)
            {
                dbError = true;
                DbLog.Error(er);
                return(null);
            }
        }
        public StudentTermRegister Insert(StudentTermRegister studentTermRegister, string modifiedBy, ref bool dbError)
        {
            try
            {
                var sql = @"   
									INSERT INTO StudentTermRegister
									   (StudentTermRegisterID
									   ,StudentID
									   ,ClassID
									   ,TermID
									   ,IsPhoneSent
									   ,IsEmailSent
									   ,IsAllowedSent
                                       , LastModifiedBy
                                       )
									VALUES
									   (
										@id
									   ,@StudentID
									   ,@ClassID
									   ,@TermID
									   ,@IsPhoneSent
									   ,@IsEmailSent
									   ,@IsAllowedSent
                                        ,@modifiedBy
									   )
							
							"                            ;
                studentTermRegister.StudentTermRegisterID = Guid.NewGuid();
                var id = GetConnection().Execute(sql, new
                {
                    id            = studentTermRegister.StudentTermRegisterID,
                    StudentID     = studentTermRegister.StudentID,
                    ClassID       = studentTermRegister.ClassID,
                    IsAllowedSent = studentTermRegister.IsAllowedSent,
                    IsEmailSent   = studentTermRegister.IsEmailSent,
                    IsPhoneSent   = studentTermRegister.IsPhoneSent,
                    TermID        = studentTermRegister.TermID,
                    modifiedBy    = modifiedBy
                });
                if (id <= 0)
                {
                    return(null);
                }
                return(studentTermRegister);
            }
            catch (Exception er)
            {
                dbError = true;
                DbLog.Error(er);
                return(null);
            }
        }
Esempio n. 3
0
        public string BulkSave(List <StudentTermRegisterFORM> enrollmentFORMs, ref List <string> sbError, ref List <string> sbSuccess)
        {
            if (enrollmentFORMs == null)
            {
                return(null);
            }
            var  classID     = enrollmentFORMs.Select(c => c.ClassID).FirstOrDefault();
            var  termID      = enrollmentFORMs.Select(c => c.TermID).FirstOrDefault();
            bool dbFlag      = false;
            var  schoolClass = _uofRepository.ClassRepository.GetClassByID(classID, ref dbFlag);
            var  studentsListEnrolledInClass = _uofRepository.StudentTermRegisterRepository.GetListByClassIDAndTermID(classID, _user.TermID, ref dbFlag);

            foreach (var enrollmentForm in enrollmentFORMs)
            {
                var student = _uofRepository.StudentRepository.GetStudentByRegNumber(enrollmentForm.RegNumber, _user.SchoolID, ref dbFlag);

                if (student == null)
                {
                    sbError.Add("Student Reg Number does not exist");
                    continue;
                }

                if (student.SchoolID != _user.SchoolID)
                {
                    sbError.Add("Student does not  exist");
                    continue;
                }
                if (schoolClass == null)
                {
                    sbError.Add("Class does not exist for school");
                    continue;
                }

                var enrollment = new StudentTermRegister()
                {
                    StudentTermRegisterID = null,
                    ClassID       = enrollmentForm.ClassID,
                    StudentID     = (Guid)student.StudentID,
                    TermID        = enrollmentForm.TermID,
                    IsAllowedSent = enrollmentForm.IsAllowedSent,
                    IsEmailSent   = enrollmentForm.IsEmailSent,
                    IsPhoneSent   = enrollmentForm.IsPhoneSent
                };

                enrollment = _uofRepository.StudentTermRegisterRepository.Insert(enrollment, _user.Username, ref dbFlag);
                if (dbFlag)
                {
                    sbError.Add("Error getting saving enrollement");
                    continue;
                }
                if (enrollment != null)
                {
                    sbSuccess.Add(enrollmentForm.RegNumber);
                }
                else
                {
                    sbError.Add(enrollmentForm.RegNumber + " Failed to save please try again");
                }
            }
            return(null);
        }
Esempio n. 4
0
        public StudentTermRegister SingleSave(StudentTermRegisterFORM enroll, ref StringBuilder sbError)
        {
            Student             student = null;
            StudentTermRegister studentDataEnrollment = null;
            bool dbFlag = false;

            if (!_user.isAdmin)
            {
                if (_user.ClassID != null)
                {
                    if (!_user.ClassID.Equals(enroll.ClassID))
                    {
                        sbError.Append("You are not class teacher of that class");
                        return(null);
                    }
                }
                else
                {
                    sbError.Append("You are not allowed to register student for this class");
                    return(null);
                }
            }



            var school = _uofRepository.SchoolRepository.GetSchoolBySchoolID(_user.SchoolID, ref dbFlag);


            student = _uofRepository.StudentRepository.GetStudentByRegNumber(enroll.RegNumber, _user.SchoolID, ref dbFlag);

            if (enroll.StudentTermRegisterID != null && enroll.StudentTermRegisterID != Guid.Empty)
            {
                var isExist = _uofRepository.StudentTermRegisterRepository.GetByID((Guid)enroll.StudentTermRegisterID, ref dbFlag);
                if (isExist == null)
                {
                    sbError.Append("Student not found by for term");
                    return(null);
                }
                else
                {
                    studentDataEnrollment = isExist;
                }
            }


            if (student == null)
            {
                sbError.Append("Student not found by reg number for school");
                return(null);
            }


            if (student == null)
            {
                sbError.Append("Student does not exist for school");
                return(null);
            }
            if (dbFlag)
            {
                sbError.Append("Error getting enrollment details");
                return(null);
            }
            if (student.SchoolID != _user.SchoolID)
            {
                sbError.Append("Student does not belong to school exist");
                return(null);
            }
            if (student.SchoolID != _user.SchoolID)
            {
                sbError.Append("Student does not belong to school exist");
                return(null);
            }



            if (enroll.StudentTermRegisterID != null && enroll.StudentTermRegisterID != Guid.Empty)
            {
                studentDataEnrollment.IsAllowedSent = enroll.IsAllowedSent;
                studentDataEnrollment.IsEmailSent   = enroll.IsEmailSent;
                studentDataEnrollment.IsPhoneSent   = enroll.IsPhoneSent;
                var e = _uofRepository.StudentTermRegisterRepository.Update(studentDataEnrollment, _user.Username, ref dbFlag);
                return(e);
            }

            var schoolClass = _uofRepository.ClassRepository.GetClassByID(enroll.ClassID, ref dbFlag);

            if (schoolClass == null)
            {
                sbError.Append("Class does not exist for school");
                return(null);
            }

            if (dbFlag)
            {
                sbError.Append("Error getting enrollment details");
                return(null);
            }

            if (schoolClass.SchoolID != _user.SchoolID)
            {
                sbError.Append("Class does not exist for school or vice versa");
                return(null);
            }

            StudentTermRegister enrollment = new StudentTermRegister()
            {
                StudentTermRegisterID = null,
                ClassID       = enroll.ClassID,
                StudentID     = (Guid)student.StudentID,
                TermID        = _user.TermID,
                IsAllowedSent = enroll.IsAllowedSent,
                IsEmailSent   = enroll.IsEmailSent,
                IsPhoneSent   = enroll.IsPhoneSent
            };


            enrollment = _uofRepository.StudentTermRegisterRepository.Insert(enrollment, _user.Username, ref dbFlag);
            if (dbFlag)
            {
                sbError.Append("Error getting saving enrollement");
                return(null);
            }

            // check if chan
            return(enrollment);
        }