Beispiel #1
0
        public void Initialise(ioschools.DB.user student, UserGroup viewer_usergroup, int year)
        {
            attendances =
                student.attendances.Where(x => x.date.Year == year).OrderByDescending(
                    x => x.date).ToModel();
            studentid = student.id;
            years     =
                student.attendances.Select(x => x.date.Year).
                Distinct().OrderBy(x => x).Select(
                    x =>
                    new SelectListItem()
            {
                Text = x.ToString(), Value = x.ToString(), Selected = (x == year)
            });

            // get totals for the year
            class_absent = student.GetAttendanceCount(year, AttendanceStatus.ABSENT, true);
            class_late   = student.GetAttendanceCount(year, AttendanceStatus.LATE, true);
            eca_absent   = student.GetAttendanceCount(year, AttendanceStatus.ABSENT, false);
            eca_late     = student.GetAttendanceCount(year, AttendanceStatus.LATE, false);

            if (UserSuperGroups.STAFF.HasFlag(viewer_usergroup))
            {
                canEdit = true;
            }
        }
        public StudentRemarksViewModel(ioschools.DB.user student, Permission viewer_perm, int year)
        {
            studentid = student.id;

            int finalYear = DateTime.Now.Year;

            if (student.FinalYear.HasValue)
            {
                finalYear = student.FinalYear.Value;
                if (year > finalYear)
                {
                    year = finalYear;
                }
            }

            this.year = year;

            years =
                student.classes_students_allocateds
                .Select(x => x.year).Union(new[] { finalYear })
                .Distinct()
                .Where(x => x <= finalYear) // don't show stuff afgter student has left
                .Select(x => new SelectListItem()
            {
                Text = x.ToString(), Value = x.ToString(), Selected = x == year
            });

            canEdit = (viewer_perm & (Permission.TRANSCRIPTS_CREATE | Permission.TRANSCRIPTS_EDIT)) != 0;
        }
Beispiel #3
0
        public static List <JGrowl> ToNotification(this ioschools.DB.user info)
        {
            var notifications = new List <JGrowl>();

            if ((info.settings & (int)UserSettings.PASSWORD_RESET) != 0)
            {
                notifications.Add(JGrowl.USER_CHANGEPASSWORD);
            }
            return(notifications);
        }
Beispiel #4
0
        public static string ToClassName(this ioschools.DB.user row)
        {
            var classs = row.classes_students_allocateds.SingleOrDefault(x => x.year == Utility.GetDBDate().Year);

            if (classs == null)
            {
                return("");
            }
            return(classs.school_class.name);
        }
Beispiel #5
0
 public static UserBase ToBaseModel(this ioschools.DB.user row)
 {
     return(new UserBase()
     {
         name = row.name,
         id = row.id.ToString(),
         thumbnailString = row.photo.HasValue
                                          ? Img.by_size(row.user_image.url, Imgsize.USER_THUMB).ToHtmlImage()
                                          : Img.PHOTO_NO_THUMBNAIL.ToHtmlImage(),
     });
 }
Beispiel #6
0
        public static string ToJqName(this ioschools.DB.user row)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("<a href='/users/{0}'>{1}</a><br/>", row.id, row.ToName());

            // add usergroup
            switch ((UserGroup)row.usergroup)
            {
            case UserGroup.ADMIN:
                sb.Append("<span class='tag_red'>sysadmin</span>");
                break;

            case UserGroup.CLERK:
                sb.Append("<span class='tag_brown'>clerk</span>");
                break;

            case UserGroup.DIRECTOR:
                sb.Append("<span class='tag_orange'>director</span>");
                break;

            case UserGroup.FINANCE:
                sb.Append("<span class='tag_brown'>finance</span>");
                break;

            case UserGroup.GUARDIAN:
                sb.Append("<span class='tag_purple'>parent/guardian</span>");
                break;

            case UserGroup.HEAD:
                sb.Append("<span class='tag_orange'>headmaster/headmistress</span>");
                break;

            case UserGroup.STUDENT:
                sb.Append("<span class='tag_blue'>student</span>");
                break;

            case UserGroup.TEACHER:
                sb.Append("<span class='tag_green'>teacher</span>");
                break;

            case UserGroup.SUPPORT:
                sb.Append("<span class='tag_grey'>support</span>");
                break;

            default:
                throw new NotImplementedException();
            }

            return(sb.ToString());
        }
