Esempio n. 1
0
        protected void ResetBtn_Click(object sender, EventArgs e)
        {
            String response = "";
            bool   success  = true;
            String passwd   = RandomizeCB.Checked ? WebhostMySQLConnection.AccountManagement.AccountManagement.GenerateRandomPassword() : NewPasswordInput.Text;

            try
            {
                PasswordReset.ChangeAllPasswords(EmailSelect.SelectedValue, "", passwd, "dublinschool.org", true);
                response = String.Format("Password for {0}@dublinschool.org has been set to {1}{2}Please visit https://webhost.dublinschool.org/PasswordInitialization.aspx to set your own password.", EmailSelect.SelectedValue, passwd, Environment.NewLine);
            }
            catch (GoogleAPICall.GoogleAPIException ge)
            {
                response = ge.Message;
                Exception inner = ge.InnerException;
                while (inner != null)
                {
                    response += Environment.NewLine + inner.Message;
                    inner     = inner.InnerException;
                }
                success = false;
                LogError("Failed to reset password:{0}{0}{1}", Environment.NewLine, response);
            }

            if (success && !ResetInfoEmail.Text.Equals(""))
            {
                MailControler.MailToUser("Password Reset", response, ResetInfoEmail.Text, EmailSelect.SelectedValue);
            }

            MailControler.MailToWebmaster("Password Reset Info", response);
            LogInformation("Password for {0} has been reset by {1}", EmailSelect.SelectedValue, bPage.user.Name);
        }
 protected void CancelNoteBtn_Click(object sender, EventArgs e)
 {
     LogError(String.Format("User has actively aborted entering requested data for {0}", ClassInfoLabel.Text),
              typeof(Dictionary <int, AttendanceControl.AdditionalInfoRequest>),
              (Dictionary <int, AttendanceControl.AdditionalInfoRequest>)Session["required_update_info"]);
     MailControler.MailToUser("User has actively aborted entering requested data.",
                              String.Format("{0} actively ignored the request for additional information on attendance markings for {1}.  These markings changes have been rejected.",
                                            user.Name, ClassInfoLabel.Text), MailControler.DeanOfStudents.Email, MailControler.DeanOfStudents.Name, user);
     MailControler.MailToUser("Aborted entering requested data.",
                              String.Format("You actively ignored the request for additional information on attendance markings for {1}.  These markings changes have been rejected.",
                                            user.Name, ClassInfoLabel.Text), user);
     Session["required_update_info"] = null;
     Redirect("~/Mobile/Attendance.aspx");
 }
        protected void LoadTable()
        {
            Dictionary <String, int> map    = MorningMeetingSeatClicker.MapMarkingToGradeTableEntry();
            Dictionary <int, String> revmap = new Dictionary <int, string>();

            foreach (String key in map.Keys)
            {
                revmap.Add(map[key], key);
            }

            using (WebhostEntities db = new WebhostEntities())
            {
                int     mmid           = AttendanceControl.MorningMeetingSectionId();
                Section morningmeeting = db.Sections.Where(sec => sec.id == mmid).Single();
                if (morningmeeting.SeatingCharts.Count <= 0)
                {
                    MailControler.MailToUser("Morning Meeting Seating Chart.", AttendanceControl.GenerateMorningMeetingSeatingChart(), ((BasePage)Page).user);
                }

                String       rows  = "ABCDEFGHIJKL";
                SeatingChart chart = db.Sections.Where(sec => sec.id == mmid).Single().SeatingCharts.ToList().First();
                foreach (SeatingChartSeat seat in chart.SeatingChartSeats.Where(s => s.StudentId.HasValue).ToList())
                {
                    String id = String.Format("{0}{1}", rows[seat.Row], seat.Column + 1);
                    seatControls.Where(sc => sc.ID.Equals(id)).Single().StudentId = seat.StudentId.Value;
                    seatControls.Where(sc => sc.ID.Equals(id)).Single().ToolTip   = String.Format("{0} {1}", seat.Student.FirstName, seat.Student.LastName);
                    if (morningmeeting.AttendanceMarkings.Where(mk => mk.AttendanceDate.Equals(SelectedDate) && mk.StudentID == seat.StudentId.Value).Count() > 0)
                    {
                        seatControls.Where(sc => sc.ID.Equals(id)).Single().Marking = revmap[morningmeeting.AttendanceMarkings.Where(mk => mk.AttendanceDate.Equals(SelectedDate) && mk.StudentID == seat.StudentId.Value).Single().MarkingIndex];
                    }
                    else
                    {
                        seatControls.Where(sc => sc.ID.Equals(id)).Single().Marking = "OK";
                    }
                }

                foreach (MorningMeetingSeatClicker clicker in seatControls)
                {
                    clicker.Enabled = clicker.StudentId != -1;
                }
            }
        }
