/// <summary>
        /// Creates a new event and saves a copy
        /// </summary>
        private NewEventItemModel(AppLevelModel appViewModel, DateTime eventStartDate, bool navFromCalendar) :
            base(appViewModel, eventStartDate, navFromCalendar)
        {
            EditEvent  = true;
            IsNewEvent = true;

            // Override base icons
            IconCode  = "Add";
            PageTitle = Q.Resources.NewEvent_PageTitle;

            SubMenu.Clear();
            SubMenu.Add(new MenuItem <AppLevelModel>(Q.Resources.Event_EditAttendance, "Contact2", EditAttendanceCommand));
            SubMenu.Add(new MenuItem <AppLevelModel>(Q.Resources.Event_SaveEvent, "Save", SaveEventCommand));
            SubMenu.Add(new MenuItem <AppLevelModel>(Q.Resources.Event_DiscardChanges, "Cancel", CancelEventChangesCommand));

            SqLiteManager.RetriveNewEvent(this);

            // Create backup
            meetingBackup = new Meeting
            {
                EventTitle        = EventTitle,
                Venue             = Venue,
                Description       = Description,
                EventStart        = EventBegin,
                EventEnd          = EventBegin,
                ImagePath         = ImagePath,
                VenueContactEmail = VenueContactEmail,
                VenueContactPhone = VenueContactPhone,
                MeetingID         = ID
            };
        }
        public ContactItemModel(AppLevelModel appViewModel) : base(appViewModel)
        {
            // Used for Navigation
            IconCode  = "AddFriend";
            PageTitle = Q.Resources.ContactItem_PageTitle;

            MainMenu      = AppViewModel.GuestMenuForAllContacts;
            MainMenuIndex = 0;

            SubMenu.Add(new MenuItem <AppLevelModel>(Q.Resources.Contact_Edit, "Edit", EditCommand));
            SubMenuIndex = -1;
            ResetSubMenuIndexOnNavigation = true;
        }
        public static BaseEventItemModel GetLatestEvent(AppLevelModel appViewModel)
        {
            using (var db = new EventManagerDBContext())
            {
                var query = from event1 in db.Events
                            orderby event1.EventStart descending
                            where event1.EventStart > DateTime.Now
                            select event1;

                var result = query.FirstOrDefault();
                if (result == null)
                {
                    // No events found
                    return(null);
                }
                else
                {
                    // Upcoming future event
                    var latestEvent = new EventItemModel(appViewModel, result.EventStart, false)
                    {
                        EventTitle        = result.EventTitle,
                        Venue             = result.Venue,
                        Description       = result.Description,
                        EventBegin        = result.EventStart,
                        EventEnd          = result.EventEnd,
                        VenueContactEmail = result.VenueContactEmail,
                        VenueContactPhone = result.VenueContactPhone,
                        ImagePath         = result.ImagePath,
                        ID = result.MeetingID
                    };

                    // Guests
                    var guestQuery = from eventGuest in db.EventGuests
                                     where eventGuest.MeetingID == result.MeetingID
                                     select eventGuest;

                    foreach (var guest in guestQuery)
                    {
                        latestEvent.GuestListModel.GuestList.Items.Add(new EventGuest
                        {
                            Guest       = appViewModel.AllContacts.Contacts.GetItem(guest.ContactID),
                            ID          = guest.MeetingGuestID,
                            GuestStatus = guest.GuestStatus,
                        });
                    }

                    return(latestEvent);
                }
            }
        }
        internal static CalendarDayModel GetCalendarDay(DateTime currentDate, AppLevelModel appViewModel)
        {
            var day = new CalendarDayModel(currentDate.Day, true, currentDate.DayOfWeek.ToString());

            using (var db = new EventManagerDBContext())
            {
                var startDate = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day);
                var endDate   = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day).AddDays(1);

                var query = from theEvent in db.Events
                            where !(theEvent.EventEnd <= startDate || theEvent.EventStart >= endDate)
                            select theEvent;

                foreach (Meeting item in query)
                {
                    var newEvent = new EventItemModel(appViewModel, item.EventStart, true)
                    {
                        EventTitle        = item.EventTitle,
                        Venue             = item.Venue,
                        Description       = item.Description,
                        EventBegin        = item.EventStart,
                        EventEnd          = item.EventEnd,
                        VenueContactEmail = item.VenueContactEmail,
                        VenueContactPhone = item.VenueContactPhone,
                        ImagePath         = item.ImagePath,
                        ID = item.MeetingID
                    };

                    day.DayEvents.Add(new DayEvent(newEvent, EventDurationType.SingleDay));

                    // Guests
                    var guestQuery = from eventGuest in db.EventGuests
                                     where eventGuest.MeetingID == newEvent.ID
                                     select eventGuest;

                    foreach (var guest in guestQuery)
                    {
                        newEvent.GuestListModel.GuestList.Items.Add(new EventGuest
                        {
                            Guest       = appViewModel.AllContacts.Contacts.GetItem(guest.ContactID),
                            ID          = guest.MeetingGuestID,
                            ContactID   = guest.ContactID,
                            GuestStatus = guest.GuestStatus,
                        });
                    }
                }

                return(day);
            }
        }
