Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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;
     }
 }