public WeekendTableItem(WeekendDuty activity)
 {
     DateAndTime = activity.DateAndTime;
     Adults      = activity.DutyTeamMembers.ToList();
     Duration    = activity.Duration;
     Name        = activity.Name;
     Notes       = activity.Description;
 }
Beispiel #2
0
        protected void DeleteActivityBtn_Click(object sender, EventArgs e)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                int id = -1;
                try
                {
                    id = Convert.ToInt32(DeleteActivityDDL.SelectedValue.Substring(1));
                }
                catch
                {
                    State.log.WriteLine("Invalid Activity '{0}' Cannot Delete.", DeleteActivityDDL.SelectedValue);
                    LogError("Invalid Activity '{0}' Cannot Delete.", DeleteActivityDDL.SelectedValue);
                    return;
                }

                if (DeleteActivityDDL.SelectedValue[0] == 'A')
                {
                    WeekendActivity activity = db.WeekendActivities.Find(id);
                    activity.IsDeleted = true;
                    LogInformation("Deleted Weekend Activity {0}", activity.Name);
                    if (!activity.GoogleCalendarEventId.Equals(""))
                    {
                        using (GoogleCalendarCall call = new GoogleCalendarCall())
                        {
                            String message = call.DeleteEvent(db.GoogleCalendars.Where(cal => cal.CalendarName.Equals("Weekend Activities")).Single().CalendarId, activity.GoogleCalendarEventId);
                            State.log.WriteLine("Deleted un-wanted calendar event with response:  {0}", message);
                            activity.GoogleCalendarEventId = "";
                        }
                    }
                }
                else
                {
                    WeekendDuty duty = db.WeekendDuties.Find(id);
                    duty.IsDeleted = true;

                    if (!duty.GoogleCalendarEventId.Equals(""))
                    {
                        using (GoogleCalendarCall call = new GoogleCalendarCall())
                        {
                            String message = call.DeleteEvent(db.GoogleCalendars.Where(cal => cal.CalendarName.Equals("Weekend Duty")).Single().CalendarId, duty.GoogleCalendarEventId);
                            State.log.WriteLine("Deleted un-wanted calendar event with response:  {0}", message);
                            duty.GoogleCalendarEventId = "";
                        }
                    }

                    LogInformation("Deleted Weekend Duty {0}", duty.Name);
                }
                db.SaveChanges();
            }
            LoadWeekend();
        }
Beispiel #3
0
 protected void DeleteBtn_Click(object sender, EventArgs e)
 {
     using (WebhostEntities db = new WebhostEntities())
     {
         WeekendDuty activity = db.WeekendDuties.Where(act => act.id == DutyItemId).Single();
         activity.IsDeleted = true;
         if (!activity.GoogleCalendarEventId.Equals(""))
         {
             using (GoogleCalendarCall call = new GoogleCalendarCall())
             {
                 String message = call.DeleteEvent(db.GoogleCalendars.Where(cal => cal.CalendarName.Equals("Weekend Duty")).Single().CalendarId, activity.GoogleCalendarEventId);
                 State.log.WriteLine("Deleted un-wanted calendar event with response:  {0}", message);
                 activity.GoogleCalendarEventId = "";
             }
         }
         db.SaveChanges();
         SuccessLabel.Text    = "Delete Successful";
         SuccessPanel.Visible = true;
     }
 }
