public ActionResult SendNewMessage([Bind(Prefix = "Item2")] MessageToTeacherModel model)
        {
            if (HttpContext.Session != null)
            {
                var loggedUserEmail = System.Web.HttpContext.Current.Session["loggedUserEmail"].ToString();
                var loggedTutor     = _tutorRepository.Filter(y => y.User.Email == loggedUserEmail).FirstOrDefault();
                var teacher         = _teacherRepository.Filter(x => x.User.Email == model.To).ToList().FirstOrDefault();

                if (teacher == null)
                {
                    return(RedirectToAction("Index"));
                }
                var newNotification = new Notification(model.Subject, model.Message, loggedTutor, teacher,
                                                       NotificationType.Personal, _academicYearRepository.GetCurrentAcademicYear())
                {
                    Approved  = true,
                    SendEmail = true
                };
                newNotification.RecipientUsers.Add(teacher.User);
                _notificationRepository.Create(newNotification);
                MailgunEmailService.SendEmailToUser(teacher.User, MessageService.ConstruirMensaje(teacher.User.Role));
                ViewBag.Message = "Mensaje Enviado!";
            }
            else
            {
                ViewBag.Message = "Mensaje No Enviado!";
            }
            return(RedirectToAction("Index", "Notification", new { filter = "Personal" }));
        }
        public ActionResult Index()
        {
            var currentAcademicYear = Convert.ToInt32(_academicYearRepository.GetCurrentAcademicYear().Year.ToString(CultureInfo.InvariantCulture));
            var loggedUserEmail     = _securityRepository.GetUserLoggedEmail();

            _loggedParent = _parentRepository.Filter(y => y.MyUser.Email == loggedUserEmail).FirstOrDefault();
            var userId = _securityRepository.GetUserLogged().Id;
            var personalNotifications = _notificationRepository.GetPersonalNotifications(currentAcademicYear, userId).ToList();
            var notifications         = _notificationRepository.GetGradeNotifications(currentAcademicYear, userId).ToList();

            notifications.AddRange(_notificationRepository.GetAreaNotifications(currentAcademicYear, userId).ToList());
            notifications.AddRange(_notificationRepository.GetGeneralNotifications(currentAcademicYear).ToList());
            var personalNotificationsModel = new List <NotificationModel>();
            var notificationsModel         = new List <NotificationModel>();

            foreach (var notification in personalNotifications)
            {
                var noti = Mapper.Map <NotificationModel>(notification);
                noti.CommentsAmount      = notification.NotificationComments.Count;
                noti.NotificationCreator = notification.UserCreatorName;
                // if(noti.Id != )
                personalNotificationsModel.Add(noti);
            }
            foreach (var notification in notifications)
            {
                var noti = Mapper.Map <Notification, NotificationModel>(notification);
                noti.CommentsAmount      = notification.NotificationComments.Count;
                noti.NotificationCreator = notification.UserCreatorName;
                notificationsModel.Add(noti);
            }
            personalNotificationsModel = personalNotificationsModel.OrderByDescending(x => x.Created).ToList();
            notificationsModel         = notificationsModel.OrderByDescending(x => x.Created).ToList();
            return(View(new Tuple <List <NotificationModel>, List <NotificationModel> >(personalNotificationsModel, notificationsModel)));
        }
        public ActionResult Add(NotificationRegisterModel eventNotification)
        {
            eventNotification.NotificationCreator = _userRepository.GetById(Convert.ToInt64(_sessionManagement.GetUserLoggedId())).UserOwner.Id;
            eventNotification.AcademicYear        = _academicYearRepository.GetCurrentAcademicYear().Id;
            var notificationIdentity = Mapper.Map <Notification>(eventNotification);
            var approved             = _sessionManagement.GetUserLoggedRole().Equals("Administrador");

            notificationIdentity.Approved         = approved;
            notificationIdentity.PeopleDirectedTo = GetDestinationName(notificationIdentity);
            notificationIdentity = _notificationRepository.Create(notificationIdentity);
            var users = _userRepository.Filter(x => x.Role.Name == "Administrador");

            if (!approved)
            {
                foreach (var user in users)
                {
                    MailgunEmailService.SendEmailToUser(user, MessageService.ApproveMessage());
                }
            }
            _notificationHandlerService.SendAllPending();
            const string title   = "Notificación Agregada";
            var          content = "La notificacion " + notificationIdentity.Title + " ha sido agregada exitosamente.";

            _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
            return(RedirectToAction("Index"));
        }