コード例 #1
0
        private UserPreference GetUserProfile()
        {
            var result = new UserPreference();
            result.Interests = new Collection<Interest>();
            result.Interests.Add(new Interest() { Checked = false, Name = "Archaeology" });
            result.Interests.Add(new Interest() { Checked = false, Name = "Astronomy" });
            result.Interests.Add(new Interest() { Checked = false, Name = "Cuisine" });
            result.Interests.Add(new Interest() { Checked = false, Name = "Dancing" });
            result.Interests.Add(new Interest() { Checked = false, Name = "Geography" });
            result.Interests.Add(new Interest() { Checked = false, Name = "History" });
            result.Interests.Add(new Interest() { Checked = false, Name = "Literature" });
            result.Interests.Add(new Interest() { Checked = false, Name = "Shopping" });

            result.Cuisine = new Collection<Interest>();
            result.Cuisine.Add(new Interest() { Checked = false, Name = "American" });
            result.Cuisine.Add(new Interest() { Checked = false, Name = "Asian" });
            result.Cuisine.Add(new Interest() { Checked = false, Name = "Chinese" });
            result.Cuisine.Add(new Interest() { Checked = false, Name = "French" });
            result.Cuisine.Add(new Interest() { Checked = false, Name = "Greek" });
            result.Cuisine.Add(new Interest() { Checked = false, Name = "Indian" });
            result.Cuisine.Add(new Interest() { Checked = false, Name = "Italian" });
            result.Cuisine.Add(new Interest() { Checked = false, Name = "Japanese" });
            result.Cuisine.Add(new Interest() { Checked = false, Name = "Seafood" });
            result.Cuisine.Add(new Interest() { Checked = false, Name = "Sushi" });

            return result;
        }
コード例 #2
0
        private HttpResponseMessage SaveUserPreferences(UserPreference preferences, string user)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(ConfigurationManager.AppSettings["APIurl"] + "/api/UserPreference/SaveUserPreference");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var json = new JavaScriptSerializer().Serialize(preferences);
            string urlParameters = "?user="******"&preferences=" + json.ToString();

            HttpContent content = new StringContent("");
            HttpResponseMessage response = client.PostAsync(urlParameters, content).Result;

            return response;
        }
コード例 #3
0
        public ActionResult UserPreference(UserPreference result)
        {
            result.Interests = new Collection<Interest>();
            result.SelectedInterests = result.SelectedInterests != null ? result.SelectedInterests : new Collection<string>();
            result.Interests.Add(new Interest() { Checked = result.SelectedInterests.Contains("Archaeology"), Name = "Archaeology" });
            result.Interests.Add(new Interest() { Checked = result.SelectedInterests.Contains("Astronomy"), Name = "Astronomy" });
            result.Interests.Add(new Interest() { Checked = result.SelectedInterests.Contains("Cuisine"), Name = "Cuisine" });
            result.Interests.Add(new Interest() { Checked = result.SelectedInterests.Contains("Dancing"), Name = "Dancing" });
            result.Interests.Add(new Interest() { Checked = result.SelectedInterests.Contains("Geography"), Name = "Geography" });
            result.Interests.Add(new Interest() { Checked = result.SelectedInterests.Contains("History"), Name = "History" });
            result.Interests.Add(new Interest() { Checked = result.SelectedInterests.Contains("Literature"), Name = "Literature" });
            result.Interests.Add(new Interest() { Checked = result.SelectedInterests.Contains("Shopping"), Name = "Shopping" });

            result.Cuisine = new Collection<Interest>();
            result.SelectedCuisine = result.SelectedCuisine != null ? result.SelectedCuisine : new Collection<string>();
            result.Cuisine.Add(new Interest() { Checked = result.SelectedCuisine.Contains("American"), Name = "American" });
            result.Cuisine.Add(new Interest() { Checked = result.SelectedCuisine.Contains("Asian"), Name = "Asian" });
            result.Cuisine.Add(new Interest() { Checked = result.SelectedCuisine.Contains("Chinese"), Name = "Chinese" });
            result.Cuisine.Add(new Interest() { Checked = result.SelectedCuisine.Contains("French"), Name = "French" });
            result.Cuisine.Add(new Interest() { Checked = result.SelectedCuisine.Contains("Greek"), Name = "Greek" });
            result.Cuisine.Add(new Interest() { Checked = result.SelectedCuisine.Contains("Indian"), Name = "Indian" });
            result.Cuisine.Add(new Interest() { Checked = result.SelectedCuisine.Contains("Italian"), Name = "Italian" });
            result.Cuisine.Add(new Interest() { Checked = result.SelectedCuisine.Contains("Japanese"), Name = "Japanese" });
            result.Cuisine.Add(new Interest() { Checked = result.SelectedCuisine.Contains("Seafood"), Name = "Seafood" });
            result.Cuisine.Add(new Interest() { Checked = result.SelectedCuisine.Contains("Sushi"), Name = "Sushi" });

            HttpResponseMessage response = SaveUserPreferences(result, Session["logged_username"].ToString());
            if (response.IsSuccessStatusCode)
            {
                ViewBag.result = "Data Saved Successfully!";
            }
            return View(result);
        }