Esempio n. 1
0
        public JsonResult AddSubProductTable(string tableName, int picId, int? subCatId)
        {
            int id = DataProvider.AddSubProductTable(subCatId, picId, tableName);
            ProductTable table = new ProductTable()
            {
                Id = id,
                PictureId = picId,
                Title = tableName,
                PictureName = Session["PicTitle"].ToString()
            };

            string html = this.RenderPartialToString("Partials/_ProductTableRow", table);
            return Json(new { html = html });
        }
Esempio n. 2
0
        public static List<ProductTable> GetProductTables(int picId, string term = null)
        {
            List<ProductTable> tables = new List<ProductTable>();

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[CONNECTION_STRING].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("GetProductTables", conn))
                {
                    cmd.Parameters.Add(new SqlParameter("@PicId", picId));
                    if (!string.IsNullOrWhiteSpace(term))
                        cmd.Parameters.Add(new SqlParameter("@Term", term));

                    cmd.CommandType = CommandType.StoredProcedure;
                    conn.Open();

                    using (IDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            ProductTable p = new ProductTable();
                            p.Id = reader.GetInt32(0);
                            p.Title = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                            p.PictureId = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                            p.PictureName = reader.IsDBNull(3) ? string.Empty : reader.GetString(3);
                            p.SubCategoryId = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                            p.SubCategoryName = reader.IsDBNull(5) ? string.Empty : reader.GetString(5);
                            p.MainCategoryId = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
                            p.MainCategoryName = reader.IsDBNull(7) ? string.Empty : reader.GetString(7);
                            tables.Add(p);
                        }
                    }

                    conn.Close();
                }
            }

            return tables;
        }