public JsonResult AddProductTableRow(string sbName, string sku) { int picId = (int)Session["PicId"]; int ptid = (int)Session["SubProdId"]; int subCatId = (int)Session["SubCat"]; int mainCatId = (int)Session["MainCategory"]; int id = DataProvider.AddSubProduct(sbName, sku, picId, ptid, subCatId, mainCatId); SubProductRow sbr = new SubProductRow() { Id = id, MainCategoryId = mainCatId, Description = "", MainCategoryName = Session["MainCategoryName"].ToString(), OrderId = 0, SKU = sku, ProductPictureId = picId, ProductPictureTitle = Session["PicTitle"].ToString(), ProductTableId = ptid, SubCategoryId = subCatId, SubCategoryName = Session["SubCatName"].ToString(), SubProductName = Session["SubProdName"].ToString() }; string html = this.RenderPartialToString("Partials/_SubProductRow", sbr); return Json(new { html = html }); }
public static List<SubProductRow> GetSubProducts(int tableId, string term = null) { List<SubProductRow> subProds = new List<SubProductRow>(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[CONNECTION_STRING].ConnectionString)) { using (SqlCommand cmd = new SqlCommand("GetSubProducts", conn)) { cmd.Parameters.Add(new SqlParameter("@ProductTableId", tableId)); 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()) { SubProductRow sp = new SubProductRow(); sp.Id = reader.GetInt32(0); sp.SKU = reader.IsDBNull(1) ? string.Empty : reader.GetString(1); sp.ProductPictureTitle = reader.IsDBNull(2) ? string.Empty : reader.GetString(2); sp.ProductPictureId = reader.IsDBNull(3) ? 0 : reader.GetInt32(3); sp.SubProductName = reader.IsDBNull(4) ? string.Empty : reader.GetString(4); sp.SubCategoryName = reader.IsDBNull(5) ? string.Empty : reader.GetString(5); sp.ProductTableId = reader.IsDBNull(6) ? 0 : reader.GetInt32(6); sp.Description = reader.IsDBNull(7) ? string.Empty : reader.GetString(7); sp.SubCategoryId = reader.IsDBNull(8) ? 0 : reader.GetInt32(8); sp.MainCategoryId = reader.IsDBNull(9) ? 0 : reader.GetInt32(9); sp.MainCategoryName = reader.IsDBNull(10) ? string.Empty : reader.GetString(10); sp.OrderId = reader.IsDBNull(11) ? 0 : reader.GetInt32(11); subProds.Add(sp); } } conn.Close(); } } return subProds; }