Пример #1
0
        public IActionResult <PizzaSuggestionViewModel> Index(VotePizzaBindingModel model, HttpSession session, HttpResponse response)
        {
            using (PizzaMoreContext context = new PizzaMoreContext())
            {
                User currentUser = RetrieveUser(session, context);
                PizzaSuggestionViewModel viewModel = new PizzaSuggestionViewModel()
                {
                    Email            = currentUser.Email,
                    PizzaSuggestions = currentUser.PizzaSuggestions
                };

                Pizza pizzaEntity = context.Pizzas.Find(model.PizzaId);
                if (model.PizzaVote == "Up")
                {
                    pizzaEntity.UpVotes++;
                }
                else
                {
                    pizzaEntity.DownVotes++;
                }

                context.SaveChanges();
                this.Redirect(response, "/menu/index");
                return(null);
            }
        }
Пример #2
0
        public IActionResult Index(VotePizzaBindingModel model, HttpResponse response)
        {
            var service = new MenuService(Data.Data.Context);

            service.AddVoteForPizza(model);

            this.Redirect(response, "/menu/index");
            return(null);
        }
Пример #3
0
        public IActionResult <MenuPizzasViewModel> Index(VotePizzaBindingModel bindingModel, HttpSession currentSession, HttpResponse response)
        {
            if (!this.signInManger.IsAuthenticated(currentSession))
            {
                this.Redirect(response, "/home/index");
                return(null);
            }

            this.pizzasService.AddVote(bindingModel);
            this.Redirect(response, "/menu/index");
            return(null);
        }
Пример #4
0
        public void AddVoteForPizza(VotePizzaBindingModel model)
        {
            var pizza = this.context.Pizzas.Find(model.PizzaId);

            if (model.PizzaVote == "Up")
            {
                pizza.UpVotes++;
            }
            else
            {
                pizza.DownVotes++;
            }

            this.context.SaveChanges();
        }
Пример #5
0
        internal void AddVote(VotePizzaBindingModel bindingModel)
        {
            Pizza currentPizza = this.context.Pizzas.Find(bindingModel.PizzaId);

            if (bindingModel.Vote == "Up")
            {
                currentPizza.UpVotes++;
            }

            if (bindingModel.Vote == "Down")
            {
                currentPizza.DownVotes++;
            }

            this.context.SaveChanges();
        }