Esempio n. 4
0
        protected static void ExecuteStudentRequest(XMLTree xml, String saveDir)
        {
            int termId = Convert.ToInt32(xml.Attributes["termid"]);

            List <int> studentIds = new List <int>();

            foreach (XMLTree studentTree in xml.ChildTrees.Where(tree => tree.TagName.Equals("student")).ToList())
            {
                int studentId = Convert.ToInt32(studentTree.Attributes["studentid"]);
                studentIds.Add(studentId);
            }

            String fileName = CommentLetter.PublishTermByStudent(termId, studentIds, saveDir);

            MailControler.MailToUser("Comments Published Successfully",
                                     String.Format("Click the Link to download the comments you requested:{0}{1}",
                                                   Environment.NewLine,
                                                   fileName.Replace("W:", "https://webhost.dublinschool.org").Replace("\\", "/")),
                                     String.Format("{0}@dublinschool.org", xml.Attributes["username"]),
                                     xml.Attributes["name"],
                                     "*****@*****.**", "Comment Bot");
        }
Esempio n. 5
0
        protected static void ExecuteClassRequest(XMLTree xml, String saveDir)
        {
            int termId = Convert.ToInt32(xml.Attributes["termid"]);

            List <int>    studentIds = new List <int>();
            List <String> filenames  = new List <string>();

            foreach (XMLTree studentTree in xml.ChildTrees.Where(tree => tree.TagName.Equals("section")).ToList())
            {
                int headerId = Convert.ToInt32(studentTree.Attributes["headerid"]);
                filenames.Add(CommentLetter.PublishClass(headerId, saveDir));
            }

            String zipFile = MailControler.PackForDownloading(filenames, String.Format("{0}\\classes_{1}.zip", saveDir, DateTime.Now.Ticks));

            MailControler.MailToUser("Comments Published Successfully",
                                     String.Format("Click the Link to download the comments you requested:{0}{1}",
                                                   Environment.NewLine,
                                                   zipFile.Replace("W:", "https://webhost.dublinschool.org").Replace("\\", "/")),
                                     String.Format("{0}@dublinschool.org", xml.Attributes["username"]),
                                     xml.Attributes["name"].Replace('_', ' '),
                                     "*****@*****.**", "Comment Bot");
        }
