public ActionResult Index(long id, string sortOrder, string currentFilter, string searchString, int?page)
        {
            _viewMessageLogic.SetViewMessageIfExist();
            var allAcademicYears = _academicCourseRepository.Filter(x => x.AcademicGrade.Id == id).ToList();

            ViewBag.CurrentSort      = sortOrder;
            ViewBag.NameSortParm     = String.IsNullOrEmpty(sortOrder) ? "teacher_desc" : "";
            ViewBag.ScheduleSortParm = sortOrder == "Schedule" ? "schedule_desc" : "Schedule";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            if (!String.IsNullOrEmpty(searchString))
            {
                allAcademicYears = _academicCourseRepository.Filter(x => x.Teacher.FullName.Contains(searchString)).ToList();
            }
            var academicYearsDetails = allAcademicYears.Select(Mapper.Map <AcademicCourseDisplayModel>);

            ViewBag.IdAcademicYear = id;
            ViewBag.CurrentFilter  = searchString;
            switch (sortOrder)
            {
            case "teacher_desc":
                academicYearsDetails = academicYearsDetails.OrderByDescending(s => s.Teacher).ToList();
                break;

            case "Schedule":
                academicYearsDetails = academicYearsDetails.OrderBy(s => s.Schedule).ToList();
                break;

            case "schedule_desc":
                academicYearsDetails = academicYearsDetails.OrderByDescending(s => s.Schedule).ToList();
                break;

            default:      // Name ascending
                academicYearsDetails = academicYearsDetails.OrderBy(s => s.Teacher).ToList();
                break;
            }
            const int pageSize   = 10;
            var       pageNumber = (page ?? 1);

            return(View(academicYearsDetails.ToPagedList(pageNumber, pageSize)));
        }
        public ActionResult Create()
        {
            var teacherId = GetTeacherId();
            var courses   =
                _academicCourseRepository.Filter(
                    x => x.AcademicGrade.AcademicYear.IsActive && x.Teacher != null && x.Teacher.Id == teacherId)
                .Select(x => x.Course);

            ViewBag.course = new SelectList(courses, "Id", "Name");
            ViewBag.Years  = DateTimeController.GetYears();
            ViewBag.Months = DateTimeController.GetMonths();
            ViewBag.Days   = DateTimeController.GetDaysForMonthAndYearStatic(1, DateTime.UtcNow.Year);
            var modelRegister = new HomeworkRegisterModel {
                Year = ((KeyValuePair <int, int>)((SelectList)ViewBag.Years).SelectedValue).Value
            };

            return(View(modelRegister));
        }
Exemple #3
0
        public ActionResult Edit(AcademicGradeEditModel model)
        {
            var    item  = _academicGradeRepository.GetById(model.Id);
            var    list  = _academicGradeRepository.Filter(x => x.Grade.Id == model.Grade && x.Section == model.Section && x.Id == model.Id);
            var    list2 = _academicGradeRepository.Filter(x => x.Grade.Id == model.Grade && x.Section == model.Section && x.Id != model.Id);
            string title;
            string content;

            if (list2.Any())
            {
                title   = "Error!";
                content = "Ese grado Académico ya existe.";
                _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.ErrorMessage);
            }
            else if (!list.Any())
            {
                var pensumId    = item.ActivePensum.Id;
                var newPensumId = model.ActivePensum;
                if (pensumId != newPensumId)
                {
                    var courses = _academicCourseRepository.Filter(x => x.AcademicGrade.Id == model.Id).ToList();
                    foreach (var academicCourse in courses)
                    {
                        _academicCourseRepository.Delete(academicCourse);
                    }
                }
                item = Mapper.Map(model, item);
                item = _academicGradeRepository.Update(item);
                if (pensumId != newPensumId)
                {
                    foreach (var course in item.ActivePensum.Courses)
                    {
                        var academicCourse = new AcademicCourse
                        {
                            AcademicGrade = item,
                            Course        = course
                        };
                        _academicCourseRepository.Create(academicCourse);
                    }
                }
                title   = "Grado Académico Actualizado!";
                content = "El Grado Académico " + item.Grade.Name + " " + item.Section + " fue actualizado exitosamente.";
                _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
            }
            return(RedirectToAction("Index", new { yearId = item.AcademicYear.Id }));
        }
