Пример #1
0
        public IHttpActionResult GetParkByParkName(string parkName)
        {
            ParkModel park = parkDAL.GetParkByParkName(parkName);

            park.Trails = trailDAL.GetTrailsByParkName(parkName);
            park.UserVisitedPanoramics = new List <PanoramicModel>();
            park.Trails.ForEach(
                trail =>
            {
                trail.TrailHead         = panoramicDAL.GetTrailHeadByTrailId(trail.TrailId);
                trail.PointsOfInterest  = panoramicDAL.GetPointsOfInterestByTrailId(trail.TrailId);
                trail.PanoramicsInTrail = panoramicDAL.GetPanoramicsByTrailId(trail.TrailId);
                trail.PanoramicsInTrail.ForEach(
                    panoramic => panoramic.Connections = panoramicDAL.GetConnectionsByPanoramicId(panoramic.PanoramicId)
                    );

                if (User.Identity.IsAuthenticated)
                {
                    park.UserVisitedPanoramics.AddRange(panoramicDAL.GetVisitedPanoramicsByUsername(User.Identity.Name));
                }
            }
                );


            return(Ok(park));
        }
Пример #2
0
        public ActionResult ViewTrail(string trailName, int?panoramicId)
        {
            List <TrailModel> trails = trailDAL.GetAllTrails();

            trails.ForEach(trail => trail.TrailHead = panoramicDAL.GetTrailHeadByTrailId(trail.TrailId));
            List <PanoramicModel>      panoramics     = panoramicDAL.GetAllPanoramics();
            List <LastSeenImagesModel> lastSeenImages = lastSeenImagesDAL.GetAllLastSeenImages();
            List <LastSeenVideosModel> lastSeenVideos = lastSeenVideosDAL.GetAllLastSeenVideos();
            LastSeenModel superModel = new LastSeenModel()
            {
                Images = lastSeenImages,
                Videos = lastSeenVideos
            };

            if (!trails.Select(trail => trail.Name).Contains(trailName) ||
                (panoramics.FirstOrDefault(panoramic => panoramic.PanoramicId == panoramicId) == null) && panoramicId != null)
            {
                return(new HttpStatusCodeResult(404));
            }

            int       selectedParkId = trails.First(trail => trail.Name == trailName).ParkId;
            ParkModel selectedPark   = parkDAL.GetParkById(selectedParkId);

            int           selectedTrailId = trails.First(trail => trail.Name == trailName).TrailId;
            List <string> selectedTrail   = trailDAL.GetTrailDescriptionByTrailId(selectedTrailId);

            if (panoramicId == null)
            {
                return(RedirectToAction("ViewTrail", new { trailName = trailName, panoramicId = trails.First(trail => trail.Name == trailName).TrailHead.PanoramicId }));
            }
            ViewBag.TrailName          = trailName;
            ViewBag.ParkName           = selectedPark.Name;
            ViewBag.NameAndDescription = selectedTrail;

            return(View("ViewTrail", superModel));
        }