Esempio n. 1
0
        public static NsgaLog GetLog(this TempDataDictionary tempData)
        {
            if (tempData.ContainsKey(LogKey))
            {
                return(tempData.Peek(LogKey) as NsgaLog);
            }

            var log = new NsgaLog();

            tempData[LogKey] = log;

            return(tempData.Peek(LogKey) as NsgaLog);
        }
Esempio n. 2
0
        public static SettingsViewModel GetSettings(this TempDataDictionary tempData)
        {
            if (tempData.ContainsKey(SettingsKey))
            {
                return(tempData.Peek(SettingsKey) as SettingsViewModel);
            }

            var configurationProvider = new ConfigurationProvider();
            var settingsViewModel     = new SettingsViewModel {
                NsgaConfiguration = configurationProvider.GetConfiguration()
            };

            tempData.SaveSettings(settingsViewModel);
            return(tempData.Peek(SettingsKey) as SettingsViewModel);
        }
Esempio n. 3
0
        public static List <PersonalData> GetPersonalDataList(this TempDataDictionary tempData)
        {
            if (!tempData.ContainsKey(PersonalDataListKey))
            {
                tempData[PersonalDataListKey] = new List <PersonalData>
                {
                    new PersonalData
                    {
                        Name   = "Johny",
                        Age    = 25,
                        Gender = Gender.M,
                        Height = 185,
                        Weight = 85,
                        Pal    = 1.5,
                        Id     = 0,
                    },
                    new PersonalData
                    {
                        Name   = "Anna",
                        Age    = 22,
                        Gender = Gender.K,
                        Height = 160,
                        Weight = 50,
                        Pal    = 1.8,
                        Id     = 1
                    }
                };
            }

            return(tempData.Peek(PersonalDataListKey) as List <PersonalData>);
        }
Esempio n. 4
0
        public static Uri GetSignUpUrl(ulong appId, IList <string> permissions, string redirectUri, TempDataDictionary tempData)
        {
            if (permissions == null)
            {
                throw new ArgumentNullException("permissions", "Value cannot be null.");
            }
            if (appId < 1)
            {
                throw new ArgumentOutOfRangeException("appId", "Value cannot be less than 1.");
            }
            if (redirectUri.IsNullOrEmpty())
            {
                throw new ArgumentNullException("redirecturi", "Value cannot be Null or Empty.");
            }

            tempData[TempDataStringResuorce.FacebookStateData] = Guid.NewGuid().ToString("x");
            var queryparameters = new Dictionary <string, object>
            {
                { "client_id", appId },
                { "redirect_uri", redirectUri },
                { "scope", permissions.ToString(',') },
                { "state", CryptographyHelper.GetOneTimeHash(tempData.Peek(TempDataStringResuorce.FacebookStateData).ToString()) }
            };
            var uribuilder = new UriBuilder
            {
                Scheme = "https",
                Host   = "www.facebook.com",
                Path   = "dialog/oauth",
                Query  = queryparameters.ToUriQueryString(false)
            };
            var result = uribuilder.Uri;

            return(result);
        }
Esempio n. 5
0
        public static IList <AlertModel> Alerts(this TempDataDictionary tempData, bool keep = false)
        {
            if (tempData == null)
            {
                throw new ArgumentNullException("tempData");
            }
            var alerts = keep ? tempData.Peek(AlertKey) as IList <AlertModel> : tempData[AlertKey] as IList <AlertModel>;

            return(alerts);
        }
Esempio n. 6
0
    public void TempData_Peek_DoesNotMarkKeyForDeletion()
    {
        // Arrange
        var tempData = new TempDataDictionary(new DefaultHttpContext(), new NullTempDataProvider());

        tempData["Bar"] = "barValue";

        // Act
        var value = tempData.Peek("bar");

        tempData.Save();

        // Assert
        Assert.Equal("barValue", value);
        Assert.True(tempData.ContainsKey("Bar"));
    }
Esempio n. 7
0
        public static PersonalData GetPersonalData(this TempDataDictionary tempData)
        {
            if (!tempData.ContainsKey(PersonalDataKey))
            {
                tempData[PersonalDataKey] = new PersonalData
                {
                    Name   = "Stefan",
                    Age    = 25,
                    Gender = Gender.M,
                    Height = 185,
                    Weight = 85,
                    Pal    = 1.5
                };
            }

            return(tempData.Peek(PersonalDataKey) as PersonalData);
        }
        public void PeekDoesNotMarkKeyAsRead()
        {
            // Arrange
            NullTempDataProvider     provider          = new NullTempDataProvider();
            TempDataDictionary       tempData          = new TempDataDictionary();
            Mock <ControllerContext> controllerContext = new Mock <ControllerContext>();

            tempData["Bar"] = "barValue";

            // Act
            object value = tempData.Peek("bar");

            tempData.Save(controllerContext.Object, provider);

            // Assert
            Assert.Equal("barValue", value);
            Assert.True(tempData.ContainsKey("Bar"));
        }
