コード例 #1
0
        public ActionResult SubscriptionEdit(UserSubscription userSubscription)
        {
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(Request["CountryCode"]))
                {
                    //TEMP fix country id passed as ISO
                    var country = new ReferenceDataManager().GetCountryByISO(Request["CountryCode"]);
                    userSubscription.CountryID = country.ID;
                }
                else
                {
                    userSubscription.Country = null;
                    userSubscription.CountryID = null;
                }
                userSubscription = new UserSubscriptionManager().UpdateUserSubscription(userSubscription);
                return RedirectToAction("Subscriptions", "Profile");
            }

            PopulateSubscriptionEditorViewBag(userSubscription);
            return View(userSubscription);
        }
コード例 #2
0
        private void PopulateSubscriptionEditorViewBag(UserSubscription subscription)
        {
            var refDataManager = new ReferenceDataManager();
            var coreRefData = refDataManager.GetCoreReferenceData();

            var allCountries = coreRefData.Countries;

            allCountries.Insert(0, new Country { ID = 0, ISOCode = "", Title = "(All Countries)" });

            ViewBag.CountryList = new SelectList(allCountries, "ISOCode", "Title", (subscription.Country != null ? subscription.Country.ISOCode : null));

            var NotificationFrequencyOptions = new[]{
                new { ID = 5, Title = "Every 5 Minutes"},
                new { ID = 30, Title = "Every 30 Minutes"},
                new { ID = 60, Title = "Every Hour"},
                new { ID = 60*12, Title = "Every 12 Hours"},
                new { ID = 60*24, Title = "Every Day"},
                new { ID = 60*24*7, Title = "Every Week"},
                new { ID = 60*24*7*31, Title = "Every Month"},
            };

            ViewBag.NotificationFrequencyOptions = new SelectList(NotificationFrequencyOptions, "ID", "Title", subscription.NotificationFrequencyMins);

            //var matchingItems = new UserSubscriptionManager().GetAllSubscriptionMatches();
            //ViewBag.MatchingItems = matchingItems;

            ViewBag.CountryExtendedInfo = JsonConvert.SerializeObject(OCM.Core.Data.CacheManager.GetExtendedCountryInfo());

            if (subscription.FilterSettings == null) subscription.FilterSettings = new UserSubscriptionFilter();
            ViewBag.OperatorList = new MultiSelectList(refDataManager.GetOperators(subscription.CountryID), "ID", "Title", subscription.FilterSettings.OperatorIDs);
            ViewBag.LevelList = new MultiSelectList(coreRefData.ChargerTypes, "ID", "Title", subscription.FilterSettings.LevelIDs);
            ViewBag.ConnectionTypeList = new MultiSelectList(coreRefData.ConnectionTypes, "ID", "Title", subscription.FilterSettings.ConnectionTypeIDs);
            ViewBag.StatusTypeList = new MultiSelectList(coreRefData.StatusTypes, "ID", "Title", subscription.FilterSettings.StatusTypeIDs);
            ViewBag.UsageTypeList = new MultiSelectList(coreRefData.UsageTypes, "ID", "Title", subscription.FilterSettings.UsageTypeIDs);
        }
コード例 #3
0
        public ActionResult SubscriptionEdit(int? id)
        {
            var subscription = new UserSubscription();
            var userId = int.Parse(Session["UserID"].ToString());
            if (id != null)
            {
                subscription = new UserSubscriptionManager().GetUserSubscription(userId, (int)id);
            }
            else
            {
                LocationLookupResult locationGuess = PerformLocationGuess(true);

                subscription.UserID = userId;
                subscription.NotificationFrequencyMins = 60 * 24 * 7;//default to 1 week
                subscription.DistanceKM = 100;

                if (locationGuess != null && locationGuess.Country_Code != null)
                {
                    subscription.CountryID = locationGuess.CountryID;
                    subscription.Country = new Country { ID = (int)locationGuess.CountryID, Title = locationGuess.Country_Name, ISOCode = locationGuess.Country_Code };
                }
                else
                {
                    //default to UK
                    subscription.CountryID = 1;
                    subscription.Country = new ReferenceDataManager().GetCountryByISO("GB");
                }
                subscription.Latitude = null;
                subscription.Longitude = null;
                subscription.IsEnabled = true;
                subscription.NotifyComments = true;
                subscription.NotifyPOIAdditions = true;
                subscription.NotifyPOIUpdates = true;

                if (locationGuess != null && locationGuess.SuccessfulLookup)
                {
                    if (locationGuess.CountryID != null) subscription.CountryID = locationGuess.CountryID;
                    if (locationGuess.Latitude != null && locationGuess.Longitude != null)
                    {
                        subscription.Latitude = locationGuess.Latitude;
                        subscription.Longitude = locationGuess.Longitude;
                    }
                }

                subscription.Title = "Charging Locations Near Me";
            }

            PopulateSubscriptionEditorViewBag(subscription);
            return View("SubscriptionEdit", subscription);
        }