Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// verify if meetup overlaps with any other meetings saved in the final list
 /// </summary>
 /// <param name="objMeetup"></param>
 /// <param name="sortList"></param>
 /// <returns> bool </returns>
 public bool ValidateOverlappingMeetup(Meetup objMeetup, SortedList <DateTime, Meetup> sortList)
 {
     try
     {
         return(sortList.Count > 0 && sortList.Values.Any(a => a.MeetupStart >= objMeetup.MeetupStart && a.MeetupEnd <= objMeetup.MeetupEnd));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(false);
     }
 }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Mapping of data to Meetup object with bookingDate as out param
        /// </summary>
        /// <param name="meet"></param>
        /// <param name="bookingDate"></param>
        /// <returns>Meetup object</returns>
        public Meetup GetAppliedMeetups(string meet, out DateTime bookingDate)
        {
            Meetup objMeetup = new Meetup();

            bookingDate = new DateTime();
            try
            {
                List <string> tempString = meet.Split(" ").ToList();
                bookingDate           = DateTime.Parse($"{tempString[0]} {tempString[1]}");
                objMeetup.EntityName  = tempString[2];
                objMeetup.MeetupStart = DateTime.Parse($"{tempString[3]} {tempString[4]}");
                objMeetup.MeetupEnd   = objMeetup.MeetupStart.AddHours(Convert.ToInt32(tempString[5]));
                return(objMeetup);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new Meetup());
            }
        }