private static RecordsStats GetRecordsStatsFromDataRow(DataRow dr)
        {
            var stats = new RecordsStats();

            stats.RecordFirst  = dr["RecordFirst"].ToInt();
            stats.RecordLast   = dr["RecordLast"].ToInt();
            stats.RecordsTotal = dr["RecordsTotal"].ToInt();
            stats.RecordCount  = dr["recordCount"].ToInt();
            return(stats);
        }
Beispiel #2
0
        public LoggingModel GetApplicationLogs(String appName, String logLevel, int top, int skip, String search = "")
        {
            var result = new LoggingModel();

            // Create a SQL command to execute the sproc
            using (SqlCommand command = (SqlCommand)StoreDbContext.Database.Connection.CreateCommand())
            {
                command.CommandTimeout = StoreConstants.StoreProcedureCommandTimeOut;
                command.CommandType    = CommandType.StoredProcedure;
                command.CommandText    = "log_GetApplicationLogs";
                if (!String.IsNullOrEmpty(appName.Trim()))
                {
                    command.Parameters.Add("AppName", SqlDbType.NVarChar).Value = appName;
                }
                else
                {
                    command.Parameters.Add("AppName", SqlDbType.NVarChar).Value = DBNull.Value;
                }

                if (!String.IsNullOrEmpty(search.Trim()))
                {
                    command.Parameters.Add("search", SqlDbType.NVarChar).Value = search;
                }
                else
                {
                    command.Parameters.Add("search", SqlDbType.NVarChar).Value = DBNull.Value;
                }

                if (!String.IsNullOrEmpty(logLevel.Trim()))
                {
                    command.Parameters.Add("logLevel", SqlDbType.NVarChar).Value = logLevel;
                }
                else
                {
                    command.Parameters.Add("logLevel", SqlDbType.NVarChar).Value = DBNull.Value;
                }

                command.Parameters.Add("top", SqlDbType.Int).Value  = top;
                command.Parameters.Add("skip", SqlDbType.Int).Value = skip;


                using (SqlDataAdapter adapter = new SqlDataAdapter())
                {
                    adapter.SelectCommand = command;

                    using (DataSet dataset = new DataSet())
                    {
                        adapter.Fill(dataset);

                        var systemLoggingList = new List <system_logging>();
                        using (DataTable dt = dataset.Tables[0])
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                var systemLogging = new system_logging();
                                systemLogging.entered_date    = dr["entered_date"].ToDateTime();
                                systemLogging.log_application = dr["log_application"].ToStr();
                                systemLogging.log_date        = dr["log_date"].ToStr();
                                systemLogging.log_level       = dr["log_level"].ToStr();
                                systemLogging.log_logger      = dr["log_logger"].ToStr();
                                systemLogging.log_message     = dr["log_message"].ToStr();
                                systemLogging.log_call_site   = dr["log_call_site"].ToStr();
                                systemLogging.log_exception   = dr["log_exception"].ToStr();
                                systemLogging.log_stacktrace  = dr["log_stacktrace"].ToStr();
                                systemLoggingList.Add(systemLogging);
                            }
                        }

                        result.SystemLoggingList = systemLoggingList;

                        RecordsStats stats = new RecordsStats();
                        using (DataTable dt = dataset.Tables[1])
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                stats.RecordFirst  = dr["RecordFirst"].ToInt();
                                stats.RecordLast   = dr["RecordLast"].ToInt();
                                stats.RecordsTotal = dr["RecordsTotal"].ToInt();
                                stats.RecordCount  = dr["recordCount"].ToInt();
                            }
                        }
                        result.RecordsStats = stats;
                    } // dataset
                }     //dataAdapter
            }         //command

            return(result);
        }
        private ProductsSearchResult GetProductsSearchResult(
            int storeId,
            string search,
            List <Filter> filters,
            int top,
            int skip,
            Boolean isAdmin = false, string categoryApiId = "women")
        {
            var searchResult = new ProductsSearchResult();

            String commandText   = @"SearchProducts";
            var    commandType   = CommandType.StoredProcedure;
            var    parameterList = new List <SqlParameter>();
            var    dtFilters     = new DataTable("med_tpt_Filter");

            dtFilters.Columns.Add("FieldName");
            dtFilters.Columns.Add("ValueFirst");
            dtFilters.Columns.Add("ValueLast");

            if (filters != null && filters.Any())
            {
                foreach (var filter in filters)
                {
                    DataRow dr = dtFilters.NewRow();
                    dr["FieldName"]  = filter.FieldName;
                    dr["ValueFirst"] = filter.ValueFirst;
                    dr["ValueLast"]  = filter.ValueLast;
                    dtFilters.Rows.Add(dr);
                }
            }

            parameterList.Add(DatabaseUtility.GetSqlParameter("IsAdmin", isAdmin, SqlDbType.Bit));
            parameterList.Add(DatabaseUtility.GetSqlParameter("storeId", storeId, SqlDbType.Int));
            parameterList.Add(DatabaseUtility.GetSqlParameter("search", search.ToStr(), SqlDbType.NVarChar));
            parameterList.Add(DatabaseUtility.GetSqlParameter("ApiCategoryId", categoryApiId.ToStr(), SqlDbType.NVarChar));
            parameterList.Add(DatabaseUtility.GetSqlParameter("filter", dtFilters, SqlDbType.Structured));
            parameterList.Add(DatabaseUtility.GetSqlParameter("top", top, SqlDbType.Int));
            parameterList.Add(DatabaseUtility.GetSqlParameter("skip", skip, SqlDbType.Int));
            DatabaseUtility.SqlCommandTimeout = StoreConstants.StoreProcedureCommandTimeOut;
            DataSet dataSet = DatabaseUtility.ExecuteDataSet((SqlConnection)StoreDbContext.Database.Connection, commandText, commandType, parameterList.ToArray());

            if (dataSet.Tables.Count > 0)
            {
                var productCategories = new List <ProductCategory>();
                using (DataTable dt = dataSet.Tables[0])
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var item = GetProductCategoriesFromDataRow(dr);
                        productCategories.Add(item);
                    }
                    ;
                }
                searchResult.ProductCategories = productCategories;


                var fileManagerList = new List <FileManager>();
                using (DataTable dt = dataSet.Tables[3])
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var item = GetFileManagerFromDataRow(dr);
                        fileManagerList.Add(item);
                    }
                    ;
                }

                var productFiles = new List <ProductFile>();
                using (DataTable dt = dataSet.Tables[2])
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var item = GetProductFilesFromDataRow(dr);
                        productFiles.Add(item);
                        item.FileManager = fileManagerList.FirstOrDefault(r => r.Id == item.FileManagerId);
                    }
                    ;
                }


                var products = new List <Product>();
                using (DataTable dt = dataSet.Tables[1])
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var item = GetProductsFromDataRow(dr);
                        products.Add(item);
                        item.ProductFiles = productFiles.Where(r => r.ProductId == item.Id).ToList();
                    }
                    ;
                }
                searchResult.Products = products;

                using (DataTable dt = dataSet.Tables[4])
                {
                    var m = new List <Filter>();
                    foreach (DataRow dr in dt.Rows)
                    {
                        var item = GetFilterFromDataRow(dr);
                        item.OwnerType = ProductsItem;
                        m.Add(item);
                    }
                    searchResult.Filters = m;
                }
                using (DataTable dt = dataSet.Tables[5])
                {
                    var stats = new RecordsStats();
                    foreach (DataRow dr in dt.Rows)
                    {
                        stats           = GetRecordsStatsFromDataRow(dr);
                        stats.OwnerType = ProductsItem;
                    }
                    searchResult.Stats = stats;
                }
            }
            searchResult.PageSize = top;
            return(searchResult);
        }