public List <FIL.Contracts.DataModels.ScheduleDetail> GetScheduleDetails(FIL.Contracts.Commands.CreateEventV1.EventRecurranceCommand eventRecurranceCommand)
        {
            List <FIL.Contracts.DataModels.ScheduleDetail> eventSchedules = new List <Contracts.DataModels.ScheduleDetail>();

            if (eventRecurranceCommand.ActionType == Contracts.Commands.CreateEventV1.ActionType.BulkDelete)
            {
                var alleventSchedules = _eventScheduleRepository.GetAllByEventId(eventRecurranceCommand.EventId);
                var eventDetails      = _eventDetailRepository.GetByEventId(eventRecurranceCommand.EventId);
                var eventAttributes   = _eventAttributeRepository.GetByEventDetailId(eventDetails.Id);
                var StartDate         = eventRecurranceCommand.StartDateTime; // new DateTime(eventRecurranceCommand.StartDateTime.Year, eventRecurranceCommand.StartDateTime.Month, eventRecurranceCommand.StartDateTime.Day).ToUniversalTime();
                var EndDate           = eventRecurranceCommand.EndDateTime;   // new DateTime(eventRecurranceCommand.EndDateTime.Year, eventRecurranceCommand.EndDateTime.Month, eventRecurranceCommand.EndDateTime.Day).ToUniversalTime();
                var scheduleDetails   = _scheduleDetailRepository.GetAllByEventScheduleIds(alleventSchedules.Select(s => s.Id).ToList()).Where(s => s.StartDateTime.Date >= StartDate.Date && s.EndDateTime.Date <= EndDate.Date).OrderBy(s => s.StartDateTime).ToList();

                foreach (var scheduleDetail in scheduleDetails)
                {
                    var startDate = _localTimeZoneConvertProvider.ConvertToLocal(scheduleDetail.StartDateTime, eventAttributes.TimeZone);
                    var endDate   = _localTimeZoneConvertProvider.ConvertToLocal(scheduleDetail.EndDateTime, eventAttributes.TimeZone);
                    if (startDate.ToString(@"HH:mm", new CultureInfo("en-US")) == eventRecurranceCommand.LocalStartTime && endDate.ToString(@"HH:mm", new CultureInfo("en-US")) == eventRecurranceCommand.LocalEndTime)
                    {
                        eventSchedules.Add(scheduleDetail);
                    }
                }
                return(eventSchedules);
                //  return scheduleDetails.Where(s => s.StartDateTime.ToString(@"HH:mm", new CultureInfo("en-US")) == eventRecurranceCommand.StartDateTime.ToString(@"HH:mm", new CultureInfo("en-US")) && s.EndDateTime.ToString(@"HH:mm", new CultureInfo("en-US")) == eventRecurranceCommand.EndDateTime.ToString(@"HH:mm", new CultureInfo("en-US"))).ToList();
            }
            else
            {
                var scheduleDetail = _scheduleDetailRepository.Get(eventRecurranceCommand.ScheduleDetailId);
                eventSchedules.Add(scheduleDetail);
                return(eventSchedules);
            }
        }
