コード例 #1
0
        public ActionResult Details(string url)
        {
            var eventDb = Mapper.Map <EventBaseVm>(_context.GetEvent(url));

            if (eventDb == null)
            {
                return(RedirectToAction("Index"));
            }
            var schedules = _context.GetEventPlacesByEventId(eventDb.EventId).Select(s => new EventScheduleItemVm {
                PlaceId = s.PlaceId, PlaceTitle = s.Title, PlaceUrl = s.TranslitUrl, PlaceAddress = s.Address
            }).ToList();

            foreach (var scheduleItem in schedules)
            {
                scheduleItem.StartEventList = _context.GetEventSchedulesDateTimes(eventDb.EventId, scheduleItem.PlaceId);
            }

            var otherEvents = Mapper.Map <List <EventBaseVm> >(_context.GetOtherEvent(eventDb.EventId));

            var places = _context.GetPlaceInfo(otherEvents.Select(s => s.EventId).ToList());

            Parallel.ForEach(otherEvents, eventItem =>
            {
                if (places.ContainsKey(eventItem.EventId))
                {
                    eventItem.PlaceUrl  = places[eventItem.EventId].Item1;
                    eventItem.PlaceName = places[eventItem.EventId].Item2;
                }
            });
            var model = new EventDetailsVm
            {
                Event       = eventDb,
                OtherEvents = otherEvents,
                Schedules   = schedules,
                StartDate   = _context.GetEventStartDate(eventDb.EventId)
            };

            model.Event.Title = string.Format("{0} \"{1}\"", model.Event.CategoryName, model.Event.Title);

            ViewBag.Keywords    = string.Format("подія, {0}", model.Event.Title.Split(' ').FirstOrDefault());
            ViewBag.Description = model.Event.ShortInfoCutted(150);
            if (Request.Url != null)
            {
                ViewBag.OgImage = string.Format("{0}{1}",
                                                Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, string.Empty), model.Event.PosterSmallUrl);
            }

            return(View(model));
        }