Exemple #4
0
        public void SendNotification(Notification notification)
        {
            if (notification.Sent)
            {
                return;
            }
            switch (notification.NotificationType)
            {
            case NotificationType.General:
                var allGrades = _academicGradeRepository.Filter(x => x.AcademicYear.Id == notification.AcademicYear.Id).ToList();
                foreach (var grade in allGrades)
                {
                    SendToStudents(grade.Students, notification);
                }
                notification.Sent = true;
                _notificationRepository.Update(notification);
                break;

            case NotificationType.EducationLevel:
                var gradesForLevel =
                    _academicGradeRepository.Filter(
                        x => x.Grade.EducationLevel.Id == notification.DestinationId &&
                        x.AcademicYear.Id == notification.AcademicYear.Id).ToList();
                foreach (var grade in gradesForLevel)
                {
                    SendToStudents(grade.Students, notification);
                }
                notification.Sent = true;
                _notificationRepository.Update(notification);
                break;

            case NotificationType.Grade:
                var grades =
                    _academicGradeRepository.Filter(x => x.Grade.Id == notification.DestinationId &&
                                                    x.AcademicYear.Id == notification.AcademicYear.Id).ToList();
                foreach (var grade in grades)
                {
                    SendToStudents(grade.Students, notification);
                }
                notification.Sent = true;
                _notificationRepository.Update(notification);
                break;

            case NotificationType.Section:
                var singleGrade =
                    _academicGradeRepository.Filter(x => x.Id == notification.DestinationId &&
                                                    x.AcademicYear.Id == notification.AcademicYear.Id).FirstOrDefault();
                if (singleGrade != null)
                {
                    SendToStudents(singleGrade.Students, notification);
                    notification.Sent = true;
                    _notificationRepository.Update(notification);
                }
                break;

            case NotificationType.Course:
                var course = _academicCourseRepository.Filter(x => x.Id == notification.DestinationId &&
                                                              x.AcademicGrade.AcademicYear.Id ==
                                                              notification.AcademicYear.Id).FirstOrDefault();
                if (course != null)
                {
                    SendToStudents(course.AcademicGrade.Students, notification);
                    notification.Sent = true;
                    _notificationRepository.Update(notification);
                }
                break;

            case NotificationType.Student:
                var singleStudent = _suStudentRepository.Filter(x => x.Id == notification.DestinationId).FirstOrDefault();
                if (singleStudent != null)
                {
                    SendToStudent(singleStudent, notification);
                    notification.Sent = true;
                    _notificationRepository.Update(notification);
                }
                break;
            }
        }
        public ActionResult Index(string searchName, int?page)
        {
            _viewMessageLogic.SetViewMessageIfExist();
            var user =
                _userRepository.GetById(Convert.ToInt64(_sessionManagement.GetUserLoggedId()));
            var isDirector    = user.Role.Name.Equals("Director");
            var isAdmin       = user.Role.Name.Equals("Administrador");
            var notifications = new List <Notification>();

            if (isAdmin)
            {
                notifications = _notificationRepository.Filter(personal => personal.NotificationType != NotificationType.Personal).ToList();
            }
            else if (isDirector)
            {
                notifications.AddRange(
                    _notificationRepository.Filter(x => x.NotificationType == NotificationType.General));
                var educationLevel = _educationLevelRepository.Filter(x => x.Director != null && x.Director.Id == user.Id).FirstOrDefault();
                if (educationLevel != null)
                {
                    notifications.AddRange(
                        _notificationRepository.Filter(
                            x =>
                            x.NotificationType == NotificationType.EducationLevel &&
                            x.DestinationId == educationLevel.Id));
                    var gradeIds = educationLevel.Grades.Select(x => x.Id);
                    notifications.AddRange(_notificationRepository.Filter(x => x.NotificationType == NotificationType.Grade && gradeIds.Contains(x.DestinationId)));
                    var academicGradeIds =
                        _academicGradeRepository.Filter(x => gradeIds.Contains(x.Grade.Id)).Select(x => x.Id);
                    notifications.AddRange(_notificationRepository.Filter(x => x.NotificationType == NotificationType.Section && academicGradeIds.Contains(x.DestinationId)));
                    var courseIds = _academicCourseRepository.Filter(x => academicGradeIds.Contains(x.AcademicGrade.Id)).Select(x => x.Id);
                    notifications.AddRange(_notificationRepository.Filter(x => x.NotificationType == NotificationType.Course && courseIds.Contains(x.DestinationId)));
                    var tutorIds =
                        _studentRepository.Filter(x => x.MyGrade != null && academicGradeIds.Contains(x.MyGrade.Id))
                        .Select(x => x.Tutor1.Id);
                    notifications.AddRange(_notificationRepository.Filter(x => x.NotificationType == NotificationType.Student && tutorIds.Contains(x.DestinationId)));
                }
            }
            else
            {
                notifications = _notificationRepository.Filter(x => x.NotificationCreator.Id == user.UserOwner.Id).ToList();
            }
            if (!string.IsNullOrWhiteSpace(searchName))
            {
                notifications = notifications.ToList().FindAll(x => x.Title.Contains(searchName));
            }

            var       notificationsModel = notifications.OrderByDescending(i => i.CreationDate).Select(Mapper.Map <NotificationDisplayModel>);
            const int pageSize           = 10;
            var       pageNumber         = (page ?? 1);

            return(View(notificationsModel.ToPagedList(pageNumber, pageSize)));
        }