public JsonResult AddProduct(Products item)
        {
            try
            {
                if (Session["iuser"] == null)
                {
                    throw new Exception(" Session หมดอายุ , กรุณาเข้าสู่ระบบใหม่อีกครั้ง !! ");
                }


                ProductData data = new ProductData();
                data.AddProduct(item);

                return(Json(new
                {
                    data = "บันทึกข้อมูลสำเร็จ",
                    success = true
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    success = false,
                    data = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
        /// <summary>
        /// Purpose: Add a new product
        /// Accepts: Nothing
        /// Returns: String (Product Code)
        /// </summary>
        public string AddProduct()
        {
            //The product code that was added to database
            string retProdcd = "";

            try
            {
                Hashtable hsh = new Hashtable();
                hsh["productcode"]         = ProductCode;
                hsh["name"]                = Name;
                hsh["brand"]               = Brand;
                hsh["description"]         = Description;
                hsh["categoryid"]          = CategoryID;
                hsh["msrp"]                = Msrp;
                hsh["isfreeshipping"]      = IsFreeShipping;
                hsh["istaxfree"]           = IsTaxFree;
                hsh["quantityinstock"]     = QuantityInStock;
                hsh["isquantityunlimited"] = IsQuantityUnlimited;
                hsh["created"]             = Created;
                hsh["modified"]            = Modified;
                hsh["isactive"]            = IsActive;

                ProductData prodData = new ProductData();
                retProdcd = prodData.AddProduct(hsh);
            }
            catch (Exception ex)
            {
                ErrorRoutine(ex, "Product", "AddProduct()");
            }

            return(retProdcd);
        }
Пример #3
0
        static void Main(string[] args)
        {
            try
            {
                IDbContext db = new MyDbContext();

                db.RecreateDatabase();

                ICategoryData           categoryData           = new CategoryData(db);
                IProductData            productData            = new ProductData(db);
                IShoppingBasketItemData shoppingBasketItemData = new ShoppingBasketItemData(db);

                Console.WriteLine("Creating database entries");

                categoryData.AddCategory(new ClassLibrary.Category {
                    CategoryId = 1, Name = "Fruits"
                });
                categoryData.AddCategory(new ClassLibrary.Category {
                    CategoryId = 2, Name = "Vegetables"
                });
                categoryData.AddCategory(new ClassLibrary.Category {
                    CategoryId = 3, Name = "Pulses"
                });

                productData.AddProduct(new ClassLibrary.Product {
                    ProductId = 1, Name = "Orange", Price = 0.45m, ImageFilePath = "https://upload.wikimedia.org/wikipedia/commons/c/c4/Orange-Fruit-Pieces.jpg", CategoryId = 1
                });
                productData.AddProduct(new ClassLibrary.Product {
                    ProductId = 2, Name = "Apple", Price = 0.35m, ImageFilePath = "https://cdn.ecommercedns.uk/files/1/231541/9/8022859/green20apple.jpg", CategoryId = 1
                });
                productData.AddProduct(new ClassLibrary.Product {
                    ProductId = 3, Name = "Banana", Price = 0.65m, ImageFilePath = "https://api.time.com/wp-content/uploads/2019/11/gettyimages-459761948.jpg?w=800&quality=85", CategoryId = 1
                });
                productData.AddProduct(new ClassLibrary.Product {
                    ProductId = 4, Name = "Cabbage", Price = 0.85m, ImageFilePath = "https://cdn-prod.medicalnewstoday.com/content/images/articles/284/284823/one-big-cabbage.jpg", CategoryId = 2
                });
                productData.AddProduct(new ClassLibrary.Product {
                    ProductId = 5, Name = "Pepper", Price = 0.40m, ImageFilePath = "http://www.lima-europe.eu/wp-content/uploads/2017/04/pepper.jpg", CategoryId = 2
                });
                productData.AddProduct(new ClassLibrary.Product {
                    ProductId = 6, Name = "Red Lentil", Price = 2.10m, ImageFilePath = "https://upload.wikimedia.org/wikipedia/commons/4/43/Split_Red_Lentil.jpg", CategoryId = 3
                });

                Console.WriteLine("Database entries created");

                foreach (var product in productData.GetProducts())
                {
                    Console.WriteLine($"ProductId={product.ProductId}\tName={product.Name}\tPrice={product.Price}\tImageFilePath={product.ImageFilePath}\tCategoryId={product.CategoryId}");
                }
                foreach (var category in categoryData.GetCategories())
                {
                    Console.WriteLine($"CategoryId={category.CategoryId}\tName={category.Name}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #4
0
 public ViewResult Create(Product newProduct)
 {
     TempData["CreateOrEdit"] = "Create";
     if (ProductData.AddProduct(newProduct))
     {
         ViewBag.Message = "Product(" + ProductData.ProductList.Count + ") added successful";
     }
     else
     {
         ViewBag.Message = "Can not add this product";
     }
     return(View());
 }
Пример #5
0
 // POST api/<controller>
 public void Post([FromBody] ProductModel product)
 {
     productData.AddProduct(product);
 }
Пример #6
0
 public bool AddProduct(Product p)
 {
     return(product.AddProduct(p));
 }
Пример #7
0
        // POST: Save New Product
        public JsonResult CreateProduct(Product pro)
        {
            var product = objproduct.AddProduct(pro);

            return(Json(product, JsonRequestBehavior.AllowGet));
        }
 public int Create(Product product)
 {
     return(objproduct.AddProduct(product));
 }
Пример #9
0
        public void OnCreateProduct()
        {
            var product = this.productView.RetrieveProduct();

            productData.AddProduct(product);
        }