Esempio n. 1
0
        public JsonResult AddPictureProduct(string title, string bigImg, string smallImg, int subCatId, string subCatName, int mainCatId, string mainCatName)
        {
            int orderId;
            int id = DataProvider.AddProductPicture(title, smallImg, bigImg, subCatId, subCatName, mainCatId, mainCatName, out orderId);

            PictureProduct p = new PictureProduct()
            {
                Id = id,
                ImageName = bigImg,
                IsActive = true,
                MainCategoryId = mainCatId,
                MainCategoryName = mainCatName,
                OrderId = orderId,
                SmallImageName = smallImg,
                SubCategoryId = subCatId,
                SubCategoryName = subCatName,
                Title = title
            };

            string html = this.RenderPartialToString("Partials/_ProductPicRow", p);

            return Json(new { success = true, html = html });
        }
Esempio n. 2
0
        public static List<PictureProduct> GetPictureProducts(int? category = null, string term = null)
        {
            List<PictureProduct> products = new List<PictureProduct>();

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[CONNECTION_STRING].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("GetProductsFromManagement", conn))
                {
                    if (category.HasValue && category.Value > 0)
                        cmd.Parameters.Add(new SqlParameter("@Cat", category.Value));
                    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())
                        {
                            PictureProduct p = new PictureProduct();
                            p.Id = reader.GetInt32(0);
                            p.ImageName = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                            p.SubCategoryId = reader.GetInt32(2);
                            p.Title = reader.IsDBNull(3) ? string.Empty : reader.GetString(3);
                            p.SubCategoryName = reader.IsDBNull(4) ? string.Empty : reader.GetString(4);
                            p.SmallImageName = 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);
                            p.OrderId = reader.IsDBNull(8) ? 0 : reader.GetInt32(8);
                            p.IsActive = reader.GetBoolean(9);

                            products.Add(p);
                        }
                    }

                    conn.Close();
                }
            }

            return products;
        }