public List <Models.Appointment> GetAppointments(out string error) { error = string.Empty; List <Models.Appointment> modelAppts = new List <Models.Appointment>(); try { List <Appointment> dbAppts = dbBCS.Appointments.ToList(); foreach (Appointment appt in dbAppts) { Models.Appointment model = new Models.Appointment() { // ID = appt.ID, Body = appt.Body, EndTime = (DateTime)appt.EndTime, Location = appt.Location, StartTime = (DateTime)appt.StartTime, Subject = appt.Subject }; modelAppts.Add(model); } } catch (Exception e) { error = "Critical Error: Could not open Categories DataBase"; } return(modelAppts); }
private void Calendar_AddAppointment(object sender, RoutedEventArgs e) { if (!superuser) { return; } DataAccessLayer.Models.Appointment appointment = new DataAccessLayer.Models.Appointment(); appointment.Subject = ""; double Hour = (e.OriginalSource as CalendarTimeslotItem).Hour; appointment.StartTime = new DateTime(cal.CurrentDate.Year, cal.CurrentDate.Month, cal.CurrentDate.Day, (int)Hour, 0, 0); appointment.EndTime = new DateTime(cal.CurrentDate.Year, cal.CurrentDate.Month, cal.CurrentDate.Day, (int)Hour + 1, 0, 0);; AddAppointmentWindow aaw = new AddAppointmentWindow(); aaw.DataContext = appointment; aaw.ShowDialog(); if (appointment.Subject.Count() == 0) { return; } allAppts.Add(appointment); dbAccess.SaveAppts(appointment); cal.Appointments = Filters.ByDate(allAppts, cal.CurrentDate).ToList(); //we might have added an appointment for today so refresh the left side List <DataAccessLayer.Models.Appointment> today = allAppts.Where(a => a.StartTime.ToShortDateString() == DateTime.Now.ToShortDateString()).ToList(); lvDataBinding.ItemsSource = today; }
private void Delete_Click(object sender, RoutedEventArgs e) { List <DataAccessLayer.Models.Appointment> toRemove = new List <DataAccessLayer.Models.Appointment>(); foreach (object o in lvDataBinding.SelectedItems) { DataAccessLayer.Models.Appointment appt = o as DataAccessLayer.Models.Appointment; dbAccess.DeleteAppointment(appt.Subject, appt.StartTime); toRemove.Add(appt); } toRemove.ForEach(t => allAppts.Remove(t)); toRemove.ForEach(t => today.Remove(t)); if (today.Count == 0) { if (selectedDayButton != null) { selectedDayButton.Foreground = new SolidColorBrush(Colors.Black); } } //we deleted an appointment for today so refresh the left side lvDataBinding.ItemsSource = today; cal.Appointments = today; }
private void Delete_Click(object sender, RoutedEventArgs e) { List <DataAccessLayer.Models.Appointment> toRemove = new List <DataAccessLayer.Models.Appointment>(); foreach (object o in lvDataBinding.SelectedItems) { DataAccessLayer.Models.Appointment appt = o as DataAccessLayer.Models.Appointment; dbAccess.DeleteAppointment(appt.Subject, appt.StartTime); toRemove.Add(appt); } toRemove.ForEach(t => today.Remove(t)); //we might have added an appointment for today so refresh the left side // List<DataAccessLayer.Models.Appointment> revisedAppts = allAppts.Where(a => a.StartTime.ToShortDateString() == DateTime.Now.ToShortDateString()).ToList(); lvDataBinding.ItemsSource = today; cal.Appointments = today; }
public void SaveAppts(Models.Appointment appt) { Appointment apptdb = new Appointment() { Body = appt.Body, EndTime = appt.EndTime, Location = appt.Location, StartTime = appt.StartTime, Subject = appt.Subject }; dbBCS.Appointments.Add(apptdb); try { dbBCS.SaveChanges(); } catch (Exception e) { } }