示例#1
0
        public ActionResult Edit(FoodieEditViewModel input)
        {
            if (Session["UserId"] != null)
            {
                _profile = _repository.Get(Convert.ToInt32(Session["UserId"]));

                var config = new MapperConfiguration(cfg => cfg.CreateMap <FoodieEditViewModel, Foodie>());
                var mapper = config.CreateMapper();
                //Copy values

                Foodie userProfile = mapper.Map <Foodie>(input);
                userProfile.UserId = Convert.ToInt32(Session["UserId"]);

                if (input.PostedPicture != null)
                {
                    FilePreProcessor(input, userProfile);
                }

                _repository.Update(userProfile);


                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Index", "Login"));
        }
示例#2
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));
        }
示例#3
0
        public async Task <IActionResult> Edit(int id, [Bind("FoodieId,FoodieName,IdentityUserId")] Foodie foodie)
        {
            if (id != foodie.FoodieId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(foodie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FoodieExists(foodie.FoodieId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdentityUserId"] = new SelectList(_context.Users, "Id", "Id", foodie.IdentityUserId);
            return(View(foodie));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("FoodieId,FoodieName,IdentityUserId")] Foodie foodie)
        {
            if (ModelState.IsValid)
            {
                var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                foodie.IdentityUserId = userId;
                _context.Add(foodie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdentityUserId"] = new SelectList(_context.Users, "Id", "Id", foodie.IdentityUserId);
            return(View(foodie));
        }
示例#5
0
        public ActionResult Edit()
        {
            if (Session["UserId"] != null)
            {
                _profile = _repository.Get(Convert.ToInt32(Session["UserId"]));

                var config = new MapperConfiguration(cfg => cfg.CreateMap <Foodie, FoodieEditViewModel>());
                var mapper = config.CreateMapper();
                //Copy values

                FoodieEditViewModel profileEditViewModel = mapper.Map <FoodieEditViewModel>(_profile);

                return(View(profileEditViewModel));
            }

            return(RedirectToAction("Index", "Login"));
        }
示例#6
0
        public ActionResult Details(int id)
        {
            _profile = _repository.Get(id);


            //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.CheckIns = _profile.CheckIns;
            }

            return(View(profileDetails));
        }
示例#7
0
        public ActionResult ProfileView()
        {
            _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));
        }