Esempio n. 6
0
        protected void LoadInfo(int sectionId, DateTime date)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                int        year        = DateRange.GetCurrentAcademicYear();
                GradeTable attMarkings = db.GradeTables.Where(t => t.AcademicYearID == year && t.Name.Equals("Attendance")).Single();
                AttendanceTable.Rows.Clear();
                Section section = db.Sections.Where(sec => sec.id == sectionId).Single();
                ClassNameLabel.Text = String.Format("[{0}] {1}", section.Block.LongName, section.Course.Name);



                AttendancePageInfo api = new AttendancePageInfo()
                {
                    SectionId   = sectionId,
                    Date        = date,
                    Name        = ClassNameLabel.Text,
                    Attendances = new List <AttendanceData>()
                };

                List <Student> StudentRoster = section.Course.Name.Equals("Morning Meeting") ?
                                               section.Students.OrderBy(s => s.GraduationYear).ThenBy(s => s.LastName).ThenBy(s => s.FirstName).ToList() :
                                               section.Students.OrderBy(s => s.LastName).ThenBy(s => s.FirstName).ToList();

                bool allSubmitted = true;

                foreach (Student student in StudentRoster)
                {
                    AttendanceMarking mark = null;
                    AttendanceData    atd  = new AttendanceData()
                    {
                        StudentId = student.ID, Name = String.Format("{0} {1}", student.FirstName, student.LastName)
                    };

                    if (section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).Count() == 1)
                    {
                        mark = section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).Single();
                    }
                    else if (section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).Count() > 1)
                    {
                        LogError("Multiple Attendance Markings found for {0} {1} in [{2}] {3} on {4}", student.FirstName, student.LastName, section.Block.LongName, section.Course.Name, date.ToString("DDD dd MMM, yyyy"));
                        AttendanceMarking        toKeep   = null;
                        List <AttendanceMarking> toDelete = section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).ToList();
                        foreach (AttendanceMarking errMark in toDelete)
                        {
                            if (toKeep == null)
                            {
                                toKeep = errMark;
                            }

                            if (toKeep.Marking.Name.Equals("Excused"))
                            {
                                break;
                            }

                            if (errMark.SubmissionTime > toKeep.SubmissionTime)
                            {
                                toKeep = errMark;
                            }
                        }

                        toDelete.Remove(toKeep);

                        db.AttendanceMarkings.RemoveRange(toDelete);
                        db.SaveChanges();
                        foreach (Faculty teacher in section.Teachers.ToList())
                        {
                            MailControler.MailToUser("Attendance Needs Checking.",
                                                     String.Format("There was a problem with the marking for {0} {1} in [{2}] {3} on {4}.  I have attempted to correct the error, but you should double check it.  Currently, they are marked as {5}.", student.FirstName, student.LastName, section.Block.LongName, section.Course.Name, date.ToString("DDD dd MMM, yyyy"), toKeep.Marking.Name),
                                                     String.Format("{0}@dublinschool.org", teacher.UserName),
                                                     String.Format("{0} {1}", teacher.FirstName, teacher.LastName));
                        }
                    }
                    else
                    {
                        allSubmitted = false;
                    }

                    TableRow  row       = new TableRow();
                    TableCell nameCell  = new TableCell();
                    Label     nameLabel = new Label()
                    {
                        Text    = student.FirstName + " " + student.LastName,
                        ToolTip = "Advisor:  " + student.Advisor.FirstName + " " + student.Advisor.LastName,
                        Width   = Unit.Percentage(60)
                    };
                    HiddenField sidf = new HiddenField()
                    {
                        Value = Convert.ToString(student.ID)
                    };

                    nameCell.Controls.Add(sidf);
                    nameCell.Controls.Add(nameLabel);

                    TableCell       markingCell = new TableCell();
                    RadioButtonList markddl     = new RadioButtonList()
                    {
                        Width = Unit.Percentage(100), RepeatLayout = RepeatLayout.Table, RepeatDirection = RepeatDirection.Horizontal, RepeatColumns = 2, CssClass = "table_fixed"
                    };
                    int presentId = attMarkings.GradeTableEntries.Where(m => m.Name.Equals("Present")).Single().id;
                    markddl.DataSource     = attMarkings.GradeTableEntries.ToList();
                    markddl.DataTextField  = "Name";
                    markddl.DataValueField = "id";
                    markddl.DataBind();

                    if (mark != null)
                    {
                        markddl.ClearSelection();
                        markddl.SelectedValue = Convert.ToString(mark.MarkingIndex);
                        atd.Marking           = mark.Marking.Name;
                    }
                    else
                    {
                        markddl.ClearSelection();
                        markddl.SelectedValue = Convert.ToString(presentId);
                        atd.Marking           = "Present";
                    }

                    markingCell.Controls.Add(markddl);
                    ((List <AttendanceData>)api.Attendances).Add(atd);
                    row.BorderWidth = Unit.Pixel(2);
                    row.BorderStyle = BorderStyle.Solid;

                    row.Cells.Add(nameCell);
                    row.Cells.Add(markingCell);
                    AttendanceTable.Rows.Add(row);
                }

                if (section.AttendanceSubmissionStatuses.Where(s => s.Day.Equals(date) && s.AttendanceStatus.Blocking).Count() > 0)
                {
                    AttendanceSubmissionStatus status = section.AttendanceSubmissionStatuses.Where(s => s.Day.Equals(date)).Single();
                    if (status.TimeStamp.AddSeconds(5 * section.Students.Count) < DateTime.Now)
                    {
                        LogError("There was a problem entering attendance for [{0}] {1} at {2}. I will let the user know that there was a problem.",
                                 section.Block.LongName, section.Course.Name, status.TimeStamp.ToString("dddd, dd MM - h:mm:ss"));

                        if (allSubmitted) // calculated manually above!
                        {
                            LogInformation("Attendance was submitted earlier--but may not have been updated correctly.");
                            MailControler.MailToUser("Attendance Problem",
                                                     String.Format("Hello,{0}" +
                                                                   "Your attendance entry for [{1}] {2} had a problem when you tried to submit it at {3}.  There are saved attendance entries, but they may not be correct.  Please double check the entries and resubmit if necessary.{0}{0}Thanks!",
                                                                   Environment.NewLine, section.Block.LongName, section.Course.Name, status.TimeStamp.ToString("dddd, dd MM - h:mm:ss")), user, "*****@*****.**", "Attendance Bot");
                            SubmittedLabel.Text     = "You have not yet entered attendance data.";
                            SubmittedLabel.CssClass = "incomplete_highlight";
                            status.TimeStamp        = DateTime.Now;
                            status.StatusId         = db.AttendanceStatuses.Where(st => st.Name.Equals("Not Submitted")).Single().id;
                        }
                        else
                        {
                            LogInformation("Attendance was not submitted prior to this attempt.");
                            MailControler.MailToUser("Attendance Problem",
                                                     String.Format("Hello,{0}" +
                                                                   "Your attendance entry for [{1}] {2} had a problem when you tried to submit it at {3}.  There are incomplete attendance records right now.  Please double check the entries and resubmit your attendance for this class.{0}{0}Thanks!",
                                                                   Environment.NewLine, section.Block.LongName, section.Course.Name, status.TimeStamp.ToString("dddd, dd MM - h:mm:ss")), user, "*****@*****.**", "Attendance Bot");
                            SubmittedLabel.Text     = "Successfully Submitted.";
                            SubmittedLabel.CssClass = "success_highlight";
                            status.TimeStamp        = DateTime.Now;
                            status.StatusId         = db.AttendanceStatuses.Where(st => st.Name.Equals("Submitted")).Single().id;
                        }
                        db.SaveChanges();
                    }
                    else
                    {
                        LogWarning("The attendance for [{0}] {1} is still processing (less than the alotted {2} seconds have passed).", section.Block.LongName, section.Course.Name, (5 * section.Students.Count));
                        MailControler.MailToUser(String.Format("Attendance Submission Status for [{0}] {1}", section.Block.LongName, section.Course.Name),
                                                 String.Format("Hello,{0}Your attendance for [{1}] {2} is still processing.  Because of the number of students in your class, this may take as long as {3}:{4} minutes.  Wait at least that long and check again to see if it has submitted properly.",
                                                               Environment.NewLine, section.Block.LongName, section.Course.Name, (5 * section.Students.Count) / 60, (5 * section.Students.Count) % 60), user, "*****@*****.**", "Attendance Bot");
                        SubmittedLabel.Text     = "Attendance for this section is Currently Processing.";
                        SubmittedLabel.CssClass = "working_highlight";
                    }
                }
                else if (allSubmitted)
                {
                    SubmittedLabel.Text     = "Successfully Submitted.";
                    SubmittedLabel.CssClass = "success_highlight";
                }
                else
                {
                    SubmittedLabel.Text     = "You have not yet entered attendance data.";
                    SubmittedLabel.CssClass = "incomplete_highlight";
                }

                LogCurrentData(api);
            }
        }
