private static void AddEventToCalendar(
            ObservableCollection <CalendarDayModel> calendarGroup,
            EventItemModel newEvent,
            DateTime firstDayOfMonth,
            DateTime lastDayOfMonth,
            int offset)
        {
            int start;

            if (newEvent.EventBegin < firstDayOfMonth)
            {
                start = 1;
            }
            else
            {
                start = newEvent.EventBegin.Day;
            }

            int end;

            if (newEvent.EventEnd > lastDayOfMonth)
            {
                end = lastDayOfMonth.Day;
            }
            else
            {
                end = newEvent.EventEnd.Day;
            }

            if (start == end)
            {
                calendarGroup[start + offset].
                DayEvents.
                Add(new DayEvent(newEvent, EventDurationType.None));
            }
            else
            {
                for (var day = start; day <= end; day++)
                {
                    DayEvent dayEvent;
                    if (day == start)
                    {
                        dayEvent = new DayEvent(newEvent, EventDurationType.BeginMultiday);
                    }
                    else if (day == end)
                    {
                        dayEvent = new DayEvent(newEvent, EventDurationType.EndMultiday);
                    }
                    else
                    {
                        dayEvent = new DayEvent(newEvent, EventDurationType.MiddleMultiday);
                    }

                    calendarGroup[day + offset].DayEvents.Add(dayEvent);
                }
            }
        }
        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);
            }
        }
예제 #4
0
        private EventItemModel ConvertEvent(NewEventItemModel newEvent)
        {
            var convertedEvent = new EventItemModel(AppViewModel, newEvent.EventBegin, newEvent.NavFromCalendar)
            {
                EventTitle        = newEvent.EventTitle,
                Venue             = newEvent.Venue,
                Description       = newEvent.Description,
                EventBegin        = newEvent.EventBegin,
                EventEnd          = newEvent.EventEnd,
                ImagePath         = newEvent.ImagePath,
                VenueContactEmail = newEvent.VenueContactEmail,
                VenueContactPhone = newEvent.VenueContactPhone,
                ID = newEvent.ID
            };

            convertedEvent.GuestListModel = newEvent.GuestListModel;

            return(convertedEvent);
        }
        /// <summary>
        /// Add or update contact
        /// </summary>
        public static int UpdateExistingEvent(EventItemModel eventToUpdate)
        {
            if (eventToUpdate == null)
            {
                throw new ArgumentNullException();
            }
            if (eventToUpdate.ID < 0)
            {
                throw new ArgumentException($"Use {nameof(RetriveNewEvent)} to get new event");
            }

            using (var db = new EventManagerDBContext())
            {
                // Get new ID
                var query = from event1 in db.Events
                            where event1.MeetingID == eventToUpdate.ID
                            select event1;
                var returnedEvent = query.FirstOrDefault();

                if (returnedEvent == null)
                {
                    throw new IndexOutOfRangeException($"Event index {eventToUpdate.ID} not found");
                }

                returnedEvent.EventTitle        = eventToUpdate.EventTitle;
                returnedEvent.Venue             = eventToUpdate.Venue;
                returnedEvent.Description       = eventToUpdate.Description;
                returnedEvent.EventStart        = eventToUpdate.EventBegin;
                returnedEvent.EventEnd          = eventToUpdate.EventEnd;
                returnedEvent.ImagePath         = eventToUpdate.ImagePath;
                returnedEvent.VenueContactEmail = eventToUpdate.VenueContactEmail;
                returnedEvent.VenueContactPhone = eventToUpdate.VenueContactPhone;

                db.Events.Update(returnedEvent);
                db.SaveChanges();

                return(returnedEvent.MeetingID);
            }
        }
        /// <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);
            }
        }