Esempio n. 1
0
        public ActionResult Index(ProviderListFiltersModel filters)
        {
            int pageTotal;

            var providers = _providerService.GetAll("CreatedDate", "DESC", filters.Criteria, filters.Page, DefaultPageSize, out pageTotal);

            var pagedList = new StaticPagedList <ProviderDto>(providers, filters.Page, DefaultPageSize, pageTotal);

            var listModel = new ProviderListModel(pagedList, filters);

            return(View(listModel));
        }
        public ActionResult Index(ProviderListFiltersModel filters)
        {
            int pageTotal;

            var providers = _providerService.GetAll("CreatedDate", "DESC", filters.Criteria, filters.Page, DefaultPageSize, out pageTotal);

            var pagedList = new StaticPagedList<ProviderDto>(providers, filters.Page, DefaultPageSize, pageTotal);

            var listModel = new ProviderListModel(pagedList, filters);

            return View(listModel);
        }
        //private IEnumerable<dynamic> dbGetProviderList(ref int totalRecordCount )
        private dynamic dbGetProviderList(ref int totalRecordCount)
        {
            bool   initGrid   = Request.Query["type"].ToString() == "initGrid" ? true : false;
            bool   exportGrid = Request.Query["type"].ToString() == "exportGrid" ? true : false;
            string remoteIP   = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP    = this.HttpContext.Connection.LocalIpAddress.ToString();

            List <dynamic>  rows            = new List <dynamic>();
            GIGridInitModel giGridInitModel = new GIGridInitModel()
            {
                ColumnList = new List <GIGridColumn>()
            };

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_GetProviderList]";
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);

                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        if (Request != null && Request.Query != null && Request.Query.Keys != null && Request.Query.Keys.Count > 0)
                        {
                            foreach (string key in Request.Query.Keys)
                            {
                                if (!key.StartsWith("_"))
                                {
                                    string param = $"@{key}";
                                    sqlCommand.Parameters.AddWithValue(param, Request.Query[key].ToString());
                                }
                            }
                        }
                        ;

                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            while (recordSet.Read())
                            {
                                dynamic model = null;
                                if (initGrid == true)
                                {
                                    model = new GIGridColumn();
                                }
                                else
                                {
                                    model = new ProviderListModel();
                                }

                                var properties = model.GetType().GetProperties();
                                foreach (var el in properties)
                                {
                                    string name = el.Name;
                                    value = recordSet[recordSet.GetOrdinal(name)];
                                    if (value != System.DBNull.Value)
                                    {
                                        switch (el.PropertyType.Name)
                                        {
                                        case "Int32":
                                            el.SetValue(model, (int)value);
                                            break;

                                        case "String":
                                            el.SetValue(model, (string)value);
                                            break;

                                        case "Boolean":
                                            el.SetValue(model, (bool)value);
                                            break;

                                        case "Decimal":
                                            el.SetValue(model, (decimal)value);
                                            break;

                                        case "DateTime":
                                            el.SetValue(model, (DateTime)value);
                                            break;
                                        }
                                    }
                                }

                                if (initGrid == true)
                                {
                                    giGridInitModel.ColumnList.Add(model);
                                }
                                else
                                {
                                    rows.Add(model);
                                }
                            }

                            if (initGrid == true && recordSet.NextResult() && recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("Title")]) != System.DBNull.Value)
                                {
                                    giGridInitModel.Title = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Toolbar")]) != System.DBNull.Value)
                                {
                                    giGridInitModel.Toolbar = (string)value;
                                }
                            }

                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                            {
                                totalRecordCount = (int)outputValue.Value;
                            }
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            if (initGrid == false)
            {
                return(rows);
            }
            return(giGridInitModel);
        }