Esempio n. 2
0
        public List <FIL.Contracts.DataModels.ScheduleDetail> GetScheduleDetails(FIL.Contracts.Commands.CreateEventV1.EventRecurranceCommand eventRecurranceCommand)
        {
            var eventSchedule = SaveEventSchedule(eventRecurranceCommand);
            List <FIL.Contracts.DataModels.ScheduleDetail> eventSchedules = new List <Contracts.DataModels.ScheduleDetail>();
            var eventSchedules1 = _eventScheduleRepository.GetAllByEventId(eventRecurranceCommand.EventId);
            var scheduleDetails = _scheduleDetailRepository.GetAllByEventScheduleIds(eventSchedules1.Select(s => s.Id).ToList());

            if (eventRecurranceCommand.OccuranceType == Contracts.Enums.OccuranceType.Once)
            {
                var startDateTime = _commonUtilityProvider.GetUtcDate(eventRecurranceCommand.StartDateTime, eventRecurranceCommand.LocalStartTime, eventRecurranceCommand.TimeZoneOffSet);
                var endDateTime   = _commonUtilityProvider.GetUtcDate(eventRecurranceCommand.EndDateTime, eventRecurranceCommand.LocalEndTime, eventRecurranceCommand.TimeZoneOffSet);
                if (!scheduleDetails.Where(s => s.StartDateTime == startDateTime && s.EndDateTime == endDateTime).Any())
                {
                    // allow only one day insert
                    FIL.Contracts.DataModels.ScheduleDetail scheduleDetail = new Contracts.DataModels.ScheduleDetail
                    {
                        EventScheduleId = eventSchedule.Id,
                        StartDateTime   = startDateTime,
                        EndDateTime     = endDateTime,
                        CreatedBy       = eventRecurranceCommand.ModifiedBy,
                        IsEnabled       = true,
                        CreatedUtc      = DateTime.UtcNow,
                        ModifiedBy      = eventRecurranceCommand.ModifiedBy,
                        UpdatedBy       = eventRecurranceCommand.ModifiedBy,
                        UpdatedUtc      = DateTime.UtcNow
                    };
                    eventSchedules.Add(scheduleDetail);
                    return(eventSchedules);
                }
            }
            else if (eventRecurranceCommand.OccuranceType == Contracts.Enums.OccuranceType.Daily)
            {
                foreach (DateTime day in _commonUtilityProvider.EachDay(eventRecurranceCommand.StartDateTime, eventRecurranceCommand.EndDateTime))
                {
                    var startDateTime = _commonUtilityProvider.GetUtcDate(day, eventRecurranceCommand.LocalStartTime, eventRecurranceCommand.TimeZoneOffSet);
                    var endDateTime   = _commonUtilityProvider.GetUtcDate(day, eventRecurranceCommand.LocalEndTime, eventRecurranceCommand.TimeZoneOffSet);
                    if (scheduleDetails.Where(s => s.StartDateTime == startDateTime && s.EndDateTime == endDateTime).Any())
                    {
                        continue;
                    }
                    // allow all day insert
                    FIL.Contracts.DataModels.ScheduleDetail scheduleDetail = new Contracts.DataModels.ScheduleDetail
                    {
                        EventScheduleId = eventSchedule.Id,
                        StartDateTime   = startDateTime,
                        EndDateTime     = endDateTime,
                        CreatedBy       = eventRecurranceCommand.ModifiedBy,
                        IsEnabled       = true,
                        CreatedUtc      = DateTime.UtcNow,
                        ModifiedBy      = eventRecurranceCommand.ModifiedBy,
                        UpdatedBy       = eventRecurranceCommand.ModifiedBy,
                        UpdatedUtc      = DateTime.UtcNow
                    };
                    eventSchedules.Add(scheduleDetail);
                }
                return(eventSchedules);
            }
            else if (eventRecurranceCommand.OccuranceType == Contracts.Enums.OccuranceType.Weekly)
            {
                foreach (DateTime day in _commonUtilityProvider.EachDay(eventRecurranceCommand.StartDateTime, eventRecurranceCommand.EndDateTime))
                {
                    var startDateTime = _commonUtilityProvider.GetUtcDate(day, eventRecurranceCommand.LocalStartTime, eventRecurranceCommand.TimeZoneOffSet);
                    var endDateTime   = _commonUtilityProvider.GetUtcDate(day, eventRecurranceCommand.LocalEndTime, eventRecurranceCommand.TimeZoneOffSet);
                    if (scheduleDetails.Where(s => s.StartDateTime == startDateTime && s.EndDateTime == endDateTime).Any())
                    {
                        continue;
                    }
                    // If Day match with the dayIds
                    if (eventRecurranceCommand.DayIds.Contains(((int)day.DayOfWeek).ToString()))
                    {
                        FIL.Contracts.DataModels.ScheduleDetail scheduleDetail = new Contracts.DataModels.ScheduleDetail
                        {
                            EventScheduleId = eventSchedule.Id,
                            StartDateTime   = startDateTime,
                            EndDateTime     = endDateTime,
                            CreatedBy       = eventRecurranceCommand.ModifiedBy,
                            IsEnabled       = true,
                            CreatedUtc      = DateTime.UtcNow,
                            ModifiedBy      = eventRecurranceCommand.ModifiedBy,
                            UpdatedBy       = eventRecurranceCommand.ModifiedBy,
                            UpdatedUtc      = DateTime.UtcNow
                        };
                        eventSchedules.Add(scheduleDetail);
                    }
                }
                return(eventSchedules);
            }
            else if (eventRecurranceCommand.OccuranceType == Contracts.Enums.OccuranceType.Monthly)
            {
                foreach (DateTime day in _commonUtilityProvider.EachDay(eventRecurranceCommand.StartDateTime, eventRecurranceCommand.EndDateTime))
                {
                    var startDateTime = _commonUtilityProvider.GetUtcDate(day, eventRecurranceCommand.LocalStartTime, eventRecurranceCommand.TimeZoneOffSet);
                    var endDateTime   = _commonUtilityProvider.GetUtcDate(day, eventRecurranceCommand.LocalEndTime, eventRecurranceCommand.TimeZoneOffSet);
                    if (scheduleDetails.Where(s => s.StartDateTime == startDateTime && s.EndDateTime == endDateTime).Any())
                    {
                        continue;
                    }
                    // If Day match with the loop day
                    if (eventRecurranceCommand.StartDateTime.Day == day.Day)
                    {
                        FIL.Contracts.DataModels.ScheduleDetail scheduleDetail = new Contracts.DataModels.ScheduleDetail
                        {
                            EventScheduleId = eventSchedule.Id,
                            StartDateTime   = startDateTime,
                            EndDateTime     = endDateTime,
                            CreatedBy       = eventRecurranceCommand.ModifiedBy,
                            IsEnabled       = true,
                            CreatedUtc      = DateTime.UtcNow,
                            ModifiedBy      = eventRecurranceCommand.ModifiedBy,
                            UpdatedBy       = eventRecurranceCommand.ModifiedBy,
                            UpdatedUtc      = DateTime.UtcNow
                        };
                        eventSchedules.Add(scheduleDetail);
                    }
                }
                return(eventSchedules);
            }
            return(eventSchedules);
        }
