Exemplo n.º 1
0
 public static ConcertDateRange GetDateRange(ConcertDateRangeModel model)
 {
     return(model != null ? new ConcertDateRange
     {
         Id = model.Id,
         DateStart = model.DateStart,
         DateEnd = model.DateEnd,
         IsRepeated = model.IsRepeated,
         IdEvent = model.IdEvent
     } : null);
 }
Exemplo n.º 2
0
        public IHttpActionResult Post(int id, [FromBody] ConcertDateRangeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var userId = User.Identity.GetUserId <int>();
            var succes = ServiceResponce.FromSuccess().Result("Concert schedules save complete");
            var error  = ServiceResponce.FromFailed().Result($"Error save concert schedules");

            return(Ok(_concertService.SaveConcertSchedules(model) ? succes.Response() : error.Response()));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public static ConcertDateRangeModel GetDateRangeModel(IList <ConcertDateRange> models)
        {
            if (!models.Any())
            {
                return(null);
            }
            var maxDayEnd   = models.Max(o => o.DateEnd);
            var maxDayStart = models.Max(o => o.DateStart);
            var res         = new ConcertDateRangeModel
            {
                DateStart  = models.Min(o => o.DateStart),
                DateEnd    = maxDayStart > maxDayEnd ? maxDayStart : maxDayEnd,
                IsRepeated = models.Any(o => o.IsRepeated)
            };
            var weeks = models.Where(o => o.IsRepeated && o.Schedules.Any(x => x.WeekDay != null)).ToList();

            if (weeks.Any())
            {
                res.WeekSchedules = GetWeekScheduleModels(weeks);
                res.PreviewWeek   = GetPreviewWeek(weeks);
            }
            var range = models.Where(o => o.IsRepeated && o.Schedules.Any(x => x.WeekDay == null)).ToList();

            if (range.Any())
            {
                res.RangeSchedules = GetRangeScheduleModels(range);
                res.PreviewRange   = GetPreviewRange(range);
            }
            var one = models.OrderByDescending(o => o.DateStart).FirstOrDefault(o => !o.IsRepeated);

            if (one != null)
            {
                res.OneSchedule = GetScheduleModel(one.Schedules.FirstOrDefault(), one);
            }
            return(res);
        }