// GET BY ID - READ public ZooListItems GetZooById(int id) { AttractionService attractionService = new AttractionService(); ReviewService reviewService = new ReviewService(); using (var ctx = new ApplicationDbContext()) { var entity = ctx .Zoos .SingleOrDefault(e => e.ZooId == id); foreach (Attraction attraction in entity.Attractions) { AttractionDetail attractionDetail = attractionService.GetAttractionById(attraction.AttId); var detail = new ZooListItems { ZooId = entity.ZooId, ZooName = entity.ZooName, Location = entity.Location, ZooSize = entity.ZooSize, AZAAccredited = entity.AZAAccredited, Admission = entity.Admission, AverageRating = entity.AverageRating, AttractionDetails = attractionDetail, AllZooReviews = new List <ReviewDetail>() //entity.AllZooReviews.Select(e=>reviewService.GetReviewById(e.ReviewId)).ToList() }; foreach (Review review in entity.AllZooReviews) { ReviewDetail reviewDetail = reviewService.GetReviewById(review.ReviewId); detail.AllZooReviews.Add(reviewDetail); } return(detail); } var zooDetail = new ZooListItems { ZooId = entity.ZooId, ZooName = entity.ZooName, Location = entity.Location, ZooSize = entity.ZooSize, AZAAccredited = entity.AZAAccredited, Admission = entity.Admission, AverageRating = entity.AverageRating, AllZooReviews = new List <ReviewDetail>() }; foreach (Review review in entity.AllZooReviews) { ReviewDetail reviewDetail = reviewService.GetReviewById(review.ReviewId); zooDetail.AllZooReviews.Add(reviewDetail); } return(zooDetail); } }
public AttractionDetail GetAttractionById(int id) { var entity = _context.Attractions.Find(id); if (entity == null) { return(null); } var detail = new AttractionDetail { AttId = entity.AttId, Animals = entity.Animals, Experiences = entity.Experiences, HasAquaticExhibit = entity.HasAquaticExhibit, HasGarden = entity.HasGarden, SeasonalAttractions = entity.SeasonalAttractions, ZooId = entity.ZooId, }; return(detail); }
// GET ALL - READ public IEnumerable <ZooListItems> GetZoos() { using (var ctx = new ApplicationDbContext()) { AttractionDetail attractionDetail = new AttractionDetail(); var zooQuery = ctx .Zoos.ToList() .Select( e => new ZooListItems { ZooId = e.ZooId, ZooName = e.ZooName, ZooSize = e.ZooSize, Location = e.Location, AZAAccredited = e.AZAAccredited, Admission = e.Admission, AverageRating = e.AverageRating, }); return(zooQuery.ToArray()); } }