Beispiel #7
0
        public static int GetAttendanceCount(this ioschools.DB.user usr, DateTime startDate, DateTime endDate, AttendanceStatus status, bool forClass)
        {
            var results = usr.attendances.Where(x => x.status == status.ToString() && x.date >= startDate && x.date <= endDate);

            if (forClass)
            {
                results = results.Where(x => x.classid.HasValue);
            }
            else
            {
                results = results.Where(x => x.ecaid.HasValue);
            }

            return(results.Count());
        }
Beispiel #8
0
        public static int GetAttendanceCount(this ioschools.DB.user usr, int year, AttendanceStatus status, bool forClass)
        {
            var results = usr.attendances.Where(x => x.status == status.ToString() && x.date >= new DateTime(year, 1, 1) && x.date <= new DateTime(year, 12, 31));

            if (forClass)
            {
                results = results.Where(x => x.classid.HasValue);
            }
            else
            {
                results = results.Where(x => x.ecaid.HasValue);
            }

            return(results.Count());
        }
Beispiel #9
0
        public ECAStudentViewModel(ioschools.DB.user student, Permission perms, int year)
        {
            ecas = student.eca_students.Where(x => x.year == year).OrderBy(x => x.eca.name).ToModel();

            studentid = student.id;
            years     =
                student.eca_students.Select(x => x.year).Union(new[] { DateTime.Now.Year }).
                Distinct().OrderByDescending(x => x).Select(
                    x =>
                    new SelectListItem()
            {
                Text = x.ToString(), Value = x.ToString(), Selected = (x == year)
            });
            canEdit = perms.HasFlag(Permission.ECA_CREATE);
        }
Beispiel #10
0
        public static string ToName(this ioschools.DB.user row, bool includeDesignation = true)
        {
            var sb = new StringBuilder();

            // add name
            if (string.IsNullOrEmpty(row.designation) || !includeDesignation)
            {
                sb.Append(row.name);
            }
            else
            {
                sb.AppendFormat("{0} {1}", row.designation, row.name);
            }

            return(sb.ToString());
        }
        public static EmailStudentViewModel ToAttendanceEmailModel(this ioschools.DB.user usr)
        {
            var data = new EmailStudentViewModel()
            {
                date     = Utility.GetDBDate().ToString(Constants.DATEFORMAT_DATEPICKER),
                offender = usr.ToName()
            };
            var receiver = usr.students_guardians.Where(x => !string.IsNullOrEmpty(x.user1.email)).Select(
                x => x.user1).FirstOrDefault();

            if (receiver != null)
            {
                data.receiverEmail = receiver.email;
                data.receiver      = receiver.ToName();
            }
            return(data);
        }
Beispiel #12
0
        public static string ToContactString(this ioschools.DB.user row)
        {
            var contacts = new List <string>();

            if (!string.IsNullOrEmpty(row.phone_home))
            {
                contacts.Add("H:" + row.phone_home);
            }
            if (!string.IsNullOrEmpty(row.phone_cell))
            {
                contacts.Add("M:" + row.phone_cell);
            }
            if (row.user_parents != null && !string.IsNullOrEmpty(row.user_parents.phone_office))
            {
                contacts.Add("O:" + row.user_parents.phone_office);
            }
            return(string.Join(", ", contacts.ToArray()));
        }