Esempio n. 3
0
        public List <FIL.Contracts.Models.CreateEventV1.EventRecurranceScheduleModel> GetScheduleDetails(long EventId,
                                                                                                         DateTime StartDate,
                                                                                                         DateTime EndDate,
                                                                                                         bool IsGetDateRange = false,
                                                                                                         bool IsGetAll       = false
                                                                                                         )
        {
            List <FIL.Contracts.Models.CreateEventV1.EventRecurranceScheduleModel> eventRecurranceScheduleModels = new List <FIL.Contracts.Models.CreateEventV1.EventRecurranceScheduleModel>();
            var allScheduleDetails = new List <FIL.Contracts.DataModels.ScheduleDetail>();
            var eventSchedules     = _eventScheduleRepository.GetAllByEventId(EventId);
            var eventDetails       = _eventDetailRepository.GetByEventId(EventId);

            if (eventDetails == null && IsGetDateRange)
            {
                return(eventRecurranceScheduleModels);
            }
            var eventAttributes = _eventAttributeRepository.GetByEventDetailId(eventDetails.Id);

            if (IsGetDateRange)
            {
                allScheduleDetails = _scheduleDetailRepository.GetAllByEventScheduleIds(eventSchedules.Select(s => s.Id).ToList()).ToList();
                FIL.Contracts.Models.CreateEventV1.EventRecurranceScheduleModel eventRecurranceScheduleModel = new FIL.Contracts.Models.CreateEventV1.EventRecurranceScheduleModel();
                if (!allScheduleDetails.Any())
                {
                    return(eventRecurranceScheduleModels);
                }
                eventRecurranceScheduleModel.StartDateTime = allScheduleDetails.OrderBy(s => s.StartDateTime).FirstOrDefault().StartDateTime;
                eventRecurranceScheduleModel.EndDateTime   = allScheduleDetails.OrderBy(s => s.StartDateTime).LastOrDefault().EndDateTime;
                eventRecurranceScheduleModels.Add(eventRecurranceScheduleModel);
                return(eventRecurranceScheduleModels);
            }
            allScheduleDetails = _scheduleDetailRepository.GetAllByEventScheduleIds(eventSchedules.Select(s => s.Id).ToList()).OrderBy(s => s.StartDateTime).ToList();
            var scheduleDetails = allScheduleDetails.OrderBy(s => s.StartDateTime).ToList();

            if (!IsGetAll)
            {
                scheduleDetails = allScheduleDetails.Where(s => s.StartDateTime >= new DateTime(StartDate.Year, StartDate.Month, StartDate.Day, 00, 00, 00).ToUniversalTime() && s.EndDateTime <= new DateTime(EndDate.Year, EndDate.Month, EndDate.Day, 23, 59, 00).ToUniversalTime()).OrderBy(s => s.StartDateTime).ToList();
            }
            foreach (var scheduleDetail in scheduleDetails)
            {
                FIL.Contracts.Models.CreateEventV1.EventRecurranceScheduleModel eventRecurranceScheduleModel = new FIL.Contracts.Models.CreateEventV1.EventRecurranceScheduleModel();
                var currentEventSchedule = eventSchedules.Where(s => s.Id == scheduleDetail.EventScheduleId).FirstOrDefault();
                var startDate            = _localTimeZoneConvertProvider.ConvertToLocal(scheduleDetail.StartDateTime, eventAttributes.TimeZone);
                var endDate = _localTimeZoneConvertProvider.ConvertToLocal(scheduleDetail.EndDateTime, eventAttributes.TimeZone);
                eventRecurranceScheduleModel.EventScheduleId                       = currentEventSchedule.Id;
                eventRecurranceScheduleModel.DayIds                                = currentEventSchedule.DayId;
                eventRecurranceScheduleModel.ScheduleDetailId                      = scheduleDetail.Id;
                eventRecurranceScheduleModel.IsEnabled                             = scheduleDetail.IsEnabled;
                eventRecurranceScheduleModel.StartDateTime                         = scheduleDetail.StartDateTime;
                eventRecurranceScheduleModel.EndDateTime                           = scheduleDetail.EndDateTime;
                eventRecurranceScheduleModel.LocalStartDateTime                    = startDate;
                eventRecurranceScheduleModel.LocalEndDateTime                      = endDate;
                eventRecurranceScheduleModel.EventScheduleStartDateTime            = allScheduleDetails.FirstOrDefault().StartDateTime;
                eventRecurranceScheduleModel.EventScheduleEndDateTime              = allScheduleDetails.LastOrDefault().EndDateTime;
                eventRecurranceScheduleModel.LocalStartTime                        = startDate.ToString(@"HH:mm", new CultureInfo("en-US"));
                eventRecurranceScheduleModel.LocalEndTime                          = endDate.ToString(@"HH:mm", new CultureInfo("en-US"));
                eventRecurranceScheduleModel.LocalStartDateString                  = startDate.DayOfWeek + ", " + startDate.ToString(@"MMM dd, yyyy", new CultureInfo("en-US"));
                eventRecurranceScheduleModel.LocalEndDateString                    = endDate.DayOfWeek + ", " + endDate.ToString(@"MMM dd, yyyy", new CultureInfo("en-US"));
                eventRecurranceScheduleModel.LocalEventScheduleStartDateTimeString = allScheduleDetails.FirstOrDefault().StartDateTime.DayOfWeek + ", " + allScheduleDetails.FirstOrDefault().StartDateTime.ToString(@"MMM dd, yyyy", new CultureInfo("en-US"));
                eventRecurranceScheduleModel.LocalEventScheduleEndDateTimeString   = allScheduleDetails.LastOrDefault().EndDateTime.DayOfWeek + ", " + allScheduleDetails.LastOrDefault().EndDateTime.ToString(@"MMM dd, yyyy", new CultureInfo("en-US"));
                eventRecurranceScheduleModels.Add(eventRecurranceScheduleModel);
            }
            return(eventRecurranceScheduleModels);
        }