Esempio n. 7
0
        protected void ConfirmBtn_Click(object sender, EventArgs e)
        {
            if (DateTime.Today.DayOfWeek.Equals(DayOfWeek.Saturday) || DateTime.Today.Day.Equals(DayOfWeek.Sunday))
            {
                LogInformation("No Email Pings on the weekend!");
                return;
            }

            using (WebhostEntities db = new WebhostEntities())
            {
                Dictionary <Faculty, List <Section> > needAttendance = new Dictionary <Faculty, List <Section> >();
                int  tid  = DateRange.GetCurrentOrLastTerm();
                Term term = db.Terms.Find(tid);

                foreach (Section section in term.Sections.ToList())
                {
                    if (section.Block.IsSpecial)
                    {
                        continue;                          // don't mark these blocks...
                    }
                    switch (DateTime.Today.DayOfWeek)
                    {
                    case DayOfWeek.Monday: if (!section.Block.MeetsMonday)
                        {
                            continue;
                        }
                        break;

                    case DayOfWeek.Tuesday: if (!section.Block.MeetsTuesday)
                        {
                            continue;
                        }
                        break;

                    case DayOfWeek.Wednesday:
                        if (!section.Block.MeetsWednesday || section.Course.Name.Contains("Tutorial"))
                        {
                            continue;
                        }
                        else if (db.WednesdaySchedules.Where(w => w.Day.Equals(DateTime.Today)).Count() > 0)
                        {
                            WednesdaySchedule wed = db.WednesdaySchedules.Where(w => w.Day.Equals(DateTime.Today)).Single();
                            if (wed.IsABC && (new Regex("[DEF]")).IsMatch(section.Block.Name))
                            {
                                continue;
                            }
                        }
                        break;

                    case DayOfWeek.Thursday: if (!section.Block.MeetsThursday)
                        {
                            continue;
                        }
                        break;

                    case DayOfWeek.Friday: if (!section.Block.MeetsFriday)
                        {
                            continue;
                        }
                        break;

                    default: break;
                    }

                    if (section.AttendanceMarkings.Where(at => at.AttendanceDate.Equals(DateTime.Today)).Count() <= 0)
                    {
                        LogWarning("No attendance has been submitted for [{0}] {1}", section.Block.LongName, section.Course.Name);
                        foreach (Faculty teacher in section.Teachers.ToList())
                        {
                            if (!needAttendance.ContainsKey(teacher))
                            {
                                LogWarning("Adding {0} {1} to the Notify list.", teacher.FirstName, teacher.LastName);
                                needAttendance.Add(teacher, new List <Section>()
                                {
                                    section
                                });
                            }
                            else
                            {
                                needAttendance[teacher].Add(section);
                            }
                        }
                    }
                }

                String Subject      = "Please submit attendance";
                String BodyTemplate = "You have not entered attendance today for the following classes:" + Environment.NewLine;
                String DigestBody   = "The following Teachers have been informed that their attendance has not been taken for the indicated classes.";

                foreach (Faculty teacher in needAttendance.Keys)
                {
                    LogInformation("Sending Request Email to {0} {1} for {2} classes.", teacher.FirstName, teacher.LastName, needAttendance[teacher].Count);
                    String Body = String.Format("Dear {0},{1}{1}{2}", teacher.FirstName, Environment.NewLine, BodyTemplate);

                    DigestBody += String.Format("{0}{0}____________________________________{0}{1} {2}:", Environment.NewLine, teacher.FirstName, teacher.LastName);

                    foreach (Section section in needAttendance[teacher])
                    {
                        Body       += String.Format("{0}[{1}] {2}", Environment.NewLine, section.Block.LongName, section.Course.Name);
                        DigestBody += String.Format("{0}[{1}] {2}", Environment.NewLine, section.Block.LongName, section.Course.Name);
                    }

                    Body += String.Format("{0}{0}Thanks,{0}Dean of Students Office{0}{0}CC:[email protected], {1}@dublinschool.org", Environment.NewLine, teacher.UserName);

                    MailControler.MailToUser(Subject, Body, String.Format("{0}@dublinschool.org", teacher.UserName), String.Format("{0} {1}", teacher.FirstName, teacher.LastName));
                    //MailControler.MailToUser(Subject, Body, MailControler.DeanOfStudents.Email, MailControler.DeanOfStudents.Name);
                    //MailControler.MailToWebmaster(Subject, Body);
                }

                MailControler.MailToWebmaster("Attendance Reminder Digest", DigestBody);
                MailControler.MailToUser("Attendance Reminder Digest", DigestBody, MailControler.DeanOfStudents.Email, MailControler.DeanOfStudents.Name);
                LogInformation("Done sending Attendance Reminders.");
            }
            ConfirmPanel.Visible = false;
        }
        protected void Signup_Click(object sender, EventArgs e)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                WeekendActivity activity   = db.WeekendActivities.Where(act => act.id == ActivityId).Single();
                int             studentId  = ((BasePage)Page).user.ID;
                String          calendarId = db.GoogleCalendars.Where(c => c.CalendarName.Equals("Weekend Activities")).Single().CalendarId;
                Student         student    = db.Students.Where(s => s.ID == studentId).Single();
                LogInformation("Processing {0} click for {1}.", Signup.Text, activity.Name);

                /*
                 * // Check Campused
                 * if(activity.Weekend.CampusedStudents.Contains(student))
                 * {
                 *  State.log.WriteLine("Signup was blocked.  Campused!");
                 *  MailControler.MailToUser("Signup was blocked.", String.Format("You are not allowed to sign up for {0} because you have been campused this weekend.", activity.Name), ((BasePage)Page).user);
                 *  return;
                 * }
                 *
                 * // Check Detention
                 * DateRange activityTimes = activity.DateAndTime.Hour == 0 ? new DateRange(activity.DateAndTime, activity.DateAndTime.AddDays(1)) :
                 *                              activity.Duration == 0 ? new DateRange(activity.DateAndTime, activity.DateAndTime.AddHours(3)) :
                 *                                                       new DateRange(activity.DateAndTime, activity.DateAndTime.AddMinutes(activity.Duration));
                 *
                 * if(activityTimes.Intersects(DateRange.Detention) && activity.Weekend.DetentionList.Contains(student))
                 * {
                 *  State.log.WriteLine("Signup was blocked.  Detention!");
                 *  MailControler.MailToUser("Signup was blocked.", String.Format("You are not allowed to sign up for {0} because you are in Detention this weekend.", activity.Name), ((BasePage)Page).user);
                 *  return;
                 * }
                 */
                if (Signup.Text.Contains("Remove"))
                {
                    State.log.WriteLine("Removing {0} {1} from {2}", student.FirstName, student.LastName, activity.Name);
                    LogInformation("Removing {0} {1} from {2}", student.FirstName, student.LastName, activity.Name);
                    try
                    {
                        WebhostMySQLConnection.StudentSignup signup = student.StudentSignups.Where(sig => sig.ActivityId == ActivityId).Single();
                        signup.IsRescended = true;
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        State.log.WriteLine("Failed to remove...\r\n{0}", ex.Message);
                        LogError("Failed to remove {0} {1} from {2}\r\n{3}", student.FirstName, student.LastName, activity.Name, ex.Message);
                        MailControler.MailToWebmaster("Webhost Error:  Removing Signup", String.Format(
                                                          "Could not remove {0} {1} from signup {2}\r\n{3}", student.FirstName, student.LastName, activity.Name, ex.Message
                                                          ));

                        return;
                    }

                    if (!activity.GoogleCalendarEventId.Equals(""))
                    {
                        using (GoogleCalendarCall gcal = new GoogleCalendarCall())
                        {
                            gcal.RemoveParticipant(calendarId, activity.GoogleCalendarEventId, student.UserName);
                            State.log.WriteLine("Removed {0} {1} from Calendar Event.");
                        }
                    }
                }
                else
                {
                    State.log.WriteLine("Atempting to sign up {0} {1} for {2}", student.FirstName, student.LastName, activity.Name);
                    if (student.StudentSignups.Where(sig => sig.ActivityId == ActivityId).Count() > 0)
                    {
                        WebhostMySQLConnection.StudentSignup signup = student.StudentSignups.Where(sig => sig.ActivityId == ActivityId).Single();
                        if (signup.IsBanned)
                        {
                            State.log.WriteLine("Signup was blocked.");
                            LogWarning("{0} {1} was blocked from signing up for {2} because they have been banned.", student.FirstName, student.LastName, activity.Name);
                            MailControler.MailToUser("Signup was blocked.", String.Format("You are not allowed to sign up for {0}", activity.Name), ((BasePage)Page).user);
                            return;
                        }

                        signup.IsRescended = false;
                        signup.TimeStamp   = DateTime.Now;
                        Signup.Text        = "Sign me up!";
                        State.log.WriteLine("Re-signed up!");
                        LogInformation("{0} {1} has resigned up for {2}.", student.FirstName, student.LastName, activity.Name);
                    }
                    else
                    {
                        WebhostMySQLConnection.StudentSignup newSig = new WebhostMySQLConnection.StudentSignup()
                        {
                            StudentId   = studentId,
                            ActivityId  = ActivityId,
                            IsBanned    = false,
                            IsRescended = false,
                            TimeStamp   = DateTime.Now
                        };

                        db.StudentSignups.Add(newSig);
                        State.log.WriteLine("New Signup created.");
                        LogInformation("{0} {1} has signed up for {2}.", student.FirstName, student.LastName, activity.Name);
                    }

                    if (!activity.GoogleCalendarEventId.Equals(""))
                    {
                        using (GoogleCalendarCall call = new GoogleCalendarCall())
                        {
                            call.AddEventParticipant(calendarId, activity.GoogleCalendarEventId, student.UserName);
                            State.log.WriteLine("Updated calendar Event to include {0}", student.UserName);
                        }
                    }
                    db.SaveChanges();
                }

                State.log.WriteLine("Signup Changes Saved to Database.");
                reload();
            }
        }
