public IHttpActionResult GetRegistrationEvent(string segment, int id)
        {

            Event evt = RetrieveEvent(segment);
            if (evt == null)
            {
                return NotFound();
            }

            //get areas that have available tickets for the selected age group
            var cutoff = evt.TicketCutoffs.Where(x =>
                cstTime > x.OnSellDate && cstTime < x.CutoffDate).SingleOrDefault();
            if (cutoff == null)
            {
                return Ok(new List<RegistrationCutoffAreaApiModel>());
            }

            RegistrationCutoffApiModel item = new RegistrationCutoffApiModel
            {
                CutoffDate = cutoff.CutoffDate.ToShortDateString(),
                OnSellDate = cutoff.OnSellDate.ToShortDateString(),
                Areas = new List<RegistrationCutoffAreaApiModel>()
            };

            var discount = evt.TicketDiscounts.Where(x => x.TicketDiscountID == id).SingleOrDefault();

            if (discount == null)
            {
                return NotFound();
            }

            if (discount.TicketSeats.Count == 0)
            {
                foreach (var area in cutoff.TicketPrices.GroupBy(x => x.TicketArea))
                {
                    var prices = cutoff.TicketPrices.Where(x => x.TicketAreaID == area.Key.TicketAreaID).OrderBy(x => x.EventAgeGroup.MinimumAge);
                    var regArea = new RegistrationCutoffAreaApiModel
                    {
                        AreaID = area.Key.TicketAreaID,
                        Name = area.Key.Name,
                        Prices = new List<RegistrationCutoffPriceApiModel>()
                    };

                    foreach (var price in prices)
                    {
                        if (discount.EventAgeGroups.Contains(price.EventAgeGroup))
                        {
                            //discount limited to certain ages
                            var areaPrice = new RegistrationCutoffPriceApiModel
                            {
                                AgeName = price.EventAgeGroup.Name,
                                AgeRange = (price.EventAgeGroup.MaximumAge.HasValue ? price.EventAgeGroup.MinimumAge + " - " + price.EventAgeGroup.MaximumAge : price.EventAgeGroup.MinimumAge + "+"),
                                BasePrice = price.BasePrice
                            };

                            var discountArea = discount.TicketAreaDiscounts.Where(x => x.TicketAreaID == area.Key.TicketAreaID).SingleOrDefault();
                            if (discountArea != null)
                            {
                                //apply discount
                                areaPrice.BasePrice = CalculateDiscountedPrice(discountArea.AdjustmentType, areaPrice.BasePrice, discountArea.AdjustmentAmount);
                            }

                            regArea.Prices.Add(areaPrice);
                        }
                    }



                    item.Areas.Add(regArea);
                }
            }
            else
            {
                //reserved seats
                foreach (var area in discount.TicketSeats.GroupBy(x => x.TicketArea))
                {
                    var prices = cutoff.TicketPrices.Where(x => x.TicketAreaID == area.Key.TicketAreaID).OrderBy(x => x.EventAgeGroup.MinimumAge);
                    var regArea = new RegistrationCutoffAreaApiModel
                    {
                        AreaID = area.Key.TicketAreaID,
                        Name = area.Key.Name,
                        Prices = new List<RegistrationCutoffPriceApiModel>()
                    };

                    foreach (var price in prices)
                    {
                        if (discount.EventAgeGroups.Contains(price.EventAgeGroup))
                        {
                            //discount limited to certain ages
                            var areaPrice = new RegistrationCutoffPriceApiModel
                            {
                                AgeName = price.EventAgeGroup.Name,
                                AgeRange = (price.EventAgeGroup.MaximumAge.HasValue ? price.EventAgeGroup.MinimumAge + " - " + price.EventAgeGroup.MaximumAge : price.EventAgeGroup.MinimumAge + "+"),
                                BasePrice = price.BasePrice
                            };

                            var discountArea = discount.TicketAreaDiscounts.Where(x => x.TicketAreaID == area.Key.TicketAreaID).SingleOrDefault();
                            if (discountArea != null)
                            {
                                //apply discount
                                switch (discountArea.AdjustmentType)
                                {
                                    case AdjustmentType.Percent:
                                        areaPrice.BasePrice = areaPrice.BasePrice - (areaPrice.BasePrice * (discountArea.AdjustmentAmount / 100));

                                        break;
                                    case AdjustmentType.Flat:
                                        areaPrice.BasePrice = areaPrice.BasePrice - discountArea.AdjustmentAmount;
                                        break;
                                }
                                areaPrice.BasePrice = areaPrice.BasePrice < 0 ? 0 : areaPrice.BasePrice;

                            }

                            regArea.Prices.Add(areaPrice);
                        }
                    }



                    item.Areas.Add(regArea);
                }

            }

            return Ok(item);
        }
        public IHttpActionResult RegistrationPrices(string segment, int id)
        {

            Event evt = RetrieveEvent(segment);
            if (evt == null)
            {
                return NotFound();
            }

            if (!CanAccessRegistration(evt))
            {
                return BadRequest(GetDisabledMessage(evt));
            }

            TicketDiscount discount = evt.TicketDiscounts.Where(x => x.TicketDiscountID == id).SingleOrDefault();
            if (discount == null)
            {
                return NotFound();
            }

            //get areas that have available tickets for the selected age group
            var cutoff = evt.TicketCutoffs.Where(x =>
                cstTime > x.OnSellDate && cstTime < x.CutoffDate).SingleOrDefault();
            if (cutoff == null)
            {
                return Ok(new List<RegistrationCutoffAreaApiModel>());
            }

            RegistrationCutoffApiModel item = new RegistrationCutoffApiModel
            {
                CutoffDate = cutoff.CutoffDate.ToShortDateString(),
                OnSellDate = cutoff.OnSellDate.ToShortDateString(),
                Areas = new List<RegistrationCutoffAreaApiModel>()
            };

            List<int> discountAreas = discount.TicketSeats.Select(x => x.TicketAreaID).Distinct().ToList();
            foreach (var area in cutoff.TicketPrices.Where(x => discountAreas.Contains(x.TicketAreaID)).GroupBy(x => x.TicketArea))
            {
                TicketAreaDiscount areaDiscount = discount.TicketAreaDiscounts.Where(x => x.TicketAreaID == area.Key.TicketAreaID).Single();

    var prices = cutoff.TicketPrices.Where(x => x.TicketAreaID == area.Key.TicketAreaID).OrderBy(x => x.EventAgeGroup.MinimumAge);
                item.Areas.Add(new RegistrationCutoffAreaApiModel
                {
                    AreaID = area.Key.TicketAreaID,
                    Name = area.Key.Name,
                    // TODO: Adjust price by discount
                    Prices = prices.Select(x => new RegistrationCutoffPriceApiModel
                    {
                        AgeName = x.EventAgeGroup.Name,
                        AgeRange = (x.EventAgeGroup.MaximumAge.HasValue ? x.EventAgeGroup.MinimumAge + " - " + x.EventAgeGroup.MaximumAge : x.EventAgeGroup.MinimumAge + "+"),
                        BasePrice = CalculateDiscountedPrice(areaDiscount.AdjustmentType, x.BasePrice, areaDiscount.AdjustmentAmount)
                    }).ToList()
                });
            }

            return Ok(item);
        }