Exemplo n.º 1
0
        public ActionResult Add(CourseRegisterModel model)
        {
            string title;
            string content;
            var    toCreate = Mapper.Map <Course>(model);
            var    toCheck  = _courseRepository.Filter(x => x.Name == model.Name && x.Pensum.Id == model.Pensum);

            if (toCheck.Any())
            {
                title   = "Error!";
                content = "El Curso ya existe.";
                _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.ErrorMessage);
                return(RedirectToAction("Index", new { pensumId = model.Pensum }));
            }
            toCreate = _courseRepository.Create(toCreate);
            var academicGrades = _academicGradeRepository.Filter(x => x.ActivePensum.Id == toCreate.Pensum.Id);

            foreach (var academicGrade in academicGrades.ToList())
            {
                academicGrade.CoursesDetails.Add(new AcademicCourse {
                    AcademicGrade = academicGrade, Course = toCreate
                });
                _academicGradeRepository.Update(academicGrade);
            }
            title   = "Curso Agregado";
            content = "El pensum " + toCreate.Name + " ha sido guardado exitosamente.";
            _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
            return(RedirectToAction("Index", new{ pensumId = model.Pensum }));
        }
Exemplo n.º 2
0
        public ActionResult Index(DataImportModel dataImportModel)
        {
            if (!IsFileValid(dataImportModel))
            {
                ModelState.AddModelError("UploadFile", "Por favor seleccione un archivo de Excel");
            }

            var academicGrade = _academicGradeRepository.Filter(x => x.AcademicYear.Id == dataImportModel.Year &&
                                                                x.Grade.Id == dataImportModel.Grade && x.Section.Equals(dataImportModel.Section)).FirstOrDefault();

            if (academicGrade == null)
            {
                ModelState.AddModelError("Year", "No existe ese grado académico");
            }
            else if (academicGrade.Students.Any())
            {
                ModelState.AddModelError("Year", "Ya hay alumos en este grado, borrelos e ingreselos de nuevo.");
            }
            if (!ModelState.IsValid)
            {
                var user       = _userRepository.GetById(Convert.ToInt64(_sessionManagementService.GetUserLoggedId()));
                var isDirector = ViewBag.IsDirector = user.Role.Name.Equals("Director");
                ViewBag.GradeId = isDirector
                    ? new SelectList(_gradeRepository.Filter(x => x.EducationLevel.Director != null && x.EducationLevel.Director.Id == user.Id).ToList(), "Id", "Name", 0)
                    : new SelectList(_gradeRepository.GetAllGrade(), "Id", "Name", 0);
                ViewBag.Year    = new SelectList(_academicYearRepository.Filter(x => x.EnrollsOpen), "Id", "Year");
                ViewBag.Section = new List <SelectListItem>();
                return(View(dataImportModel));
            }
            var myDataSet = _dataImportService.GetDataSetFromExcelFile(dataImportModel.UploadFile);

            try
            {
                _dataImportService.Import(myDataSet, academicGrade);
            }
            catch (Exception ex)
            {
                _viewMessageLogic.SetNewMessage("Error!", ex.Message, ViewMessageType.ErrorMessage);
                return(RedirectToAction("Index"));
            }

            const string title   = "Importación de Datos Exitosa";
            var          content = string.Format("Se importaron datos para el año: {0}, grado: {1} y sección: {2}"
                                                 , academicGrade.AcademicYear.Year // 0
                                                 , academicGrade.Grade.Name        // 1
                                                 , dataImportModel.Section         // 2
                                                 );

            _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public ActionResult Index(long yearId, string currentFilter, string searchString, int?page)
        {
            _viewMessageLogic.SetViewMessageIfExist();
            var user       = _userRepository.GetById(Convert.ToInt64(_sessionManagementService.GetUserLoggedId()));
            var isDirector = ViewBag.IsDirector = user.Role.Name.Equals("Director");
            var grades     = isDirector
                ? _academicGradeRepository.Filter(
                x =>
                x.AcademicYear.Id == yearId && x.Grade.EducationLevel.Director != null &&
                x.Grade.EducationLevel.Director.Id == user.Id).ToList()
                : _academicGradeRepository.Filter(x => x.AcademicYear.Id == yearId).ToList();

            ViewBag.IdAcademicYear = yearId;
            ViewBag.Year           = _academicYearRepository.GetById(yearId).Year;
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            if (!string.IsNullOrEmpty(searchString))
            {
                try
                {
                    grades = isDirector
                        ? _academicGradeRepository.Filter(
                        x =>
                        x.AcademicYear.Id == yearId && x.Grade.EducationLevel.Director != null &&
                        x.Grade.EducationLevel.Director.Id == user.Id &&
                        (x.Section.Equals(searchString) || x.Grade.Name.Contains(searchString))).ToList()
                        : _academicGradeRepository.Filter(
                        x =>
                        x.AcademicYear.Id == yearId &&
                        (x.Section.Equals(searchString) || x.Grade.Name.Contains(searchString))).ToList();
                }
                catch (Exception)
                {
                    grades = isDirector
                        ? _academicGradeRepository.Filter(
                        x =>
                        x.AcademicYear.Id == yearId && x.Grade.EducationLevel.Director != null &&
                        x.Grade.EducationLevel.Director.Id == user.Id).ToList()
                        : _academicGradeRepository.Filter(x => x.AcademicYear.Id == yearId).ToList();
                }
            }
            ViewBag.CurrentFilter = searchString;
            var       model      = grades.Select(Mapper.Map <AcademicGradeDisplayModel>);
            const int pageSize   = 10;
            var       pageNumber = (page ?? 1);

            return(View(model.ToPagedList(pageNumber, pageSize)));
        }
Exemplo n.º 4
0
        public ActionResult StudentByGrade(string gradeSection, int?page, long gradeId)
        {
            _viewMessageLogic.SetViewMessageIfExist();
            ViewBag.gradeId      = gradeId;
            ViewBag.gradeSection = gradeSection;

            var grades = _academicGradeRepository.Filter(x => x.AcademicYear.IsActive && x.Grade.Id == gradeId).ToList();

            var sections = grades.ToList().Select(grade => grade.Section).ToList();

            var listSelectedSections = new List <SelectListItem> {
                new SelectListItem {
                    Selected = true, Value = "N/A", Text = "Sin Filtro"
                }
            };

            for (int i = 0; i < sections.Count; i++)
            {
                listSelectedSections.Add(new SelectListItem {
                    Value = sections[i], Text = sections[i]
                });
            }
            ViewBag.Sections = listSelectedSections;
            if (gradeSection != null && !gradeSection.IsEmpty() && !gradeSection.Equals("N/A"))
            {
                grades = grades.FindAll(x => x.Section == gradeSection);
            }
            if (!grades.Any())
            {
                return(View(new List <EnrollDisplayModel>().ToPagedList(1, 10)));
            }
            var model = new List <EnrollDisplayModel>();

            foreach (var academicGrade in grades)
            {
                model.AddRange(academicGrade.Students.Select(n => new EnrollDisplayModel
                {
                    AcademicGradeId = academicGrade.Id,
                    StudentId       = n.Id,
                    FullName        = n.FullName,
                    Photo           = n.Photo,
                    MyGender        = n.MyGender.ToString("G"),
                    AccountNumber   = n.AccountNumber,
                    Grade           = academicGrade.Grade.Name,
                    Section         = academicGrade.Section
                }));
            }
            const int pageSize   = 10;
            var       pageNumber = (page ?? 1);

            return(View(model.ToPagedList(pageNumber, pageSize)));
        }
Exemplo n.º 5
0
        public ActionResult Index(string searchName, int?page)
        {
            _viewMessageLogic.SetViewMessageIfExist();
            var loggedUser =
                _userRepository.GetById(Convert.ToInt64(_sessionManagement.GetUserLoggedId()));

            var roleName      = loggedUser.Role.Name;
            var notifications = new List <Notification>();

            if (roleName.Equals("Administrador"))
            {
                notifications =
                    _notificationRepository.Filter(personal => personal.NotificationType == NotificationType.Personal)
                    .OrderByDescending(x => x.CreationDate).ToList();
            }
            else if (roleName.Equals("Director"))
            {
                var academicGrade = _academicGradeRepository.Filter(
                    x =>
                    x.Grade.EducationLevel.Director != null &&
                    x.Grade.EducationLevel.Director.Id == loggedUser.Id && x.SectionTeacher != null).ToList();
                var teachersIds = academicGrade.Select(x => x.SectionTeacher.User.Id).Distinct().ToList();
                notifications =
                    _notificationRepository.Filter(personal => personal.NotificationType == NotificationType.Personal
                                                   &&
                                                   teachersIds.Any(
                                                       x => personal.To != null &&
                                                       personal.To.User.Id == x)).ToList();
            }
            else
            {
                notifications =
                    _notificationRepository.Filter(personal => personal.NotificationType == NotificationType.Personal &&
                                                   personal.To != null &&
                                                   personal.To.User.Email == loggedUser.Email)
                    .OrderByDescending(x => x.CreationDate)
                    .ToList();
            }


            if (!string.IsNullOrWhiteSpace(searchName))
            {
                notifications = notifications.ToList().FindAll(x => x.Title.Contains(searchName));
            }
            ViewBag.RoleName = roleName;
            var       notificationsModel = notifications.Select(Mapper.Map <PersonalMessageDisplayModel>);
            const int pageSize           = 10;
            var       pageNumber         = page ?? 1;

            return(View(notificationsModel.ToPagedList(pageNumber, pageSize)));
        }
Exemplo n.º 6
0
        public ActionResult Index(string sortOrder, string currentFilter, int?page)
        {
            ViewBag.GradeId = -1;
            _viewMessageLogic.SetViewMessageIfExist();
            ViewBag.CurrentSort  = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            var user       = _userRepository.GetById(Convert.ToInt64(_sessionManagementService.GetUserLoggedId()));
            var isDirector = user.Role.Name.Equals("Director");
            var grades     = isDirector
                ? _academicGradeRepository.Filter(
                x =>
                x.AcademicYear.IsActive && x.Grade.EducationLevel.Director != null &&
                x.Grade.EducationLevel.Director.Id == user.Id).ToList()
                : _academicGradeRepository.Filter(x => x.AcademicYear.IsActive).ToList();

            if (!grades.Any())
            {
                return(View(new List <EnrollDisplayModel>().ToPagedList(1, 10)));
            }
            var model = new List <EnrollDisplayModel>();

            foreach (var academicGrade in grades)
            {
                model.AddRange(academicGrade.Students.Select(n => new EnrollDisplayModel
                {
                    AcademicGradeId = academicGrade.Id,
                    StudentId       = n.Id,
                    FullName        = n.FullName,
                    Photo           = n.Photo,
                    MyGender        = n.MyGender.ToString("G"),
                    AccountNumber   = n.AccountNumber,
                    Grade           = academicGrade.Grade.Name,
                    Section         = academicGrade.Section
                }));
            }
            switch (sortOrder)
            {
            case "name_desc":
                model = model.OrderByDescending(s => s.FullName).ToList();
                break;

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

            return(View(model.ToPagedList(pageNumber, pageSize)));
        }
Exemplo n.º 7
0
 public ActionResult Delete(long id)
 {
     if (!_academicGradeRepository.Filter(x => x.Grade.Id == id).Any())
     {
         var          grade   = _gradeRepository.Delete(id);
         const string title   = "Grado ha sido Eliminado";
         var          content = grade.Name + " ha sido eliminado exitosamente.";
         _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
         return(RedirectToAction("Index"));
     }
     else
     {
         const string title   = "Error!";
         const string content = "No se puede borrar el grado pues existe un año académico con este grado.";
         _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.ErrorMessage);
         return(RedirectToAction("Index"));
     }
 }
Exemplo n.º 8
0
        public ActionResult Delete(long id)
        {
            Pensum pensum  = _pensumRepository.GetById(id);
            var    gradeId = pensum.Grade.Id;

            if (_academicGradeRepository.Filter(x => x.ActivePensum.Id == id).Any())
            {
                _viewMessageLogic.SetNewMessage("Error", "El pensum esta siendo usado por un grado académico y no puede eliminarse.", ViewMessageType.ErrorMessage);
                return(RedirectToAction("Index", new { gradeId }));
            }
            if (pensum.Courses.Any())
            {
                _viewMessageLogic.SetNewMessage("Error", "El pensum tiene cursos, elimine los cursos primero para posteriormente poder eliminar el pensum.", ViewMessageType.ErrorMessage);
                return(RedirectToAction("Index", new { gradeId }));
            }
            pensum = _pensumRepository.Delete(pensum);
            const string title   = "Pensum Eliminado";
            string       content = "El Pesum " + pensum.Name + " ha sido eliminado exitosamente.";

            _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
            return(RedirectToAction("Index", new { gradeId }));
        }
Exemplo n.º 9
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)));
        }