private void Deportaments_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            var txt = SearchText.Text.Trim();

            if (String.IsNullOrEmpty(txt))
            {
                //отобразить список полностью
                StudentsList.Clear();
                _tempStudents.ToList().ForEach(StudentsList.Add);
                return;
            }

            var list = StudentsList.Where(s => s.LastName.StartsWith(txt)).ToList();

            StudentsList.Clear();
            list.ForEach(StudentsList.Add);
        }
Example #2
0
        public async Task OnGetAsync()
        {
            //get list of Students and Programmes
            StudentsList = await _db.Students.AsNoTracking().ToListAsync();

            ProgrammesList = await _db.Programmes.AsNoTracking().ToListAsync();

            if ((ProgrammeID.Length == 0) || (ProgrammeID == "All"))
            {
                ProgrammesFound = ProgrammesList.Select(p => p).ToList();
            }
            else
            {
                ProgrammesFound = ProgrammesList.Where(p => p.ProgrammeID == ProgrammeID)
                                  .Select(p => p).ToList();
            }

            if (ProgrammesFound.Count() != 0)
            {
                foreach (var programme in ProgrammesFound)
                {
                    var students = StudentsList.Where(s => s.ProgrammeID == programme.ProgrammeID)
                                   .Select(s => s);

                    {
                        foreach (var stud in students)
                        {
                            StudentsInProgramme.Add(stud);
                        }
                    }
                }
            }
            else
            {
                foreach (var stud in StudentsList)
                {
                    StudentsInProgramme.Add(stud);
                }
            }
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                StudentsList = await _db.Students.AsNoTracking().ToListAsync();

                int studentCounter = 1;
                foreach (var studID in SelectedStudentIDsInProgramme)
                {
                    var student = StudentsList.Where(s => s.StudentID == studID)
                                  .Select(s => s)
                                  .FirstOrDefault();

                    if (SendSMSMessage)
                    {
                        try
                        {
                            msgMgr.SendSMSMessage(student.MobilePhoneNumber,
                                                  Message,
                                                  myTwilioPhoneNumber
                                                  );

                            MessageResults += $"{studentCounter}. SMS to {student.ToString()},mobile: {student.MobilePhoneNumber}, " +
                                              $"sent on {DateTime.Now.ToShortDateString()} at {DateTime.Now.ToShortTimeString()} was sent successfully." +
                                              $" {Environment.NewLine}";
                        }
                        catch (TwilioException e)
                        {
                            MessageResults += $"{studentCounter}. SMS Error, student: {student.ToString()}, mobile number: {student.MobilePhoneNumber}. {Environment.NewLine}";
                            if (e.Message != null)
                            {
                                MessageResults += e.Message;
                            }
                            if ((e.InnerException != null) && (e.InnerException.Message != null))
                            {
                                MessageResults += e.InnerException.Message;
                            }
                            MessageResults += Environment.NewLine;
                        }
                    }
                    if (SendEmailMessage)
                    {
                        try
                        {
                            // No HTML content sent for now
                            string htmlContent = "";
                            msgMgr.SendEmailMessage(mySourceEmailAddress,
                                                    student.EmailAddress,
                                                    Subject,
                                                    Message,
                                                    htmlContent).Wait();
                            MessageResults += $"{studentCounter}. Email  to {student.ToString()} ,email : {student.EmailAddress}, " +
                                              $"sent on {DateTime.Now.ToShortDateString()} at {DateTime.Now.ToShortTimeString()} was sent successfully." +
                                              $"{Environment.NewLine}";
                        }
                        catch (Exception e)
                        {
                            MessageResults += $"{studentCounter}. EMail Error, student: {student.ToString()}, email: {student.EmailAddress}, " +
                                              $"sent on {DateTime.Now.ToShortDateString()} at {DateTime.Now.ToShortTimeString()} {Environment.NewLine}";
                            if (e.Message != null)
                            {
                                MessageResults += e.Message;
                            }
                            if ((e.InnerException != null) && (e.InnerException.Message != null))
                            {
                                MessageResults += e.InnerException.Message;
                            }
                            MessageResults += Environment.NewLine;
                        }
                    }
                    studentCounter++;
                }

                return(RedirectToPage("/SendStudentMessageResults", new { area = "StudentPages" }));
            }
            else
            {
                return(Page());
            }
        }