public void addCalendar(PlaceCalendarCommand command, Event place) { try { /*------------------------- Regular Time ----------------------------*/ var currentIndex = 0; foreach (bool currentDay in command.RegularTimeModel.DaysOpen) { if (currentIndex > 0 && currentDay) { var placeWeekOpenDays = new PlaceWeekOpenDays(); placeWeekOpenDays.AltId = Guid.NewGuid(); placeWeekOpenDays.DayId = currentIndex; placeWeekOpenDays.EventId = place.Id; placeWeekOpenDays.IsSameTime = command.RegularTimeModel.IsSameTime; placeWeekOpenDays.IsEnabled = true; placeWeekOpenDays.CreatedUtc = DateTime.UtcNow; placeWeekOpenDays.UpdatedUtc = DateTime.UtcNow; placeWeekOpenDays.CreatedBy = Guid.NewGuid(); placeWeekOpenDays.UpdatedBy = Guid.NewGuid(); _placeWeekOpenDaysRepository.Save(placeWeekOpenDays); } currentIndex = currentIndex + 1; } if (command.RegularTimeModel.IsSameTime) { var placeWeekOpnday = _placeWeekOpenDaysRepository.GetByEventId(place.Id); foreach (FIL.Contracts.DataModels.PlaceWeekOpenDays currentDay in placeWeekOpnday) { foreach (FIL.Contracts.Commands.PlaceCalendar.TimeViewModel currentTime in command.RegularTimeModel.TimeModel) { var dayTimeMapping = new DayTimeMappings(); dayTimeMapping.AltId = Guid.NewGuid(); dayTimeMapping.StartTime = currentTime.From; dayTimeMapping.EndTime = currentTime.To; dayTimeMapping.PlaceWeekOpenDayId = currentDay.Id; dayTimeMapping.IsEnabled = true; dayTimeMapping.CreatedUtc = DateTime.UtcNow; dayTimeMapping.UpdatedUtc = DateTime.UtcNow; dayTimeMapping.CreatedBy = Guid.NewGuid(); dayTimeMapping.UpdatedBy = Guid.NewGuid(); _dayTimeMappingsRepository.Save(dayTimeMapping); } } } if (!command.RegularTimeModel.IsSameTime) { var placeWeekOpnday = _placeWeekOpenDaysRepository.GetByEventId(place.Id); foreach (FIL.Contracts.DataModels.PlaceWeekOpenDays currentDay in placeWeekOpnday) { foreach (FIL.Contracts.Commands.PlaceCalendar.CustomTimeModelData currentTime in command.RegularTimeModel.CustomTimeModel) { var currentDays = _daysRepository.GetByDayname(currentTime.Day); if (currentDays.Id == currentDay.DayId) { foreach (FIL.Contracts.Commands.PlaceCalendar.TimeViewModel time in currentTime.Time) { var dayTimeMapping = new DayTimeMappings(); dayTimeMapping.AltId = Guid.NewGuid(); dayTimeMapping.StartTime = time.From; dayTimeMapping.EndTime = time.To; dayTimeMapping.PlaceWeekOpenDayId = currentDay.Id; dayTimeMapping.IsEnabled = true; dayTimeMapping.CreatedUtc = DateTime.UtcNow; dayTimeMapping.UpdatedUtc = DateTime.UtcNow; dayTimeMapping.CreatedBy = Guid.NewGuid(); dayTimeMapping.UpdatedBy = Guid.NewGuid(); _dayTimeMappingsRepository.Save(dayTimeMapping); } } } } } /*------------------------- Season Time ----------------------------*/ foreach (FIL.Contracts.Commands.PlaceCalendar.SeasonViewModel currentSeason in command.SeasonTimeModel) { var currentDayIndex = 0; var placeSeasonDetail = new PlaceSeasonDetails(); placeSeasonDetail.Name = currentSeason.Name; placeSeasonDetail.StartDate = currentSeason.StartDate; placeSeasonDetail.EndDate = currentSeason.EndDate; placeSeasonDetail.AltId = Guid.NewGuid(); placeSeasonDetail.EventId = place.Id; placeSeasonDetail.IsSameTime = currentSeason.IsSameTime; placeSeasonDetail.IsEnabled = true; placeSeasonDetail.CreatedUtc = DateTime.UtcNow; placeSeasonDetail.UpdatedUtc = DateTime.UtcNow; placeSeasonDetail.CreatedBy = Guid.NewGuid(); placeSeasonDetail.UpdatedBy = Guid.NewGuid(); var currentSeasonModel = _placeSeasonDetailsRepository.Save(placeSeasonDetail); foreach (bool currentDay in currentSeason.DaysOpen) { if (currentDayIndex > 0 && currentDay) { var day = _daysRepository.Get(currentDayIndex); var seasonDayMappingModel = new SeasonDaysMapping(); seasonDayMappingModel.AltId = Guid.NewGuid(); seasonDayMappingModel.DayId = currentDayIndex; seasonDayMappingModel.PlaceSeasonDetailId = currentSeasonModel.Id; seasonDayMappingModel.IsEnabled = true; seasonDayMappingModel.CreatedUtc = DateTime.UtcNow; seasonDayMappingModel.UpdatedUtc = DateTime.UtcNow; seasonDayMappingModel.CreatedBy = Guid.NewGuid(); seasonDayMappingModel.UpdatedBy = Guid.NewGuid(); var seasonDay = _seasonDaysMappingsRepository.Save(seasonDayMappingModel); if (currentSeason.IsSameTime) { foreach (FIL.Contracts.Commands.PlaceCalendar.TimeViewModel currentTime in currentSeason.SameTime) { var seasonDayTimeMappings = new SeasonDaysTimeMapping(); seasonDayTimeMappings.SeasonDaysMappingId = seasonDay.Id; seasonDayTimeMappings.AltId = Guid.NewGuid(); seasonDayTimeMappings.StartTime = currentTime.From; seasonDayTimeMappings.EndTime = currentTime.To; seasonDayTimeMappings.IsEnabled = true; seasonDayTimeMappings.CreatedUtc = DateTime.UtcNow; seasonDayTimeMappings.UpdatedUtc = DateTime.UtcNow; seasonDayTimeMappings.CreatedBy = Guid.NewGuid(); seasonDayTimeMappings.UpdatedBy = Guid.NewGuid(); _seasonDayTimeMappingsRepository.Save(seasonDayTimeMappings); } } else if (!currentSeason.IsSameTime) { foreach (FIL.Contracts.Commands.PlaceCalendar.SpeecialDateSeasonTimeViewModel currentSpeecialDateSeasonTimeViewModel in currentSeason.Time) { if (currentSpeecialDateSeasonTimeViewModel.Day == day.Name) { foreach (FIL.Contracts.Commands.PlaceCalendar.TimeViewModel currentTime in currentSpeecialDateSeasonTimeViewModel.Time) { var seasonDayTimeMappings = new SeasonDaysTimeMapping(); seasonDayTimeMappings.SeasonDaysMappingId = seasonDay.Id; seasonDayTimeMappings.AltId = Guid.NewGuid(); seasonDayTimeMappings.StartTime = currentTime.From; seasonDayTimeMappings.EndTime = currentTime.To; seasonDayTimeMappings.IsEnabled = true; seasonDayTimeMappings.CreatedUtc = DateTime.UtcNow; seasonDayTimeMappings.UpdatedUtc = DateTime.UtcNow; seasonDayTimeMappings.CreatedBy = Guid.NewGuid(); seasonDayTimeMappings.UpdatedBy = Guid.NewGuid(); _seasonDayTimeMappingsRepository.Save(seasonDayTimeMappings); } } } } } currentDayIndex = currentDayIndex + 1; } } /*------------------------- Special Day/Holiday Time ----------------------------*/ foreach (FIL.Contracts.Commands.PlaceCalendar.SpecialDayViewModel currentSpecialDay in command.SpecialDayModel) { var specialDay = new PlaceSpecialDayTimeMappings(); specialDay.Name = currentSpecialDay.Name; specialDay.SpecialDate = currentSpecialDay.SpecialDate; specialDay.StartTime = currentSpecialDay.From; specialDay.EndTime = currentSpecialDay.To; specialDay.EventId = place.Id; specialDay.AltId = Guid.NewGuid(); specialDay.IsEnabled = true; specialDay.CreatedUtc = DateTime.UtcNow; specialDay.UpdatedUtc = DateTime.UtcNow; specialDay.CreatedBy = Guid.NewGuid(); specialDay.UpdatedBy = Guid.NewGuid(); _placeSpecialDayTimeMappingsRepository.Save(specialDay); } } catch (Exception e) { } }
public GetPlaceInventoryQueryResult GetCalendarData(long eventId) { /*-------------------------- Regular Time --------------------------*/ var placeWeekOpenDays = _placeWeekOpenDaysRepository.GetByEventId(eventId).ToList(); var allDays = _daysRepository.GetAll().ToList(); var regular = new RegularViewModel(); if (placeWeekOpenDays.Any()) { bool[] openDays = new bool[8]; var i = 0; foreach (FIL.Contracts.DataModels.PlaceWeekOpenDays currentPlaceWeek in placeWeekOpenDays) { openDays[currentPlaceWeek.DayId] = true; i = i + 1; } if (i == 7) { openDays[0] = true; } if (placeWeekOpenDays[0].IsSameTime) { i = 0; var dayTimeMappings = _dayTimeMappingsRepository.GetAllByPlaceWeekOpenDay(placeWeekOpenDays[0].Id).ToList(); List <TimeViewModel> timeModels = new List <TimeViewModel>(); List <CustomTimeModelData> customTimeModels = new List <CustomTimeModelData>(); foreach (FIL.Contracts.DataModels.DayTimeMappings daysTime in dayTimeMappings) { var newTimeModel = new TimeViewModel(); newTimeModel.Id = i + 1; newTimeModel.From = daysTime.StartTime; newTimeModel.To = daysTime.EndTime; i = i + 1; timeModels.Add(newTimeModel); } regular.TimeModel = timeModels; i = 0; foreach (FIL.Contracts.DataModels.PlaceWeekOpenDays currentPlaceWeek in placeWeekOpenDays) { var newCustomTimeModel = new CustomTimeModelData(); timeModels = new List <TimeViewModel>(); var newTimeModel = new TimeViewModel(); var currentDay = _daysRepository.Get(currentPlaceWeek.DayId); newCustomTimeModel.Id = i + 1; newCustomTimeModel.Day = currentDay.Name; newTimeModel.Id = i + 1; newTimeModel.From = ""; newTimeModel.To = ""; timeModels.Add(newTimeModel); newCustomTimeModel.Time = timeModels; customTimeModels.Add(newCustomTimeModel); i = i + 1; } regular.CustomTimeModel = customTimeModels; } else if (!placeWeekOpenDays[0].IsSameTime) { i = 0; var dayTimeMappings = _dayTimeMappingsRepository.GetAllByPlaceWeekOpenDay(placeWeekOpenDays[0].Id).ToList(); List <TimeViewModel> timeModels = new List <TimeViewModel>(); List <CustomTimeModelData> customTimeModels = new List <CustomTimeModelData>(); var newTimeModel = new TimeViewModel(); newTimeModel.Id = i + 1; newTimeModel.From = ""; newTimeModel.To = ""; timeModels.Add(newTimeModel); regular.TimeModel = timeModels; i = 0; foreach (FIL.Contracts.DataModels.PlaceWeekOpenDays currentPlaceWeek in placeWeekOpenDays) { var newCustomTimeModel = new CustomTimeModelData(); var currentDayTimeMappings = _dayTimeMappingsRepository.GetAllByPlaceWeekOpenDay(currentPlaceWeek.Id).ToList(); var currentDay = _daysRepository.Get(currentPlaceWeek.DayId); timeModels = new List <TimeViewModel>(); var index = 0; foreach (FIL.Contracts.DataModels.DayTimeMappings currentTime in currentDayTimeMappings) { var currentTimeModel = new TimeViewModel(); currentTimeModel.Id = index + 1; currentTimeModel.From = currentTime.StartTime; currentTimeModel.To = currentTime.EndTime; timeModels.Add(currentTimeModel); index = index + 1; } newCustomTimeModel.Time = timeModels; newCustomTimeModel.Day = currentDay.Name; newCustomTimeModel.Id = i + 1; customTimeModels.Add(newCustomTimeModel); i = i + 1; } regular.CustomTimeModel = customTimeModels; } regular.IsSameTime = placeWeekOpenDays[0].IsSameTime; regular.DaysOpen = openDays.OfType <bool>().ToList(); } else { if (regular.CustomTimeModel == null) { regular.CustomTimeModel = new List <CustomTimeModelData>(); } if (regular.TimeModel == null) { regular.TimeModel = new List <TimeViewModel>(); } if (regular.DaysOpen == null) { bool[] openDays = new bool[8]; regular.DaysOpen = openDays.OfType <bool>().ToList(); } regular.IsSameTime = true; } /*-------------------------- Season Time --------------------------*/ var season = new List <SeasonViewModel>(); var placeSeasonDetails = _placeSeasonDetailsRepository.GetByEventId(eventId).ToList(); var seasonIndex = 0; foreach (FIL.Contracts.DataModels.PlaceSeasonDetails currentSeason in placeSeasonDetails) { var seasonDaysMappings = _seasonDaysMappingsRepository.GetByPlaceSeasonDetailId(currentSeason.Id).ToList(); var newSeasonViewModel = new SeasonViewModel(); List <TimeViewModel> timeModelList = new List <TimeViewModel>(); List <SpeecialDateSeasonTimeViewModel> speecialDateSeasonTimeList = new List <SpeecialDateSeasonTimeViewModel>(); bool[] openDays = new bool[8]; if (currentSeason.IsSameTime && seasonDaysMappings.Any()) { var seasonSameTiming = _seasonDayTimeMappingsRepository.GetSeasonDaysMappings(seasonDaysMappings[0].Id).ToList(); var timeIndex = 0; foreach (FIL.Contracts.DataModels.SeasonDaysTimeMapping currentSeasonTime in seasonSameTiming) { var timeModel = new TimeViewModel(); timeModel.Id = timeIndex; timeModel.From = currentSeasonTime.StartTime; timeModel.To = currentSeasonTime.EndTime; timeIndex = timeIndex + 1; timeModelList.Add(timeModel); } timeIndex = 0; foreach (FIL.Contracts.DataModels.SeasonDaysMapping currentSeasonDay in seasonDaysMappings) { var speecialDateSeasonTime = new SpeecialDateSeasonTimeViewModel(); var currentDay = _daysRepository.Get(currentSeasonDay.DayId); var timeModels = new List <TimeViewModel>(); var timeModel = new TimeViewModel(); timeModel.Id = 1; timeModel.From = ""; timeModel.To = ""; timeModels.Add(timeModel); speecialDateSeasonTime.Id = timeIndex + 1; speecialDateSeasonTime.Day = currentDay.Name; speecialDateSeasonTime.Time = timeModels; openDays[currentSeasonDay.DayId] = true; timeIndex = timeIndex + 1; speecialDateSeasonTimeList.Add(speecialDateSeasonTime); } } else if (!currentSeason.IsSameTime) { var timeIndex = 0; var timeModel = new TimeViewModel(); timeModel.Id = 1; timeModel.From = ""; timeModel.To = ""; timeModelList.Add(timeModel); foreach (FIL.Contracts.DataModels.SeasonDaysMapping currentSeasonDay in seasonDaysMappings) { var speecialDateSeasonTime = new SpeecialDateSeasonTimeViewModel(); var currentDay = _daysRepository.Get(currentSeasonDay.DayId); var timeModels = new List <TimeViewModel>(); var seasonSpecialTime = _seasonDayTimeMappingsRepository.GetSeasonDaysMappings(currentSeasonDay.Id); var seasonTimeIndex = 0; foreach (FIL.Contracts.DataModels.SeasonDaysTimeMapping currentSeasonDayTime in seasonSpecialTime) { timeModel = new TimeViewModel(); timeModel.Id = seasonTimeIndex + 1; timeModel.To = currentSeasonDayTime.EndTime; timeModel.From = currentSeasonDayTime.StartTime; timeModels.Add(timeModel); seasonTimeIndex = seasonTimeIndex + 1; } openDays[currentSeasonDay.DayId] = true; speecialDateSeasonTime.Id = timeIndex + 1; speecialDateSeasonTime.Day = currentDay.Name; speecialDateSeasonTime.Time = timeModels; speecialDateSeasonTimeList.Add(speecialDateSeasonTime); timeIndex = timeIndex + 1; } } newSeasonViewModel.Id = seasonIndex + 1; newSeasonViewModel.SameTime = timeModelList; newSeasonViewModel.Time = speecialDateSeasonTimeList; newSeasonViewModel.StartDate = currentSeason.StartDate.AddHours(5).AddMinutes(30); newSeasonViewModel.EndDate = currentSeason.EndDate.AddHours(5).AddMinutes(30); newSeasonViewModel.Name = currentSeason.Name; newSeasonViewModel.IsSameTime = currentSeason.IsSameTime; newSeasonViewModel.DaysOpen = openDays.OfType <bool>().ToList(); seasonIndex = seasonIndex + 1; season.Add(newSeasonViewModel); } /*-------------------------- Special day/Holiday Time --------------------------*/ var specialDay = new List <SpecialDayViewModel>(); var specialDays = _placeSpecialDayTimeMappingsRepository.GetAllByEventId(eventId); var specialDayindex = 0; foreach (FIL.Contracts.DataModels.PlaceSpecialDayTimeMappings currentSpecialDay in specialDays) { var newSpecialDay = new SpecialDayViewModel(); newSpecialDay.Id = specialDayindex + 1; newSpecialDay.Name = currentSpecialDay.Name; newSpecialDay.From = currentSpecialDay.StartTime; newSpecialDay.To = currentSpecialDay.EndTime; newSpecialDay.SpecialDate = currentSpecialDay.SpecialDate.AddHours(5).AddMinutes(30); specialDayindex = specialDayindex + 1; specialDay.Add(newSpecialDay); } return(new GetPlaceInventoryQueryResult { SeasonTimeModel = season, SpecialDayModel = specialDay, RegularTimeModel = regular }); }