-
-
Save gregorybmclub/0cb262745d4738b1f144 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Event> EventList() | |
{ | |
List<Event> events = new List<Event>(); | |
using (SchoolAdminDBEntities db = new SchoolAdminDBEntities()) | |
{ | |
BrushConverter converter = new BrushConverter(); | |
string loggedInUserName = Thread.CurrentPrincipal.Identity.Name; | |
var appointments = db.Appointments.Where(a => a.User.Username.Equals(loggedInUserName)).ToList(); | |
foreach (var appointement in appointments) | |
{ | |
Event e = new Event | |
{ | |
Id = appointement.AppointmentID, | |
UserID = appointement.UserID, | |
Subject = appointement.Subject, | |
Location = appointement.Location, | |
Description = appointement.Notes, | |
Start = appointement.StartDate, | |
End = appointement.EndDate | |
}; | |
if (!string.IsNullOrEmpty(appointement.Colour)) | |
{ | |
e.Color = converter.ConvertFromString(appointement.Colour) as Brush; | |
} | |
events.Add(e); | |
} | |
} | |
return events; | |
} | |
public void AddAppointment(Event a) | |
{ | |
var app = new DataObjects.Appointment(); | |
BrushConverter converter = new BrushConverter(); | |
using (var context = new SchoolAdminDBEntities()) | |
{ | |
app.AppointmentID = a.Id; | |
app.UserID = a.UserID; | |
app.StartDate = (DateTime)a.Start; | |
app.EndDate = (DateTime)a.End; | |
app.Location = a.Location; | |
app.Subject = a.Subject; | |
app.Notes = a.Description; | |
//app.Colour = a.Color.ToString(); | |
app.Colour = converter.ConvertToString(a.Color); | |
context.AddToAppointments(app); | |
context.SaveChanges(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<StackPanel> | |
<Label Content="Select Event Color:" /> | |
<xceed:ColorPicker SelectedColor="{Binding CurrentEvent.Color, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="200" | |
AvailableColorsHeader="Knowned appointments" | |
DisplayColorAndName="True" | |
ShowAvailableColors="True" | |
ShowStandardColors="True" | |
ShowAdvancedButton="False" | |
UsingAlphaChannel="False"/> | |
</StackPanel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppointmentViewModel : FormViewModelBase | |
{ | |
AppointmentRepository rep = new AppointmentRepository(); | |
#region constructor | |
public AppointmentViewModel() | |
: base("") | |
{ | |
} | |
#endregion | |
public TimeSpan StartJourney | |
{ | |
get { return DummyDatabase.GetAppSettingStartJourney(); } | |
} | |
public TimeSpan EndJourney | |
{ | |
get { return DummyDatabase.GetAppSettingEndJourney(); } | |
} | |
private ObservableCollection<Event> _events; | |
public ObservableCollection<Event> WpfScheduleEvents | |
{ | |
get | |
{ | |
if (_events == null) | |
_events = new ObservableCollection<Event>(rep.EventList()); | |
return _events; | |
} | |
set | |
{ | |
if (_events != value) | |
{ | |
_events = value; | |
OnPropertyChanged("WpfScheduleEvents"); | |
} | |
} | |
} | |
#region CurrentEvent | |
private Event _currentEvent; | |
public Event CurrentEvent | |
{ | |
get { return _currentEvent; } | |
set | |
{ | |
if (_currentEvent == value) return; | |
_currentEvent = value; | |
OnPropertyChanged("CurrentEvent"); | |
} | |
} | |
#endregion | |
#region IsOpen | |
private bool _isOpen; | |
public bool IsOpen | |
{ | |
get { return _isOpen; } | |
set | |
{ | |
if (_isOpen == value) return; | |
_isOpen = value; | |
OnPropertyChanged("IsOpen"); | |
} | |
} | |
#endregion | |
#region Commands | |
#region EditEventCommand | |
RelayCommand _EditEventCommand; | |
public ICommand EditEventCommand | |
{ | |
get | |
{ | |
if (_EditEventCommand == null) _EditEventCommand = new RelayCommand(EditEvent); | |
return _EditEventCommand; | |
} | |
} | |
private void EditEvent(object param) | |
{ | |
WpfScheduler.Event e = param as WpfScheduler.Event; | |
CurrentEvent = WpfScheduleEvents.SingleOrDefault(ev => ev.Id == e.Id); | |
IsOpen = true; | |
} | |
#endregion | |
#region NewEventCommand | |
RelayCommand _NewEventCommand; | |
public ICommand NewEventCommand | |
{ | |
get | |
{ | |
if (_NewEventCommand == null) | |
_NewEventCommand = new RelayCommand(this.NewEvent); | |
return _NewEventCommand; | |
} | |
} | |
private void NewEvent(object param) | |
{ | |
//DateTime? date = (DateTime?)param; | |
DateTime? d = new DateTime(); | |
CurrentEvent = new Event(); | |
CurrentEvent.Color = new SolidColorBrush(); | |
CurrentEvent.Start = (DateTime)d; | |
CurrentEvent.Subject = "New event"; | |
CurrentEvent.End = (DateTime)d; | |
CurrentEvent.Location = ""; | |
IsOpen = true; | |
} | |
#endregion | |
#region CancelEditCommand | |
RelayCommand _CancelEditCommand; | |
public ICommand CancelEditCommand | |
{ | |
get | |
{ | |
if (_CancelEditCommand == null) _CancelEditCommand = new RelayCommand(param => this.CancelEdit()); | |
return _CancelEditCommand; | |
} | |
} | |
private void CancelEdit() | |
{ | |
if (!WpfScheduleEvents.Contains(CurrentEvent)) | |
CurrentEvent = null; | |
IsOpen = false; | |
} | |
#endregion | |
#region SaveEventCommand | |
RelayCommand _SaveEventCommand; | |
public ICommand SaveEventCommand | |
{ | |
get | |
{ | |
if (_SaveEventCommand == null) _SaveEventCommand = new RelayCommand(param => this.SaveEvent()); | |
return _SaveEventCommand; | |
} | |
} | |
private void SaveEvent() | |
{ | |
if (!WpfScheduleEvents.Contains(CurrentEvent)) | |
{ | |
WpfScheduleEvents.Add(CurrentEvent); | |
rep.AddAppointment(CurrentEvent); | |
} | |
IsOpen = false; | |
MessageBox.Show("Event has been added."); | |
OnPropertyChanged("WpfScheduleEvents"); | |
} | |
#endregion | |
#region UpdateEventCommand | |
RelayCommand _UpdateEventCommand; | |
public ICommand UpdateEventCommand | |
{ | |
get | |
{ | |
if (_UpdateEventCommand == null) _UpdateEventCommand = new RelayCommand(param => this.UpdateEvent()); | |
return _UpdateEventCommand; | |
} | |
} | |
private void UpdateEvent() | |
{ | |
if (WpfScheduleEvents.Contains(CurrentEvent)) | |
{ | |
//CurrentEvent = WpfScheduleEvents.SingleOrDefault(ev => ev.Id == CurrentEvent.Id); | |
rep.UpdateAppointment(CurrentEvent); | |
} | |
IsOpen = false; | |
MessageBox.Show("Event has been updated."); | |
OnPropertyChanged("WpfScheduleEvents"); | |
} | |
#endregion | |
#region DeleteEventCommand | |
RelayCommand _DeleteEventCommand; | |
public ICommand DeleteEventCommand | |
{ | |
get | |
{ | |
if (_DeleteEventCommand == null) _DeleteEventCommand = new RelayCommand(param => this.DeleteEvent()); | |
return _DeleteEventCommand; | |
} | |
} | |
private void DeleteEvent() | |
{ | |
if (WpfScheduleEvents.Contains(CurrentEvent)) | |
{ | |
CurrentEvent = WpfScheduleEvents.SingleOrDefault(ev => ev.Id == CurrentEvent.Id); | |
rep.DeleteAppointment(CurrentEvent); | |
} | |
IsOpen = false; | |
MessageBox.Show("Event has been deleted."); | |
OnPropertyChanged("WpfScheduleEvents"); | |
} | |
#endregion | |
#endregion | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Event | |
{ | |
public Event(); | |
public bool AllDay { get; set; } | |
public Brush Color { get; set; } | |
public string Description { get; set; } | |
public DateTime End { get; set; } | |
public int Id { get; set; } | |
public string Location { get; set; } | |
public DateTime Start { get; set; } | |
public string Subject { get; set; } | |
public int UserID { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment