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); } }
protected void SaveEventSchedule(FIL.Contracts.Commands.CreateEventV1.EventRecurranceCommand eventRecurranceCommand) { if (eventRecurranceCommand.ActionType == Contracts.Commands.CreateEventV1.ActionType.BulkReschedule) { var eventSchedule = _eventScheduleRepository.Get(eventRecurranceCommand.EventScheduleId); eventSchedule.StartDateTime = _commonUtilityProvider.GetUtcDate(eventRecurranceCommand.StartDateTime, eventRecurranceCommand.LocalStartTime, eventRecurranceCommand.TimeZoneOffSet); eventSchedule.EndDateTime = _commonUtilityProvider.GetUtcDate(eventRecurranceCommand.StartDateTime, eventRecurranceCommand.LocalStartTime, eventRecurranceCommand.TimeZoneOffSet); eventSchedule.Name = eventRecurranceCommand.StartDateTime.ToString() + " - " + eventRecurranceCommand.EndDateTime.ToString(); eventSchedule.ModifiedBy = eventRecurranceCommand.ModifiedBy; eventSchedule.UpdatedBy = eventRecurranceCommand.ModifiedBy; eventSchedule.UpdatedUtc = DateTime.UtcNow; _eventScheduleRepository.Save(eventSchedule); } }
private FIL.Contracts.DataModels.EventSchedule SaveEventSchedule(FIL.Contracts.Commands.CreateEventV1.EventRecurranceCommand eventRecurranceCommand) { var eventSchedule = new FIL.Contracts.DataModels.EventSchedule { EventId = eventRecurranceCommand.EventId, DayId = eventRecurranceCommand.DayIds, EventFrequencyTypeId = eventRecurranceCommand.EventFrequencyType, OccuranceTypeId = eventRecurranceCommand.OccuranceType, StartDateTime = _commonUtilityProvider.GetUtcDate(eventRecurranceCommand.StartDateTime, eventRecurranceCommand.LocalStartTime, eventRecurranceCommand.TimeZoneOffSet), EndDateTime = _commonUtilityProvider.GetUtcDate(eventRecurranceCommand.EndDateTime, eventRecurranceCommand.LocalEndTime, eventRecurranceCommand.TimeZoneOffSet), Name = eventRecurranceCommand.StartDateTime.ToString() + " - " + eventRecurranceCommand.EndDateTime.ToString(), IsEnabled = true, CreatedBy = eventRecurranceCommand.ModifiedBy, CreatedUtc = DateTime.UtcNow, ModifiedBy = eventRecurranceCommand.ModifiedBy, UpdatedBy = eventRecurranceCommand.ModifiedBy, UpdatedUtc = DateTime.UtcNow }; return(_eventScheduleRepository.Save(eventSchedule)); }
public List <FIL.Contracts.DataModels.ScheduleDetail> GetScheduleDetails(FIL.Contracts.Commands.CreateEventV1.EventRecurranceCommand eventRecurranceCommand) { List <FIL.Contracts.DataModels.ScheduleDetail> eventSchedules = new List <Contracts.DataModels.ScheduleDetail>(); List <FIL.Contracts.DataModels.ScheduleDetail> eventSchedules1 = new List <Contracts.DataModels.ScheduleDetail>(); var startDateTime = _commonUtilityProvider.GetUtcDate(eventRecurranceCommand.StartDateTime, eventRecurranceCommand.LocalStartTime, eventRecurranceCommand.TimeZoneOffSet); var endDateTime = _commonUtilityProvider.GetUtcDate(eventRecurranceCommand.EndDateTime, eventRecurranceCommand.LocalEndTime, eventRecurranceCommand.TimeZoneOffSet); if (eventRecurranceCommand.ActionType == Contracts.Commands.CreateEventV1.ActionType.BulkReschedule) { SaveEventSchedule(eventRecurranceCommand); eventSchedules = _scheduleDetailRepository.GetAllByEventScheduleId(eventRecurranceCommand.EventScheduleId).ToList(); } else { var scheduleDetail = _scheduleDetailRepository.Get(eventRecurranceCommand.ScheduleDetailId); scheduleDetail.StartDateTime = startDateTime; scheduleDetail.EndDateTime = endDateTime; scheduleDetail.UpdatedBy = eventRecurranceCommand.ModifiedBy; scheduleDetail.ModifiedBy = eventRecurranceCommand.ModifiedBy; scheduleDetail.UpdatedUtc = DateTime.UtcNow; eventSchedules.Add(scheduleDetail); return(eventSchedules); } foreach (var scheduleDetail in eventSchedules) { if (scheduleDetail.StartDateTime.Date >= startDateTime.Date && scheduleDetail.EndDateTime.Date <= endDateTime.Date) { scheduleDetail.StartDateTime = _commonUtilityProvider.GetUtcDate(scheduleDetail.StartDateTime, eventRecurranceCommand.LocalStartTime, eventRecurranceCommand.TimeZoneOffSet); scheduleDetail.EndDateTime = _commonUtilityProvider.GetUtcDate(scheduleDetail.EndDateTime, eventRecurranceCommand.LocalEndTime, eventRecurranceCommand.TimeZoneOffSet); scheduleDetail.UpdatedBy = eventRecurranceCommand.ModifiedBy; scheduleDetail.ModifiedBy = eventRecurranceCommand.ModifiedBy; scheduleDetail.UpdatedUtc = DateTime.UtcNow; eventSchedules1.Add(scheduleDetail); } } return(eventSchedules); }
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); }
public void DeleteEventSchedule(FIL.Contracts.Commands.CreateEventV1.EventRecurranceCommand eventRecurranceCommand) { var eventSchedule = _eventScheduleRepository.Get(eventRecurranceCommand.EventScheduleId); _eventScheduleRepository.Delete(eventSchedule); }