public ActionResult Index() { VotingViewModel votList = new VotingViewModel(); //Make Web Service Request string serviceURL = "https://api-snacks.nerderylabs.com/v1/snacks/"; var client = new RestClient(serviceURL, HttpVerb.GET); var json = client.MakeSnackRequest(""); //Parse JSON Into PRoper Payload Structure List<RestDataModel.GetSnacks> payload = JsonConvert.DeserializeObject<List<RestDataModel.GetSnacks>>(json); //Separate Both Snack Lists votList.votOnlineList = payload.Where(x => x.optional == true); votList.alwaysPurchasedOnlineList = payload.Where(x => x.optional == false); //Legacy Internal DB Code //votList.sugList = (from a in db.Suggestions // select a).ToList(); votList.votList = (from a in db.Votes select a).ToList(); //Get Cookie Info IF Applicable HttpCookie myCookie = HttpContext.Request.Cookies["votes"]; votList = VotingViewLogic.GetCounterInfo(votList, myCookie); return View(votList); }
public ActionResult ShoppingList() { ShoppingListViewModel shopListVM = new ShoppingListViewModel(); //Make Web Service Request string serviceURL = "https://api-snacks.nerderylabs.com/v1/snacks/"; var client = new RestClient(serviceURL, HttpVerb.GET); var json = client.MakeSnackRequest(""); //Parse JSON Into PRoper Payload Structure List<RestDataModel.GetSnacks> payload = JsonConvert.DeserializeObject<List<RestDataModel.GetSnacks>>(json); shopListVM.OnlineSnacksSuggested = payload.Where(x => x.optional == true); shopListVM.OnlineSnacksAlwaysPurchased = payload.Where(x => x.optional == false); shopListVM.votList = (from a in db.Votes select a).ToList(); shopListVM = ShoppingListViewLogic.OrganizeShoppingList(shopListVM); return View(shopListVM); }
public ActionResult Suggestions( [Bind(Include = "Id,SnackName,SuggestedOn,SuggestionLocation")] SuggestionsViewModel suggestion) { //Legacy Internal DB Code //Build Internal DB Object //Suggestion sug = new Suggestion(); //sug.SnackName = suggestion.SnackName; //sug.SuggestedOn = suggestion.SuggestedOn; //sug.SuggestionLocation = suggestion.SuggestionLocation; //Simple Struct For Data RestDataModel.AddSnack add = new RestDataModel.AddSnack(); add.Name = suggestion.SnackName; add.Location = suggestion.SuggestionLocation; //Package Data For Transmission var dataToSend = JsonConvert.SerializeObject(add); //Add To Web Service string serviceURL = "https://api-snacks.nerderylabs.com/v1/snacks/"; var client = new RestClient(serviceURL, HttpVerb.POST, dataToSend); var json = client.MakeSnackRequest(""); //Legacy Internal DB Code //Save TO Internal DB On Success //if (ModelState.IsValid) //{ // db.Suggestions.Add(sug); // db.SaveChanges(); // return RedirectToAction("Suggestions"); //} //return View(suggestion); return RedirectToAction("Suggestions"); }
public ActionResult Suggestions() { SuggestionsViewModel sugVM = new SuggestionsViewModel(); //LEgacy Internal DB Code //sugVM.sugList = (from a in db.Suggestions // select a).ToList(); //Make Web Service Request string serviceURL = "https://api-snacks.nerderylabs.com/v1/snacks/"; var client = new RestClient(serviceURL, HttpVerb.GET); var json = client.MakeSnackRequest(""); //Parse JSON Into PRoper Payload Structure List<RestDataModel.GetSnacks> payload = JsonConvert.DeserializeObject<List<RestDataModel.GetSnacks>>(json); //Get Suggested Snack List sugVM.OnlineSuggestedSnackList = payload.Where(x => x.optional == true); // TODO: Error Handling - Show Error Messages For Items Already Purchased Or In The List return View(sugVM); }