示例#1
0
 /// <summary>
 /// verify if meetup object lies in the offic hours
 /// </summary>
 /// <param name="objMeetup"></param>
 /// <param name="officeHours"></param>
 /// <returns> boolean </returns>
 public bool ValidateOfficeTimeLimits(Meetup objMeetup, OfficeHours officeHours)
 {
     try
     {
         return(objMeetup.MeetupStart.TimeOfDay >= officeHours.StartTime && objMeetup.MeetupEnd.TimeOfDay <= officeHours.EndTime);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(false);
     }
 }
示例#2
0
        /// <summary>
        /// Get final meetings after various checks
        /// </summary>
        /// <param name="inputMeetup"></param>
        /// <returns> IEnumerable </returns>
        public IEnumerable <Meetup> GetValidMeetups(IEnumerable <string> inputMeetup)
        {
            SortedList <DateTime, Meetup> sortList = new SortedList <DateTime, Meetup>();
            Meetup      objMeetup = null;
            DateTime    bookingDate;
            OfficeHours officeHours = GetOfficeHours(inputMeetup.ElementAt(0));

            foreach (var meet in TransformInputMeetups(inputMeetup))
            {
                objMeetup = GetAppliedMeetups(meet, out bookingDate);
                if (objMeetup == new Meetup())
                {
                    return(Enumerable.Empty <Meetup>());
                }

                if (ValidateOfficeTimeLimits(objMeetup, officeHours))
                {
                    if (ValidateOverlappingMeetup(objMeetup, sortList))
                    {
                        IEnumerable <Meetup> tmpObj = sortList.Values.Where(w => w.MeetupStart >= objMeetup.MeetupStart && w.MeetupEnd <= objMeetup.MeetupEnd);
                        int             counter     = tmpObj.Count();
                        List <DateTime> lstKeys     = new List <DateTime>();
                        while (counter > 0)
                        {
                            int index = sortList.IndexOfValue(tmpObj.ElementAt(counter - 1));
                            if (bookingDate < sortList.Keys.ElementAt(index))
                            {
                                lstKeys.Add(sortList.Keys.ElementAt(index));
                            }
                            counter--;
                        }
                        if (lstKeys.Count() == tmpObj.Count())
                        {
                            for (int i = 0; i < lstKeys.Count(); i++)
                            {
                                sortList.Remove(lstKeys[i]);
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    sortList.Add(bookingDate, objMeetup);
                }
            }
            return(sortList.Values.OrderBy(o => o.MeetupStart));
        }
示例#3
0
        /// <summary>
        /// Fetching office hours from first line of input string
        /// </summary>
        /// <param name="_meetupInput"></param>
        /// <returns> Officehours object </returns>
        public OfficeHours GetOfficeHours(string _meetupInput)
        {
            OfficeHours officeHours = new OfficeHours();

            try
            {
                officeHours.StartTime = TimeSpan.Parse(DateTime.ParseExact(_meetupInput.Split(" ")[0], "HHmm", CultureInfo.InvariantCulture).ToString("HH:mm"));
                officeHours.EndTime   = TimeSpan.Parse(DateTime.ParseExact(_meetupInput.Split(" ")[1], "HHmm", CultureInfo.InvariantCulture).ToString("HH:mm"));
                return(officeHours);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new OfficeHours());
            }
        }