Esempio n. 9
0
        public void PeekDoesNotMarkKeyAsRead()
        {
            // Arrange
            NullTempDataProvider     provider          = new NullTempDataProvider();
            TempDataDictionary       tempData          = new TempDataDictionary();
            Mock <ControllerContext> controllerContext = new Mock <ControllerContext>();

            tempData["Bar"] = "barValue";

            // Act
            object value = tempData.Peek("bar");

            tempData.Save(controllerContext.Object, provider);

            // Assert
            Assert.AreEqual("barValue", value, "Incorrect value read from Peek().");
            Assert.IsTrue(tempData.ContainsKey("Bar"), "Peek() shouldn't have removed 'Bar' from TempData.");
        }
Esempio n. 10
0
        public void TempData_Peek_DoesNotMarkKeyForDeletion()
        {
            // Arrange
            var tempData = new TempDataDictionary(GetHttpContextAccessor(), new NullTempDataProvider());
            tempData["Bar"] = "barValue";

            // Act
            var value = tempData.Peek("bar");
            tempData.Save();

            // Assert
            Assert.Equal("barValue", value);
            Assert.True(tempData.ContainsKey("Bar"));
        }
Esempio n. 11
0
        public void PeekDoesNotMarkKeyAsRead() {
            // Arrange
            NullTempDataProvider provider = new NullTempDataProvider();
            TempDataDictionary tempData = new TempDataDictionary();
            Mock<ControllerContext> controllerContext = new Mock<ControllerContext>();
            tempData["Bar"] = "barValue";

            // Act
            object value = tempData.Peek("bar");
            tempData.Save(controllerContext.Object, provider);

            // Assert
            Assert.AreEqual("barValue", value, "Incorrect value read from Peek().");
            Assert.IsTrue(tempData.ContainsKey("Bar"), "Peek() shouldn't have removed 'Bar' from TempData.");
        }
        public void PeekDoesNotMarkKeyAsRead()
        {
            // Arrange
            NullTempDataProvider provider = new NullTempDataProvider();
            TempDataDictionary tempData = new TempDataDictionary();
            Mock<ControllerContext> controllerContext = new Mock<ControllerContext>();
            tempData["Bar"] = "barValue";

            // Act
            object value = tempData.Peek("bar");
            tempData.Save(controllerContext.Object, provider);

            // Assert
            Assert.Equal("barValue", value);
            Assert.True(tempData.ContainsKey("Bar"));
        }
Esempio n. 13
0
 public static DailyDietsResultViewModel GetDailyDietsResultViewModel(this TempDataDictionary tempData)
 {
     return(tempData.ContainsKey(DailyDietsResultViewModeltKey) ? tempData.Peek(DailyDietsResultViewModeltKey) as DailyDietsResultViewModel : null);
 }
Esempio n. 14
0
 public static WeightsModel GetPreferencePointModel(this TempDataDictionary tempData, int personId)
 {
     return(tempData.ContainsKey(PrefPointKey + personId) ? tempData.Peek(PrefPointKey + personId) as WeightsModel : new WeightsModel());
 }
Esempio n. 15
0
 public static AhpModel GetAhpModel(this TempDataDictionary tempData, int personId)
 {
     return(tempData.ContainsKey(AhpKey + personId) ? tempData.Peek(AhpKey + personId) as AhpModel : new AhpModel());
 }
Esempio n. 16
0
 public static GroupDietsResultViewModel GetGroupDietsResultViewModel(this TempDataDictionary tempData)
 {
     return(tempData.ContainsKey(GroupDietsResultViewModeltKey) ? tempData.Peek(GroupDietsResultViewModeltKey) as GroupDietsResultViewModel : null);
 }
Esempio n. 17
0
 public static NsgaResult GetNsgaResult(this TempDataDictionary tempData)
 {
     return(tempData.ContainsKey(NsgaResultKey) ? tempData.Peek(NsgaResultKey) as NsgaResult : null);
 }
Esempio n. 18
0
 public static PreferencesViewModel GetPreferencesViewModel(this TempDataDictionary tempData, int personId)
 {
     return(tempData.ContainsKey(PreferencesKey + personId) ? tempData.Peek(PreferencesKey + personId) as PreferencesViewModel : InitializePreferencesViewModel());
 }
Esempio n. 19
0
 public static PreferencesViewModel GetPreferencesViewModel(this TempDataDictionary tempData)
 {
     return(tempData.ContainsKey(PreferencesKey) ? tempData.Peek(PreferencesKey) as PreferencesViewModel : null);
 }