Beispiel #13
0
        public static string ToRankStudent(this ioschools.DB.user row)
        {
            ioschools.DB.user parent = null;
            var father = row.students_guardians
                         .FirstOrDefault(x => x.type == (byte)GuardianType.FATHER);

            if (father != null)
            {
                parent = father.user1;
            }

            if (parent == null)
            {
                // try mum
                var mother = row.students_guardians
                             .FirstOrDefault(x => x.type == (byte)GuardianType.MOTHER);
                if (mother != null)
                {
                    parent = mother.user1;
                }
            }
            if (parent != null)
            {
                var siblings = parent
                               .students_guardians1
                               .Where(x => (x.user.settings & (int)UserSettings.INACTIVE) == 0 && x.user.dob.HasValue)
                               .Select(x => x.user)
                               .OrderBy(y => y.dob.Value);

                var count = 1;
                foreach (var sibling in siblings)
                {
                    if (sibling.id == row.id)
                    {
                        return(count.ToString());
                    }
                    count++;
                }
            }

            return("");
        }
Beispiel #14
0
        public DisciplineViewModel(ioschools.DB.user u, long viewerId, UserGroup viewerUsergroup, int year)
        {
            studentid   = u.id;
            disciplines = u.students_disciplines.Where(x => x.created.Year == year).ToModel(viewerId).ToArray();

            if (viewerUsergroup == UserGroup.GUARDIAN ||
                viewerUsergroup == UserGroup.STUDENT)
            {
                hideCreator = true;
            }
            totalDemerit = disciplines.Where(x => x.points.HasValue && x.points.Value < 0).Sum(x => x.points.Value);
            totalMerit   = disciplines.Where(x => x.points.HasValue && x.points.Value > 0).Sum(x => x.points.Value);
            years        =
                u.students_disciplines.Select(x => x.created.Year).Union(new[] { year }).
                Distinct().OrderByDescending(x => x).Select(
                    x =>
                    new SelectListItem()
            {
                Text = x.ToString(), Value = x.ToString(), Selected = (x == year)
            });
        }
Beispiel #15
0
        private static string ToStatus(this ioschools.DB.user row, int year)
        {
            var sb = new StringBuilder();

            // show discipline points
            // add usergroup
            // DONT FORGET TO ADD TABLE TO CACHE DEPENDENCIES
            switch ((UserGroup)row.usergroup)
            {
            case UserGroup.STUDENT:
                var discipline = row.students_disciplines.Where(x => x.created.Year == year).Sum(x => x.points);
                if (discipline != 0)
                {
                    sb.AppendFormat("<div>Merit: {0}</div>", discipline);
                }

                // show late/absent count
                var incidentsArray = row.attendances.ToNumberThisWeek(Utility.GetDBDate());
                if (incidentsArray[0] != 0)
                {
                    sb.AppendFormat("<div class='font_red'><strong>{0}</strong> late</div>", incidentsArray[0]);
                }
                if (incidentsArray[1] != 0)
                {
                    sb.AppendFormat("<div class='font_red'><strong>{0}</strong> absent</div>", incidentsArray[1]);
                }
                break;

            default:
                break;
            }
            if ((row.settings & (int)UserSettings.INACTIVE) != 0)
            {
                sb.Append("<div class='font_red'>INACTIVE</div>");
            }

            return(sb.ToString());
        }
Beispiel #16
0
        public static string ToSchoolClass(this ioschools.DB.user row, int year)
        {
            var sb = new StringBuilder();

            if (row.usergroup == (int)UserGroup.STUDENT)
            {
                var classname =
                    row.classes_students_allocateds.FirstOrDefault(x => x.year == year);
                if (classname != null)
                {
                    sb.AppendFormat("<div>{0}</div><div>{1}</div>", classname.school_class.school.name, classname.school_class.name);
                }
            }
            else if (row.usergroup == (int)UserGroup.TEACHER)
            {
                if (row.schoolid.HasValue)
                {
                    // teacher can be teaching more than one class
                    sb.AppendFormat("<div>{0}</div>", row.school.name);
                }
            }
            return(sb.ToString());
        }