示例#5
0
        public NewContactItemModel(AppLevelModel appViewModel) : base(appViewModel)
        {
            // Used for Navigation
            IconCode  = "AddFriend";
            PageTitle = Q.Resources.ContactNew_PageTitle;

            MainMenu = new ObservableCollection <MenuItem <AppLevelModel> >()
            {
                new MenuItem <AppLevelModel>(Q.Resources.Contact_ReturnToMyContacts, "ImportAll")
            };
            MainMenuIndex = 0;

            SubMenu.Add(new MenuItem <AppLevelModel>(Q.Resources.Contact_Edit, "Edit", EditCommand));
            BottomMenuIndex = -1;
            ResetSubMenuIndexOnNavigation = true;
        }
        public static void GetAllContacts(AppLevelModel appViewModel, ContactCollectionModel allContacts)
        {
            using (var db = new EventManagerDBContext())
            {
                var dict = new Dictionary <string, ContactCategoryModel>();
                foreach (var contact in db.Contacts)
                {
                    // Get contact category name
                    var catName = appViewModel.Settings.UserNameInStandardFormat.Value
                        ? contact.LastName[0].ToString().ToUpper() : contact.FirstName[0].ToString().ToUpper();

                    // Get category, or create one if it doesn't exist.
                    ContactCategoryModel category;
                    if (dict.ContainsKey(catName))
                    {
                        category = dict[catName];
                    }
                    else
                    {
                        category = new ContactCategoryModel {
                            Title = catName.ToUpper()
                        };
                        dict.Add(catName, category);
                        allContacts.Categories.Add(category);
                    }

                    // Add to list of contacts
                    allContacts.Add(new ContactItemModel(appViewModel)
                    {
                        ID            = contact.ContactID,
                        EmailAddress  = contact.EmailAddress,
                        EmailAddress2 = contact.EmailAddress2,
                        FirstName     = contact.FirstName,
                        LastName      = contact.LastName,
                        PhoneNumber   = contact.PhoneNumber,
                        PhoneNumber2  = contact.PhoneNumber2,
                        Category      = category,
                        ImagePath     = contact.ImagePath
                    });
                }
            }
        }
        /// <summary>
        /// Get events within same month. Ordered by day only.
        /// </summary>
        public static ObservableCollection <CalendarDayModel> GetCalendarMonth(
            int year, int month, AppLevelModel appViewModel)
        {
            var CalendarGroup = new ObservableCollection <CalendarDayModel>();

            // Get first day of week
            var firstDayOfMonth = new DateTime(year, month, 1);
            var lastDayOfMonth  = firstDayOfMonth.AddMonths(1).AddDays(-1);
            var firstDayIndex   = (int)firstDayOfMonth.DayOfWeek + 1;

            firstDayIndex = firstDayIndex == 7 ? 0 : firstDayIndex;
            firstDayIndex--;

            for (int i = 0; i < firstDayIndex; i++)
            {
                CalendarGroup.Add(new CalendarDayModel(0, false, string.Empty));
            }

            var lastDayIndex = firstDayOfMonth.AddMonths(1).AddDays(-1).Day + firstDayIndex;

            for (int i = firstDayIndex; i < lastDayIndex; i++)
            {
                var day     = new DateTime(year, month, i - firstDayIndex + 1);
                var dayName = day.DayOfWeek.ToString();

                CalendarGroup.Add(new CalendarDayModel(i - firstDayIndex + 1, true, dayName));
            }

            for (int i = lastDayIndex; i < 42; i++)
            {
                CalendarGroup.Add(new CalendarDayModel(0, false, string.Empty));
            }

            firstDayIndex--;
            using (var db = new EventManagerDBContext())
            {
                var startDate = new DateTime(year, month, 1);
                var endDate   = startDate.AddMonths(1);
                var query     = from theEvent in db.Events
                                where !(theEvent.EventEnd <= startDate || theEvent.EventStart >= endDate)
                                select theEvent;

                foreach (Meeting item in query)
                {
                    if (item.MeetingID != appViewModel.NewEventId)
                    {
                        var newEvent = new EventItemModel(appViewModel, item.EventStart, true)
                        {
                            EventTitle        = item.EventTitle,
                            Venue             = item.Venue,
                            Description       = item.Description,
                            EventBegin        = item.EventStart,
                            EventEnd          = item.EventEnd,
                            VenueContactEmail = item.VenueContactEmail,
                            VenueContactPhone = item.VenueContactPhone,
                            ImagePath         = item.ImagePath,
                            ID = item.MeetingID
                        };

                        AddEventToCalendar(CalendarGroup, newEvent, firstDayOfMonth, lastDayOfMonth, firstDayIndex);

                        // Guests
                        var guestQuery = from eventGuest in db.EventGuests
                                         where eventGuest.MeetingID == newEvent.ID
                                         select eventGuest;

                        foreach (var guest in guestQuery)
                        {
                            newEvent.GuestListModel.GuestList.Items.Add(new EventGuest
                            {
                                Guest       = appViewModel.AllContacts.Contacts.GetItem(guest.ContactID),
                                ID          = guest.MeetingGuestID,
                                ContactID   = guest.ContactID,
                                GuestStatus = guest.GuestStatus,
                            });
                        }
                    }
                }

                return(CalendarGroup);
            }
        }
示例#8
0
 public EventItemModel(AppLevelModel appViewModel, DateTime newEventDate, bool NavFromCalendar) :
     base(appViewModel, newEventDate, NavFromCalendar)
 {
     ViewEventCommand.Execute();
 }