Esempio n. 9
0
        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            ShortRequest shreq = new ShortRequest()
            {
                StudentName = user.Name, DeviceType = DeviceType, MACAddress = MACAddrInput.Text
            };

            if (!ValidateMAC())
            {
                ErrorMessage.Text = "The MAC Address you entered is not valid--please check to make sure it is correct.";
                LogError("Invalid MAC Address for {0}", shreq.ToString());
                ErrorPanel.Visible = true;
                return;
            }
            using (WebhostEntities db = new WebhostEntities())
            {
                //Check for Existing Mac Address Request.
                if (db.RegistrationRequests.Where(req => req.MacAddress.Equals(MACAddress)).Count() > 0)
                {
                    WebhostMySQLConnection.RegistrationRequest request = db.RegistrationRequests.Where(req => req.MacAddress.Equals(MACAddress)).Single();
                    if (request.RequestCompleted)
                    {
                        ErrorMessage.Text = "This Device has already been registered.  If you are experiencing difficulties, email Mr. Cox or Mr. Harrison.";
                        LogError("The device has already been registered: {0}", shreq.ToString());
                        MailControler.MailToUser("Your Registration Request has already been registered.", shreq.ToString(), user);
                    }
                    else if (request.RequestDenied)
                    {
                        ErrorMessage.Text = "This device has been rejected.  Please see Mr. Cox or Mr. Harrison for details.";
                        LogError("Registration Request has been rejected: {0}", shreq.ToString());
                        MailControler.MailToUser("Your Registration Request has been rejected.", shreq.ToString(), user);
                    }
                    else
                    {
                        ErrorMessage.Text = "This Device is pending registration.  Don't worry--we'll get to it soon =)";
                        LogError("Impatient User: {0}", shreq);
                        MailControler.MailToUser("Your Registration Request is pending review.", shreq.ToString(), user);
                    }

                    ErrorPanel.Visible = true;
                    return;
                }

                int reqid = db.RegistrationRequests.Count() > 0 ? db.RegistrationRequests.OrderBy(req => req.id).ToList().Last().id + 1 : 0;
                WebhostMySQLConnection.RegistrationRequest nrequest = new WebhostMySQLConnection.RegistrationRequest()
                {
                    id               = reqid,
                    StudentId        = ((BasePage)Page).user.IsStudent?((BasePage)Page).user.ID:10,
                    MacAddress       = MACAddress,
                    DeviceType       = DeviceType,
                    RequestCompleted = false,
                    RequestDenied    = false
                };

                db.RegistrationRequests.Add(nrequest);
                db.SaveChanges();

                LogInformation("New Request submitted: {0}", shreq.ToString());
                if (EmailEnabled)
                {
                    MailControler.MailToWebmaster("New Device Registration Request.", shreq.ToString(), user);
                    MailControler.MailToUser("New Device Registration Request.", shreq.ToString(), "*****@*****.**", "Jeff Harrison", user);
                    MailControler.MailToUser("Your Registration Request has been successfully submitted.", shreq.ToString(), user);
                }
                SuccessPanel.Visible = true;
            }
        }