Beispiel #1
0
 public bool CreateEvent(DateTime start, DateTime end, string address, string comment, bool hearseNeded)
 {
     if (hearseNeded)
     {
         bool free = true;
         foreach (Hearse i in HearseRepo.GetCopyHearses())
         {
             foreach (Events E in Eventslist)
             {
                 if (E.Hearse == i && ((E.Start > end) || E.End < start))
                 {
                     free = false;
                 }
             }
             if (free)
             {
                 Events Event = new Events(findHighestKey() + 1, start, end, address, comment, status.NewlyMade, i);
                 AddEvent(Event);
                 return(true);
             }
             else
             {
                 free = true;
             }
         }
     }
     else
     {
         Events Event = new Events(findHighestKey() + 1, start, end, address, comment, status.NewlyMade, null);
         AddEvent(Event);
         return(true);
     }
     return(false);
 }
        // The CreateEvent method takes a number of parameters which we will use to make an event in our calendar.
        public bool CreateEvent(DateTime start, DateTime end, string address, string comment, bool hearseNeeded)
        {
            // Here we run an if-else loop on whether or not a hearse is needed for the event.
            if (hearseNeeded)
            {
                // If a hearse is needed for the event, then it will tell the boolean, available, to return true.
                bool Available = true;

                // It will then run through the Event list to see if a hearse is available by checking if the start is later than the end or the end is before the start.
                foreach (Hearse i in HearseRepo.GetCopyHearses())
                {
                    foreach (CalendarEntry _Event in Eventslist)
                    {
                        if (!(_Event.Status == status.Deleted) && _Event.Hearse == i && !(_Event.End < start || _Event.Start > end))
                        {
                            Available = false;
                        }
                    }

                    // If it is neither of those, it means the hearse is available and the AddEvent method is called to add the newly made event to the list.
                    if (Available)
                    {
                        CalendarEntry Event = new CalendarEntry(FindHighestKey() + 1, start, end, address, comment, status.NewlyMade, i);
                        AddEvent(Event);
                        return(true);
                    }
                    else
                    {
                        Available = true;
                    }
                }
                return(false);
            }

            // If a hearse is not needed. It will simply call the method AddEvent to add the event to the list.
            else
            {
                CalendarEntry _Event = new CalendarEntry(FindHighestKey() + 1, start, end, address, comment, status.NewlyMade, null);
                AddEvent(_Event);
                return(true);
            }
        }