Beispiel #17
0
        private static string ToContactInfo(this ioschools.DB.user row)
        {
            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(row.email))
            {
                sb.AppendFormat("<div><a href='mailto:{0}'>{0}</a></div>", row.email);
            }
            if (!string.IsNullOrEmpty(row.phone_home))
            {
                sb.AppendFormat("<div class='icon_home' title='home phone'>{0}</div>", row.phone_home);
            }
            if (!string.IsNullOrEmpty(row.phone_cell))
            {
                sb.AppendFormat("<div class='icon_mobile' title='mobile phone'>{0}</div>", row.phone_cell);
            }
            if (row.user_parents != null && !string.IsNullOrEmpty(row.user_parents.phone_office))
            {
                sb.AppendFormat("<div class='icon_server' title='office phone'>{0}</div>", row.user_parents.phone_office);
            }

            return(sb.ToString());
        }
Beispiel #18
0
 public static string ToReferenceNumber(this ioschools.DB.user row, int year)
 {
     return(string.Format("{0}{1}", row.id.ToString("D8"), year));
 }
Beispiel #19
0
 public static ioschools.DB.user ToParent(this ioschools.DB.user row, GuardianType type)
 {
     return(row.students_guardians.Where(
                x => x.type == (int)type).Select(x => x.user1)
            .FirstOrDefault());
 }
