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); } }
public IActionResult Index(VotePizzaBindingModel model, HttpResponse response) { var service = new MenuService(Data.Data.Context); service.AddVoteForPizza(model); this.Redirect(response, "/menu/index"); return(null); }
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); }
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(); }
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(); }