Beispiel #1
0
        /// <summary>
        /// Save a new Signature Image from a byte array.
        /// </summary>
        /// <param name="imgData"></param>
        public void SaveNewSignature(byte[] imgData)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                Faculty faculty = db.Faculties.Where(f => f.ID == FacultyId).Single();
                faculty.SignatureData = imgData;
                db.SaveChanges();
            }
            MemoryStream str = new MemoryStream();

            str.Seek(0, SeekOrigin.Begin);
            try
            {
                str.Read(imgData, 0, imgData.Length);
            }
            catch
            {
                image = null;
                return;
            }
            MemoryStream mStream = new MemoryStream();

            for (int i = 0; i < imgData.Length; i++)
            {
                mStream.WriteByte(imgData[i]);
            }

            image = Image.FromStream(mStream);
        }
Beispiel #2
0
        /// <summary>
        /// Save a new Signature straight from file content.
        /// </summary>
        /// <param name="inStream"></param>
        public void SaveNewSignature(Stream inStream)
        {
            image = System.Drawing.Image.FromStream(inStream);
            MemoryStream tmpStream = new MemoryStream();

            image.Save(tmpStream, System.Drawing.Imaging.ImageFormat.Png);
            tmpStream.Seek(0, SeekOrigin.Begin);
            byte[] imgBytes = new byte[tmpStream.Length];
            tmpStream.Read(imgBytes, 0, (int)tmpStream.Length);

            using (WebhostEntities db = new WebhostEntities())
            {
                Faculty faculty = db.Faculties.Where(f => f.ID == FacultyId).Single();
                faculty.SignatureData = imgBytes;
                db.SaveChanges();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Create a credit waiver for a given student.
        /// </summary>
        /// <param name="studentId"></param>
        /// <param name="creditTypeId"></param>
        /// <param name="creditValueId"></param>
        /// <param name="notes"></param>
        public static void CreateWaiverCredit(int studentId, int creditTypeId, int creditValueId, String notes = "Waived Credit.")
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                int newCreditId = db.Credits.Count() > 0 ? db.Credits.OrderBy(c => c.id).ToList().Last().id + 1 : 0;

                Credit waiver = new Credit()
                {
                    StudentId     = studentId,
                    CreditTypeId  = creditTypeId,
                    CreditValueId = creditValueId,
                    Notes         = notes
                };

                db.Credits.Add(waiver);
                db.SaveChanges();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Publish all the Weekend Items to the Weekend Duty and Weekend Activities calendars.
        /// </summary>
        /// <param name="WeekendId"></param>
        /// <param name="log">Pass your favorite Log object here in the Web context, or leave it blank to use the Console Standard output.</param>
        public static void PublishWeekendScheduleToGoogleCalendars(int WeekendId, StreamWriter log = null)
        {
            if (log == null)
            {
                log           = new StreamWriter(Console.OpenStandardOutput());
                log.AutoFlush = true;
                log.WriteLine("Hello Console!");
            }
            using (WebhostEntities db = new WebhostEntities())
            {
                using (GoogleCalendarCall gcal = new GoogleCalendarCall())
                {
                    Weekend weekend = db.Weekends.Where(w => w.id == WeekendId).Single();
                    log.WriteLine("Publishing {0} Weekend {1}", weekend.DutyTeam.Name, weekend.StartDate.ToShortDateString());
                    String dutyCalendarId       = db.GoogleCalendars.Where(c => c.CalendarName.Equals("Weekend Duty")).Single().CalendarId;
                    String activitiesCalendarId = db.GoogleCalendars.Where(c => c.CalendarName.Equals("Weekend Activities")).Single().CalendarId;

                    foreach (WeekendDuty duty in weekend.WeekendDuties.ToList())
                    {
                        if (duty.GoogleCalendarEventId.Equals(""))
                        {
                            log.WriteLine("Creating New Event for {0}, {1} {2}", duty.Name, duty.DateAndTime.ToLongDateString(), duty.DateAndTime.ToShortTimeString());
                            duty.GoogleCalendarEventId = gcal.PostEventToCalendar(dutyCalendarId, duty.Name, duty.DateAndTime, TimeSpan.FromMinutes(duty.Duration), duty.Description);
                            log.WriteLine("Got EventId:  {0}", duty.GoogleCalendarEventId);
                        }
                        else
                        {
                            log.WriteLine("Updating EventId: {0}", duty.GoogleCalendarEventId);
                            try
                            {
                                gcal.UpdateEvent(dutyCalendarId, duty.GoogleCalendarEventId, duty.Name, duty.DateAndTime, TimeSpan.FromMinutes(duty.Duration), duty.Description);
                            }
                            catch (GoogleAPICall.GoogleAPIException gae)
                            {
                                log.WriteLine(gae.Message);
                                log.WriteLine(gae.InnerException.Message);
                                log.WriteLine("Creating New Event for {0}, {1} {2}", duty.Name, duty.DateAndTime.ToLongDateString(), duty.DateAndTime.ToShortTimeString());
                                duty.GoogleCalendarEventId = gcal.PostEventToCalendar(dutyCalendarId, duty.Name, duty.DateAndTime, TimeSpan.FromMinutes(duty.Duration), duty.Description);
                                log.WriteLine("Got EventId:  {0}", duty.GoogleCalendarEventId);
                            }
                        }

                        List <String> participants = gcal.GetEventParticipants(dutyCalendarId, duty.GoogleCalendarEventId);
                        foreach (Faculty adult in duty.DutyTeamMembers.ToList())
                        {
                            if (participants.Contains(adult.UserName))
                            {
                                log.WriteLine("{0} {1} is already assigned to this Event.", adult.FirstName, adult.LastName);
                                participants.Remove(adult.UserName);
                            }
                            else
                            {
                                gcal.AddEventParticipant(dutyCalendarId, duty.GoogleCalendarEventId, adult.UserName);
                                log.WriteLine("Added {0} {1} to this event.", adult.FirstName, adult.LastName);
                            }
                        }

                        foreach (String toRemove in participants)
                        {
                            gcal.RemoveParticipant(dutyCalendarId, duty.GoogleCalendarEventId, toRemove);
                            log.WriteLine("Removed no longer assigned adult {0}", toRemove);
                        }
                    }

                    foreach (WeekendActivity activity in weekend.WeekendActivities.ToList())
                    {
                        if (activity.GoogleCalendarEventId.Equals(""))
                        {
                            log.WriteLine("Creating New Event for {0}, {1} {2}", activity.Name, activity.DateAndTime.ToLongDateString(), activity.DateAndTime.ToShortTimeString());
                            activity.GoogleCalendarEventId = gcal.PostEventToCalendar(activitiesCalendarId, activity.Name, activity.DateAndTime, TimeSpan.FromMinutes(activity.Duration), activity.Description);
                            log.WriteLine("Got EventId:  {0}", activity.GoogleCalendarEventId);
                        }
                        else
                        {
                            log.WriteLine("Updating EventId: {0}", activity.GoogleCalendarEventId);
                            try
                            {
                                gcal.UpdateEvent(activitiesCalendarId, activity.GoogleCalendarEventId, activity.Name, activity.DateAndTime, TimeSpan.FromMinutes(activity.Duration), activity.Description);
                            }
                            catch (GoogleAPICall.GoogleAPIException gae)
                            {
                                log.WriteLine(gae.Message);
                                log.WriteLine(gae.InnerException.Message);
                                log.WriteLine("Creating New Event for {0}, {1} {2}", activity.Name, activity.DateAndTime.ToLongDateString(), activity.DateAndTime.ToShortTimeString());
                                activity.GoogleCalendarEventId = gcal.PostEventToCalendar(activitiesCalendarId, activity.Name, activity.DateAndTime, TimeSpan.FromMinutes(activity.Duration), activity.Description);
                                log.WriteLine("Got EventId:  {0}", activity.GoogleCalendarEventId);
                            }
                        }

                        List <String> participants = gcal.GetEventParticipants(activitiesCalendarId, activity.GoogleCalendarEventId).Where(un => !un.Contains("_")).ToList();
                        foreach (Faculty adult in activity.Adults.ToList())
                        {
                            if (participants.Contains(adult.UserName))
                            {
                                log.WriteLine("{0} {1} is already assigned to this Event.", adult.FirstName, adult.LastName);
                                participants.Remove(adult.UserName);
                            }
                            else
                            {
                                gcal.AddEventParticipant(activitiesCalendarId, activity.GoogleCalendarEventId, adult.UserName);
                                log.WriteLine("Added {0} {1} to this event.", adult.FirstName, adult.LastName);
                            }
                        }

                        foreach (String toRemove in participants)
                        {
                            gcal.RemoveParticipant(activitiesCalendarId, activity.GoogleCalendarEventId, toRemove);
                            log.WriteLine("Removed no longer assigned adult {0}", toRemove);
                        }
                    }
                }

                db.SaveChanges();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Assigns Default Credit Values for all classes for all students.  These credits may be modified later and will be passed over by this method if it is run again.
        /// </summary>
        /// <returns>CSV object containing all new credits which have been created.</returns>
        public static CSV AssignDefaultCredits()
        {
            CSV output = new CSV();

            using (WebhostEntities db = new WebhostEntities())
            {
                int newCreditId = db.Credits.Count() > 0? db.Credits.OrderBy(c => c.id).ToList().Last().id + 1 : 0;

                foreach (AcademicYear acadYear in db.AcademicYears.ToList())
                {
                    GradeTable CreditTypes;
                    GradeTable CreditValues;
                    try
                    {
                        CreditTypes  = acadYear.GradeTables.Where(t => t.Name.Equals("Credit Types")).Single();
                        CreditValues = acadYear.GradeTables.Where(t => t.Name.Equals("Credit Values")).Single();
                    }
                    catch
                    {
                        continue;
                    }
                    foreach (Course course in acadYear.Courses.Where(c => c.Sections.Count > 0).ToList())
                    {
                        if (CreditTypes.GradeTableEntries.Where(t => course.Department.Name.Contains(t.Name)).Count() <= 0)
                        {
                            WebhostEventLog.Syslog.LogInformation("Skipping nonsense credit for {0}", course.Name);
                            continue;
                        }
                        foreach (Section section in course.Sections.Where(s => s.Students.Count > 0).ToList())
                        {
                            GradeTableEntry creditType  = CreditTypes.GradeTableEntries.Where(t => course.Department.Name.Contains(t.Name)).Single();
                            GradeTableEntry creditValue = CreditValues.GradeTableEntries.Where(v => v.Value == course.LengthInTerms * 3).Single();

                            foreach (Student student in section.Students.ToList())
                            {
                                // if this student already has credit for this section, then don't do anything!  it may be that the credit has been altered.
                                if (student.Credits.Where(c => c.Sections.Contains(section)).Count() <= 0)
                                {
                                    WebhostEventLog.Syslog.LogInformation("Giving {0} {1} credit for [{2}] {3}", student.FirstName, student.LastName, section.Block.LongName, section.Course.Name);
                                    Credit credit = new Credit()
                                    {
                                        id            = newCreditId++,
                                        StudentId     = student.ID,
                                        CreditTypeId  = creditType.id,
                                        CreditValueId = creditValue.id,
                                        Student       = student,
                                        CreditType    = creditType,
                                        CreditValue   = creditValue,
                                        Notes         = "This is a default credit."
                                    };

                                    credit.Sections.Add(section);

                                    db.Credits.Add(credit);

                                    Dictionary <String, String> row = new Dictionary <string, string>()
                                    {
                                        { "Student", String.Format("{0} {1}", student.FirstName, student.LastName) },
                                        { "Credit Type", creditType.Name },
                                        { "Credit Value", creditValue.Name },
                                        { "Class", section.Course.Name },
                                        { "Year", acadYear.id.ToString() }
                                    };

                                    output.Add(row);
                                }
                                else
                                {
                                    WebhostEventLog.Syslog.LogInformation("{0} {1} already has credit for {2}. Nothing to do.", student.FirstName, student.LastName, section.Course.Name);
                                }
                            }
                        }
                    }
                }

                db.SaveChanges();
            }

            return(output);
        }
Beispiel #6
0
        /// <summary>
        /// Import Credits from Blackbaud.
        /// Use the Query named for this in Blackbaud.
        /// Returns a CSV contaning everything that was ignored or errored.
        /// </summary>
        /// <param name="creditCSV"></param>
        /// <returns></returns>
        public static CSV ImportCredits(CSV creditCSV)
        {
            CSV output = new CSV();

            using (WebhostEntities db = new WebhostEntities())
            {
                int newCreditId = db.Credits.Count() > 0 ? db.Credits.OrderBy(c => c.id).Select(c => c.id).ToList().Last() + 1 : 0;
                int year        = DateRange.GetCurrentAcademicYear();
                foreach (Dictionary <String, String> row in creditCSV.Data)
                {
                    String note      = String.Format("Imported {5} Credit for {0} taken {1} {2} - {3} {4}", row[Credit_CourseName], row[Credit_Term], row[Credit_AcademicYear], row[Credit_FirstName], row[Credit_LastName], row[Credit_Department]);
                    int    studentId = Convert.ToInt32(row[Credit_StudentId]);
                    if (db.Students.Where(s => s.ID == studentId).Count() <= 0)
                    {
                        output.Add(new Dictionary <string, string>()
                        {
                            { "Student", String.Format("{0} {1}", row[Credit_FirstName], row[Credit_LastName]) }, { "Error", "Not in Webhost" }
                        });
                        continue;
                    }
                    Student student = db.Students.Where(s => s.ID == studentId).Single();
                    if (student.Credits.Where(c => c.Notes.Equals(note)).Count() > 0)
                    {
                        output.Add(new Dictionary <string, string>()
                        {
                            { "Student", String.Format("{0} {1}", row[Credit_FirstName], row[Credit_LastName]) }, { "Error", String.Format("{3} Credit already exists for {0} taken {1} {2}", row[Credit_CourseName], row[Credit_Term], row[Credit_AcademicYear], row[Credit_Department]) }
                        });
                        continue; // Don't re-import the same credit more than once!
                    }


                    GradeTable CreditTypes;
                    GradeTable CreditValues;
                    try
                    {
                        CreditTypes  = db.GradeTables.Where(t => t.Name.Equals("Credit Types") && t.AcademicYearID == year).Single();
                        CreditValues = db.GradeTables.Where(t => t.Name.Equals("Credit Values") && t.AcademicYearID == year).Single();
                    }
                    catch
                    {
                        continue;
                    }

                    String dept = row[Credit_Department];
                    if (CreditTypes.GradeTableEntries.Where(t => dept.Contains(t.Name)).Count() <= 0)
                    {
                        output.Add(new Dictionary <string, string>()
                        {
                            { "Student", String.Format("{0} {1}", row[Credit_FirstName], row[Credit_LastName]) }, { "Error", String.Format("{3} No credit given for {0} taken {1} {2}", row[Credit_CourseName], row[Credit_Term], row[Credit_AcademicYear], row[Credit_Department]) }
                        });
                        continue;
                    }
                    Credit credit = new Credit()
                    {
                        StudentId     = studentId,
                        Notes         = note,
                        CreditTypeId  = CreditTypes.GradeTableEntries.Where(t => dept.Contains(t.Name)).Single().id,
                        CreditValueId = CreditValues.GradeTableEntries.Where(v => v.Value == 3).Single().id,
                        id            = newCreditId++
                    };

                    db.Credits.Add(credit);
                }

                db.SaveChanges();
            }

            return(output);
        }