Beispiel #4
0
        public bool Save()
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                State.log.WriteLine("Save Weekend Activity Called.");
                int         id       = DutyItemId;
                Weekend     weekend  = db.Weekends.Where(w => w.id == WeekendId).Single();
                WeekendDuty activity = new WeekendDuty();
                bool        update   = true;

                if (id == -1)
                {
                    State.log.WriteLine("Creating a New Activity.");
                    update      = false;
                    id          = db.WeekendDuties.Count() > 0 ? db.WeekendDuties.OrderBy(act => act.id).ToList().Last().id + 1 : 0;
                    activity.id = id;
                }
                else
                {
                    State.log.WriteLine("Updating existing activity.");
                    activity = db.WeekendDuties.Where(act => act.id == id).Single();
                }

                activity.Name        = DutyInput.Text;
                activity.Description = NotesInput.Text.Equals("Notes") ? "" : NotesInput.Text;

                activity.DutyTeamMembers.Clear();

                foreach (int aid in DutyAssignmentSelector.GroupIds)
                {
                    Faculty fac = db.Faculties.Where(f => f.ID == aid).Single();
                    activity.DutyTeamMembers.Add(fac);
                }

                activity.WeekendId = WeekendId;
                DateTime date = weekend.StartDate.Date.AddDays(DaySelect.SelectedIndex);
                try
                {
                    date = date.AddHours(StartTimeSelector.Hour);
                    date = date.AddMinutes(StartTimeSelector.Minute);
                }
                catch (WebhostException we)
                {
                    State.log.WriteLine(we.Message);
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert_" + UniqueID, String.Format("alert('{0}');", we.Message), true);
                    return(false);
                }

                activity.DateAndTime = date;
                try
                {
                    int hours   = EndTimeSelector.Hour - StartTimeSelector.Hour;
                    int minutes = EndTimeSelector.Minute - StartTimeSelector.Minute;
                    if (minutes < 0)
                    {
                        hours--;
                        minutes = 60 + minutes;
                    }
                    activity.Duration = 60 * hours + minutes;
                }
                catch (WebhostException we)
                {
                    State.log.WriteLine(we.Message);
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert_" + UniqueID, String.Format("alert('{0}');", we.Message), true);
                    return(false);
                }

                if (!update)
                {
                    activity.GoogleCalendarEventId = "";

                    db.WeekendDuties.Add(activity);
                    State.log.WriteLine("Added New Activty to Database.");
                }

                db.SaveChanges();
                State.log.WriteLine("Saved Changes to Database.");
                return(true);
            }
        }
Beispiel #5
0
        protected void LoadTemplate_Click(object sender, EventArgs e)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                if (!LoadWeekendFromDate())
                {
                    // Initialize a new weekend!
                    int id = db.Weekends.Count() > 0 ? db.Weekends.OrderBy(w => w.id).ToList().Last().id + 1 : 0;

                    Weekend weekend = new Weekend()
                    {
                        id            = id,
                        DutyTeamIndex = DutyTeamID,
                        StartDate     = WeekendRange.Start,
                        EndDate       = WeekendRange.End,
                        Notes         = ""
                    };

                    // Get the Weekend to Copy!
                    int otherId = Convert.ToInt32(TemplateDDL.SelectedValue);
                    LogInformation("Copying Weekend.id {0} to the current weekend.", otherId);
                    Weekend other = db.Weekends.Where(w => w.id == otherId).Single();

                    //Copy Activities
                    int actId  = db.WeekendActivities.OrderBy(act => act.id).ToList().Last().id;
                    int dutyId = db.WeekendDuties.Count() > 0 ? db.WeekendDuties.OrderBy(act => act.id).ToList().Last().id : 0;
                    foreach (WeekendActivity activity in other.WeekendActivities.Where(act => !act.IsDeleted))
                    {
                        // Adjust date and time.
                        TimeSpan diff = activity.DateAndTime - activity.Weekend.StartDate;

                        WeekendActivity newActivity = new WeekendActivity()
                        {
                            id                    = ++actId,
                            Name                  = activity.Name,
                            isMandatory           = activity.isMandatory,
                            IsDeleted             = false,
                            IsOffCampus           = activity.IsOffCampus,
                            MaxSignups            = activity.MaxSignups,
                            DateAndTime           = weekend.StartDate + diff,
                            showStudents          = activity.showStudents,
                            WeekendIndex          = id,
                            isSignup              = activity.isSignup,
                            Duration              = activity.Duration,
                            Description           = activity.Description,
                            GoogleCalendarEventId = ""
                        };

                        db.WeekendActivities.Add(newActivity);
                    }

                    foreach (WeekendDuty duty in other.WeekendDuties.Where(duty => !duty.IsDeleted))
                    {
                        // Adjust date and time.
                        TimeSpan diff = duty.DateAndTime - duty.Weekend.StartDate;

                        WeekendDuty newDuty = new WeekendDuty()
                        {
                            id                    = ++dutyId,
                            Name                  = duty.Name,
                            DateAndTime           = weekend.StartDate + diff,
                            WeekendId             = id,
                            Duration              = duty.Duration,
                            Description           = duty.Description,
                            GoogleCalendarEventId = "",
                            IsDeleted             = false
                        };

                        /*if(duty.DutyTeamMembers.Count > 5)
                         * {
                         *  foreach(Faculty member in weekend.DutyTeam.Members.ToList())
                         *  {
                         *      newDuty.DutyTeamMembers.Add(member);
                         *  }
                         * }*/

                        db.WeekendDuties.Add(newDuty);
                    }

                    db.Weekends.Add(weekend);
                    db.SaveChanges();
                    WeekendID = id;
                }

                LoadWeekend();
            }
        }