Example #1
0
        public ActionResult List(string controller, int id)
        {
            List <Review> reviews = null;

            if (controller == "Food")
            {
                reviews = _reviewRepository.GetAll().Where(f => f.FoodId == id).ToList();
            }
            else if (controller == "Restaurant")
            {
                reviews = _reviewRepository.GetAll().Where(r => r.RestaurantId == id).ToList();
            }

            var reviewListViewModels = new List <ReviewListViewModel>();

            var config = new MapperConfiguration(cfg => cfg.CreateMap <Review, ReviewListViewModel>());
            var mapper = config.CreateMapper();

            if (reviews != null)
            {
                foreach (Review review in reviews)
                {
                    ReviewListViewModel reviewListViewModel = mapper.Map <ReviewListViewModel>(review);
                    reviewListViewModels.Add(reviewListViewModel);
                    Foodie foodie = _foodieRepository.Get(reviewListViewModel.UserId);
                    reviewListViewModel.UserName = foodie.FirstName + foodie.LastName;
                }
            }

            return(PartialView(reviewListViewModels));
        }
Example #2
0
        public ActionResult Index()
        {
            _profile = _repository.Get(Convert.ToInt32(Session["UserId"]));


            //Create Map
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Foodie, FoodieDetailsViewModel>());
            var mapper = config.CreateMapper();

            //Copy values
            FoodieDetailsViewModel profileDetails = mapper.Map <FoodieDetailsViewModel>(_profile);

            if (_profile != null)
            {
                profileDetails.Email    = Session["Email"].ToString();
                profileDetails.CheckIns = _profile.CheckIns;
            }

            return(View(profileDetails));
        }