Beispiel #20
0
        public static User ToModel(this ioschools.DB.user u, long viewer_id, UserAuth viewer_auth, int year)
        {
            var usr = new User();

            usr.canModify      = u.GetCanEdit(viewer_id, viewer_auth);
            usr.canModifyStaff = viewer_auth.perms.HasFlag(Permission.USERS_EDIT_STAFF);
            usr.canModifyLeave = viewer_auth.perms.HasFlag(Permission.LEAVE_ADMIN);

            // normal properties
            usr.gender      = !string.IsNullOrEmpty(u.gender)?u.gender.ToEnum <Gender>():Gender.MALE;
            usr.id          = u.id.ToString();
            usr.name        = u.name;
            usr.email       = u.email;
            usr.race        = u.race;
            usr.dialect     = u.dialect;
            usr.dob         = u.dob;
            usr.pob         = u.pob;
            usr.citizenship = u.citizenship;
            usr.birthcertno = u.birthcertno;
            usr.passport    = u.passportno;
            usr.bumi        = u.isbumi;
            usr.religion    = u.religion;
            usr.nric_new    = u.nric_new;
            usr.homephone   = u.phone_home;
            usr.cellphone   = u.phone_cell;
            usr.address     = u.address;
            usr.notes       = u.notes;
            usr.school      = u.schoolid.HasValue ? (Schools)u.schoolid.Value : (Schools?)null;

            if (usr.school.HasValue)
            {
                usr.schoolname = u.school.name;
            }

            // don't move active as rank checking depends on this value being already set
            usr.active = (u.settings & (int)UserSettings.INACTIVE) == 0;

            // thumbnails
            usr.thumbnailid = u.photo;
            if (u.photo.HasValue)
            {
                usr.profilePhoto = u.user_image.ToModel(Imgsize.USER_PROFILE);
            }
            usr.designation = u.designation;
            usr.usergroup   = (UserGroup)u.usergroup;

            // handle marital status
            usr.marital_status    = u.marital_status;
            usr.maritalStatusList = typeof(MaritalStatus).ToSelectList(false, null, null, string.IsNullOrEmpty(usr.marital_status)?MaritalStatus.SINGLE.ToString():usr.marital_status);

            // handle supergroups
            if (UserSuperGroups.STAFF.HasFlag(usr.usergroup))
            {
                usr.staffLeaves = u.leaves_allocateds.OrderBy(x => x.leave.name).ToModel();
                if (usr.canModifyStaff)
                {
                    usr.staff      = u.user_staffs.ToModel();
                    usr.permission = (Permission)u.permissions;
                }
            }

            // group specific properties
            switch ((UserGroup)u.usergroup)
            {
            case UserGroup.ADMIN:
                break;

            case UserGroup.CLERK:
                break;

            case UserGroup.DIRECTOR:
                break;

            case UserGroup.FINANCE:
                break;

            case UserGroup.GUARDIAN:
                usr.employer    = u.user_parents.employer;
                usr.officephone = u.user_parents.phone_office;
                usr.occupation  = u.user_parents.occupation;
                usr.children    = u.students_guardians1.ToChildrenModel(year);
                break;

            case UserGroup.HEAD:
                break;

            case UserGroup.STUDENT:
                // get allocated classes
                usr.allocatedStudentClasses = u.classes_students_allocateds.OrderByDescending(x => x.year).ToModel();

                // get parents
                usr.parents = u.students_guardians.Select(x => new UserParent()
                {
                    contactInfo  = x.user1.ToContactInfo(),
                    name         = x.user1.ToName(),
                    id           = x.user1.id.ToString(),
                    linkid       = x.id,
                    relationship = x.type.HasValue ? ((GuardianType)x.type.Value).ToString() : ""
                });

                if (usr.active)
                {
                    usr.rank = u.ToRankStudent();
                }

                // show attendance information
                usr.attendance = new AttendanceViewModel();
                usr.attendance.Initialise(u, viewer_auth.group, year);

                // show discipline information
                usr.discipline = new DisciplineViewModel(u, viewer_id, viewer_auth.group, year);

                // show eca information
                usr.eca = new ECAStudentViewModel(u, viewer_auth.perms, year);

                // show enrolment information
                usr.enrolments = u.registrations.ToModel();

                // next student in class only if student already has been allocated to a class
                if (usr.allocatedStudentClasses.Count(x => x.year == year) != 0)
                {
                    var commonclass = u.classes_students_allocateds.Single(x => x.year == year)
                                      .school_class.classes_students_allocateds.FirstOrDefault(x => x.studentid > u.id && x.year == year);
                    if (commonclass != null)
                    {
                        usr.nextStudentInClassID = commonclass.studentid;
                    }
                    else
                    {
                        commonclass =
                            u.classes_students_allocateds.Single(x => x.year == year)
                            .school_class.classes_students_allocateds.FirstOrDefault(x => x.studentid < u.id && x.year == year);
                        if (commonclass != null)
                        {
                            usr.nextStudentInClassID = commonclass.studentid;
                        }
                    }
                }

                // show homework information
                usr.homework = new HomeworkStudentViewModel(u.id, u.classes_students_allocateds.AsQueryable(), year, false);

                if (!(UserGroup.STUDENT | UserGroup.GUARDIAN).HasFlag(viewer_auth.group) &&
                    usr.nextStudentInClassID.HasValue)
                {
                    usr.canGoToNext = true;
                }
                break;

            case UserGroup.TEACHER:
                // get subjects teaching
                var teaching = u.subject_teachers.OrderBy(x => x.year).GroupBy(x => x.year);
                foreach (var yearteaching in teaching)
                {
                    var subjects = yearteaching.GroupBy(x => x.subject);
                    foreach (var subject in subjects)
                    {
                        var item = new SubjectsTeaching();
                        item.year        = yearteaching.Key;
                        item.subjectname = subject.Key.name;
                        item.school      =
                            u.subject_teachers.First(x => x.subjectid == subject.Key.id && x.year == yearteaching.Key).
                            school_class.school.name;
                        item.classesTeaching = string.Join(", ", u.subject_teachers.Where(
                                                               x => x.subjectid == subject.Key.id && x.year == yearteaching.Key).Select(
                                                               x => x.school_class.name));
                        usr.subjectsTeaching.Add(item);
                    }
                }

                // get allocated classes
                usr.allocatedTeacherClasses = u.classes_teachers_allocateds
                                              .OrderByDescending(x => x.year)
                                              .ThenBy(x => x.day)
                                              .ThenBy(x => x.time_start)
                                              .ToModel();

                break;

            case UserGroup.SUPPORT:
                break;

            default:
                throw new NotImplementedException();
            }

            return(usr);
        }
Beispiel #21
0
 public static int UnsetFlag(this ioschools.DB.user row, UserSettings setting)
 {
     return(row.settings & ~(int)setting);
 }