/// <summary>
    /// bindig logic
    /// </summary>
    /// <param name="controllerContext"></param>
    /// <param name="bindingContext"></param>
    /// <returns>converted object</returns>
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
      NameValueCollection RequestParameters = new NameValueCollection();

      //get parameters from RoutData
      RequestParameters = controllerContext.RouteData.Values.ToNameValueCollection();


      //MErge parameters RoutData with GET || Post parameters
      if (controllerContext.HttpContext.Request.HttpMethod == "POST")
      {
        RequestParameters = RequestParameters.Merge(controllerContext.HttpContext.Request.Form);
      }
      else if (controllerContext.HttpContext.Request.HttpMethod == "GET")
      {
        RequestParameters = RequestParameters.Merge(controllerContext.HttpContext.Request.QueryString);
      }

      //Do binding
      bindingContext = tryToSetValues(RequestParameters, bindingContext);
      ValidateModel(bindingContext);
      return bindingContext.ModelMetadata.Model;
    }
Example #2
0
 public TableUrlManager(string actionUrl, TableRequestModel requestModel, NameValueCollection routeValues)
 {
     _actionUrl = actionUrl;
     _urlParams = routeValues.Merge(requestModel);
 }
Example #3
0
        public object GetSection(string configKey)
        {
            if (configKey == "appSettings")
            {
                if (_appSettings != null)
                    return _appSettings;
            }
            else if (configKey == "connectionStrings")
            {
                if (_connectionStrings != null)
                    return _connectionStrings;
            }


            // get the section from the default location (web.config or app.config)
            object section = _clientConfigSystem.GetSection(configKey);
            

            switch (configKey)
            {
                case "appSettings":
                    if (section is NameValueCollection)
                    {
                        // create a new collection because the underlying collection is read-only
                        var cfg = new NameValueCollection((NameValueCollection)section);
                        _appSettings = cfg;
                        
                        // merge the settings from core with the local appsettings
                        _appSettings = cfg.Merge(System.Configuration.ConfigurationManager.AppSettings);
                        section = _appSettings;
                    }
                    break;

                case "connectionStrings":
                    // Cannot simply return our ConnectionStringSettingsCollection as the calling routine expects a ConnectionStringsSection result
                    ConnectionStringsSection connectionStringsSection = new ConnectionStringsSection();
                    _connectionStrings = connectionStringsSection;

                    // create a new collection because the underlying collection is read-only
                    var cssc = new ConnectionStringSettingsCollection();

                    // copy the existing connection strings into the new collection
                    foreach (ConnectionStringSettings connectionStringSetting in ((ConnectionStringsSection)section).ConnectionStrings)
                    {
                        cssc.Add(connectionStringSetting);
                    }

                    //// merge the settings from core with the local connectionStrings
                    cssc = cssc.Merge(System.Configuration.ConfigurationManager.ConnectionStrings);
                    
                    // Add our merged connection strings to the new ConnectionStringsSection
                    foreach (ConnectionStringSettings connectionStringSetting in cssc)
                    {
                        connectionStringsSection.ConnectionStrings.Add(connectionStringSetting);
                    }

                    _connectionStrings = connectionStringsSection;
                    section = _connectionStrings;
                    break;
            }

            return section;
        }