Beispiel #1
0
 private void ShareNotes_Clicked(object sender, EventArgs e)
 {
     if (emailList.Count > 0)
     {
         ShareNotes message = new ShareNotes();
         //sms.SendSms(currentCourse.Notes, InstructorPhone.Text);
         message.SendEmail("'Student Name' - " + currentCourse.Name + " Notes", currentCourse.Notes, emailList);
         EmailList.Text = "";
     }
     else
     {
         DisplayAlert("No Emails Selected", "Enter email address(es) to send notes to.", "OK");
     }
 }
Beispiel #2
0
        private async void Save_Clicked(object sender, EventArgs e)
        {
            try
            {
                bool emailValidate = true;
                bool phoneValidate = true;

                if (InstructorEmail.Text != null)
                {
                    emailValidate = Email_Validate(InstructorEmail.Text);
                }
                if (InstructorPhone.Text != null)
                {
                    phoneValidate = Phone_Validate(InstructorPhone?.Text);
                }

                if (emailValidate == false)
                {
                    DisplayAlert("Invalid Email", "Invalid email address for course instructor.", "OK");
                }
                else if (phoneValidate == false)
                {
                    DisplayAlert("Invalid Phone", "Invalid phone number for course instructor.", "OK");
                }
                else
                {
                    if (CourseTitleEntry.Text != null && CourseTitleEntry.Text != "")
                    {
                        currentCourse.Name = CourseTitleEntry.Text;
                    }
                    currentCourse.StartDate         = StartDatePicker.Date;
                    currentCourse.EndDate           = EndDatePicker.Date;
                    currentCourse.StartNotification = StartSwitch.IsToggled;
                    currentCourse.EndNotification   = EndSwitch.IsToggled;
                    if (NotesSwitch.IsToggled)
                    {
                        currentCourse.NotesPublic = true;
                        ShareNotes sms = new ShareNotes();
                        //sms.SendSms(currentCourse.Notes, InstructorPhone.Text);
                        List <string> email = new List <string>();
                        email.Add(InstructorEmail.Text);
                        sms.SendEmail("'Student Name' - " + currentCourse.Name + " Notes", currentCourse.Notes, email);
                    }
                    else
                    {
                        currentCourse.NotesPublic = false;
                    }
                    if (currentCourse.StartNotification)
                    {
                        CrossLocalNotifications.Current.Show("Course Started", currentCourse.Name + " starts today",
                                                             101, currentCourse.StartDate);
                    }
                    else
                    {
                        try
                        {
                            CrossLocalNotifications.Current.Cancel(101);
                        }
                        catch
                        {
                            //ignore
                        }
                    }
                    if (currentCourse.EndNotification)
                    {
                        CrossLocalNotifications.Current.Show("Course Ended", currentCourse.Name + " ended today",
                                                             102, currentCourse.StartDate);
                    }
                    else
                    {
                        try
                        {
                            CrossLocalNotifications.Current.Cancel(102);
                        }
                        catch
                        {
                            //ignore
                        }
                    }
                    if (currentCourse.StartNotification || currentCourse.EndNotification)
                    {
                        CrossLocalNotifications.Current.Show("Notifications Set", "Course notifications have been turned on",
                                                             103, DateTime.Now.AddSeconds(1));
                    }
                    if (CourseStatusPicker.SelectedIndex != -1)
                    {
                        currentCourse.Status = CourseStatusPicker.SelectedItem.ToString();
                    }

                    if (InstructorPicker.SelectedItem != null)
                    {
                        var        instructorName = InstructorPicker.SelectedItem.ToString();
                        Instructor instructor     = await App.Database.GetInstructorAsync(instructorName);

                        instructor.Name = InstructorName.Text;
                        string phone = barePhone;
                        if (phone.Length == 10)
                        {
                            phone = phone.Insert(0, "(");
                            phone = phone.Insert(4, ")");
                            phone = phone.Insert(8, "-");
                        }
                        else if (phone.Length == 7)
                        {
                            phone.Insert(3, "-");
                        }
                        instructor.Phone = phone;
                        instructor.Email = InstructorEmail.Text;

                        await App.Database.SaveInstructorAsync(instructor);

                        currentCourse.InstructorID = instructor.InstructorID;
                    }

                    if (NotesSwitch.IsToggled)
                    {
                        currentCourse.NotesPublic = true;

                        // add code for sending sms here
                    }
                    else
                    {
                        currentCourse.NotesPublic = false;
                    }

                    if (Notes.Text != null)
                    {
                        currentCourse.Notes = Notes.Text;
                    }

                    if (Assessment1.Text != null && Assessment1.Text != "No assessment assigned")
                    {
                        var assessment1 = await App.Database.GetAssessmentAsync(Assessment1.Text);

                        currentCourse.AssessmentID = assessment1.AssessmentID;
                    }
                    if (Assessment2.Text != null && Assessment2.Text != "No assessment assigned")
                    {
                        var assessment2 = await App.Database.GetAssessmentAsync(Assessment2.Text);

                        currentCourse.Assessment2ID = assessment2.AssessmentID;
                    }
                    await App.Database.SaveCourseAsync(currentCourse);

                    await Application.Current.MainPage.Navigation.PopAsync();

                    DisplayAlert("Saved", "Course edit has been saved.", "OK");
                }
            }
            catch
            {
                await DisplayAlert("Error", "Error editing course. Check all input fields for accurate data.", "OK");
            }
        }