Ejemplo n.º 1
0
        public AddEventViewModel(User user, MonthControlViewModel MonthVM = null)
        {
            RepeatList = new List <RepeatMode>();
            RepeatList.Add(RepeatMode.DoNotRepeat);
            RepeatList.Add(RepeatMode.RepeatDaily);
            RepeatList.Add(RepeatMode.RepeatMonthly);
            RepeatList.Add(RepeatMode.RepeatTwiceAWeek);
            RepeatList.Add(RepeatMode.RepeatWeekly);

            NotificationList = new List <NotificationMode>();
            NotificationList.Add(NotificationMode.DoNotNotify);
            NotificationList.Add(NotificationMode.NotifyDayBefore);
            NotificationList.Add(NotificationMode.NotifyHourBefore);
            NotificationList.Add(NotificationMode.NotifyThreeDaysBefore);
            NotificationList.Add(NotificationMode.NotifyThreeHoursBefore);

            AddCommand = new RelayCommand(o =>
            {
                try
                {
                    var uow      = UnitOfWorkSingleton.Instance;
                    var newevent = new Model.PrimaryModels.Event(Name,
                                                                 ChangeTime((DateTime)Start,
                                                                            (DateTime)StartTime),
                                                                 ChangeTime((DateTime)End,
                                                                            (DateTime)EndTime),
                                                                 Note,
                                                                 Status.InProcess,
                                                                 user,
                                                                 Contact,
                                                                 Repeat,
                                                                 Notification);
                    newevent.ContactId = Contact?.Id;
                    newevent.Contact   = null;
                    uow.Events.Create(newevent);
                    uow.SaveChanges();
                    MonthVM.LoadTasksAndEvents();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + ex);
                }
            });
            AddContactCommand = new RelayCommand(o =>
            {
                try
                {
                    ContactListWindow taskWin = new ContactListWindow()
                    {
                        DataContext = new ContactListViewModel(user, this, null)
                    };
                    taskWin.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
        }
Ejemplo n.º 2
0
        public ChangeEventViewModel(Diary.MVVM.Model.PrimaryModels.Event _SelectedEvent, MonthControlViewModel MonthVM, User user)
        {
            RepeatList = new List <RepeatMode>();
            RepeatList.Add(RepeatMode.DoNotRepeat);
            RepeatList.Add(RepeatMode.RepeatDaily);
            RepeatList.Add(RepeatMode.RepeatMonthly);
            RepeatList.Add(RepeatMode.RepeatTwiceAWeek);
            RepeatList.Add(RepeatMode.RepeatWeekly);

            NotificationList = new List <NotificationMode>();
            NotificationList.Add(NotificationMode.DoNotNotify);
            NotificationList.Add(NotificationMode.NotifyDayBefore);
            NotificationList.Add(NotificationMode.NotifyHourBefore);
            NotificationList.Add(NotificationMode.NotifyThreeDaysBefore);
            NotificationList.Add(NotificationMode.NotifyThreeHoursBefore);

            var uow = UnitOfWorkSingleton.Instance;

            Note         = _SelectedEvent.Notes;
            Name         = _SelectedEvent.Name;
            Start        = _SelectedEvent.StartTime;
            StartTime    = _SelectedEvent.StartTime;
            End          = _SelectedEvent.EndTime;
            EndTime      = _SelectedEvent.EndTime;
            Status       = _SelectedEvent.Status;
            Repeat       = _SelectedEvent.RepeatMode;
            Notification = _SelectedEvent.NotificationMode;
            Contact      = uow.Contacts.GetElement(_SelectedEvent.ContactId);

            _event = uow.Events.GetElement(_SelectedEvent.Id);

            SaveCommand = new RelayCommand(o =>
            {
                try
                {
                    _event.Name             = Name;
                    _event.Notes            = Note;
                    _event.EndTime          = ChangeTime((DateTime)End, (DateTime)EndTime);
                    _event.StartTime        = ChangeTime((DateTime)Start, (DateTime)StartTime);
                    _event.Status           = Status;
                    _event.RepeatMode       = Repeat;
                    _event.NotificationMode = Notification;
                    _event.ContactId        = Contact?.Id;
                    uow.SaveChanges();
                    MonthVM.LoadTasksAndEvents();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
            DelCommand = new RelayCommand(o =>
            {
                try
                {
                    //var uow = UnitOfWorkSingleton.Instance;
                    uow.Events.Delete(_event.Id);
                    uow.SaveChanges();
                    MonthVM.LoadTasksAndEvents();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
            AddContactCommand = new RelayCommand(o =>
            {
                try
                {
                    ContactListWindow taskWin = new ContactListWindow()
                    {
                        DataContext = new ContactListViewModel(user, null, this)
                    };
                    taskWin.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
        }
Ejemplo n.º 3
0
        private void rbnContactList_Click(object sender, RoutedEventArgs e)
        {
            ContactListWindow contactListWindow = new ContactListWindow();;

            contactListWindow.ShowDialog();
        }