Пример #1
0
        /// <see cref="IConcertService.SaveConcertSchedules"/>
        public bool SaveConcertSchedules(ConcertDateRangeModel model)
        {
            var list             = new List <ConcertScheduleModel>();
            ConcertDateRange res = null;

            _concertRepository.DeleteConcertSchedule(model.IdEvent);
            if (model.IsRepeated)
            {
                if (model.WeekSchedules != null)
                {
                    list.AddRange(ConcertModelHelper.GetSchedules(model.WeekSchedules));
                }
                if (model.RangeSchedules != null)
                {
                    list.AddRange(ConcertModelHelper.GetSchedules(model.RangeSchedules));
                }
                var sort =
                    list.GroupBy(o => new { ds = o.DateStart, de = o.DateEnd }).Select(o => new ConcertDateRangeModel
                {
                    DateStart  = o.Key.ds,
                    DateEnd    = o.Key.de,
                    IdEvent    = model.IdEvent,
                    IsRepeated = true
                });
                foreach (var el in sort)
                {
                    var sched = list.Where(o => o.DateStart == el.DateStart && o.DateEnd == el.DateEnd);
                    res = _concertRepository.SaveConcertSchedule(ConcertModelHelper.GetDateRange(el),
                                                                 ConcertModelHelper.GetSchedules(sched));
                    if (res == null)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (model.OneSchedule == null)
                {
                    return(true);
                }
                list.Add(model.OneSchedule);
                res = _concertRepository.SaveConcertSchedule(ConcertModelHelper.GetDateRange(model),
                                                             ConcertModelHelper.GetSchedules(list));
            }
            return(res != null);
        }