public JsonResult CreateProductFormat(int ProductID, string Size, string Color, string StockQuantity, string Image)
        {
            if (string.IsNullOrWhiteSpace(Size) || string.IsNullOrWhiteSpace(Color) ||
                string.IsNullOrWhiteSpace(StockQuantity) || string.IsNullOrWhiteSpace(Image))
            {
                return(Json("填空區不可為空白"));
            }
            else
            {
                if (Regex.Match(StockQuantity, @"^\+?[1-9][0-9]*$").Success)
                {
                    ProductFormatRepository repository    = new ProductFormatRepository();
                    ProductFormat           productFormat = new ProductFormat()
                    {
                        ProductID     = ProductID,
                        Size          = Size,
                        Color         = Color,
                        StockQuantity = int.Parse(StockQuantity),
                        Image         = Image
                    };

                    repository.Create(productFormat);
                    return(Json(""));
                }
                else
                {
                    return(Json("庫存填寫無效"));
                }
            }
        }
Example #2
0
 public void Delete(ProductFormat model, IDbConnection connection)
 {
     connection.Execute("DELETE FROM ProductFormat WHERE ProductFormatID = @ProductFormatID",
                        new
     {
         model.ProductFormatID
     });
 }
Example #3
0
 public void Update(ProductFormat model, IDbConnection connection)
 {
     connection.Execute("UPDATE ProductFormat SET Size = @Size, Color = @Color, StockQuantity = @StockQuantity, Image=@Image WHERE ProductFormatID = @ProductFormatID",
                        new
     {
         model.Size,
         model.Color,
         model.StockQuantity,
         model.Image,
         model.ProductFormatID
     });
 }
Example #4
0
 public void Create(ProductFormat model, IDbConnection connection)
 {
     connection.Execute("INSERT INTO ProductFormat VALUES ( @ProductID, @Size, @Color, @StockQuantity, @Image)",
                        new
     {
         model.ProductID,
         model.Size,
         model.Color,
         model.StockQuantity,
         model.Image
     });
 }
        public ProductFormat FindById(int ProductFormatID)
        {
            IDbConnection connection    = new SqlConnection("data source=.; database=Commerce; integrated security=true");
            var           result        = connection.Query <ProductFormat>("SELECT * FROM ProductFormat WHERE ProductFormatID = @ProductFormatID", new { ProductFormatID });
            ProductFormat productFormat = null;

            foreach (var item in result)
            {
                productFormat = item;
            }
            return(productFormat);
        }
        public void Delete(ProductFormat model)
        {
            SqlConnection connection = new SqlConnection(
                "data source=.; database=Commerce; integrated security=true");
            var sql = "DELETE FROM ProductFormat WHERE ProductFormatID = @ProductFormatID ";

            SqlCommand command = new SqlCommand(sql, connection);

            command.Parameters.AddWithValue("@ProductFormatID", model.ProductFormatID);

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        public void Delete(ProductFormat model) //刪除
        {
            SqlConnection connection = new SqlConnection(
                SqlConnectionString.ConnectionString());
            var sql = "DELETE FROM ProductFormat WHERE ProductFormatID = @ProductFormatID";

            SqlCommand command = new SqlCommand(sql, connection);

            command.Parameters.AddWithValue("@ProductFormatID", model.ProductFormatID);


            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
Example #8
0
        public ProductFormat FindById(int ProductFormatID, IDbConnection connection)
        {
            var result = connection.Query <ProductFormat>("SELECT * FROM ProductFormat WHERE ProductFormatID = @ProductFormatID",
                                                          new
            {
                ProductFormatID
            });
            ProductFormat productFormat = null;

            foreach (var item in result)
            {
                productFormat = item;
            }
            return(productFormat);
        }
        public void ProductFormat_Update()
        {
            var           repository    = new ProductFormatRepository();
            ProductFormat productFormat = new ProductFormat()
            {
                ProductFormatID = 1,
                ProductID       = 1,
                Color           = "紅色",
                Size            = "2L",
                StockQuantity   = 40
            };

            repository.Update(productFormat);
            var productFormats = repository.FindById(1);

            Assert.IsTrue(productFormats.Size == "2L");
        }
        public void Create(ProductFormat model) //新增
        {
            SqlConnection connection = new SqlConnection(
                SqlConnectionString.ConnectionString());
            var sql = "INSERT INTO ProductFormat VALUES (@ProductID, @Size, @Color,@StockQuantity,@image)";

            SqlCommand command = new SqlCommand(sql, connection);

            command.Parameters.AddWithValue("@ProductID", model.ProductID);
            command.Parameters.AddWithValue("@Size", model.Size);
            command.Parameters.AddWithValue("@Color", model.Color);
            command.Parameters.AddWithValue("@StockQuantity", model.StockQuantity);
            command.Parameters.AddWithValue("@image", model.Image);
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        public void Update(ProductFormat model)
        {
            SqlConnection connection = new SqlConnection(
                "data source=.; database=Commerce; integrated security=true");
            var sql = "UPDATE ProductFormat SET Size = @Size, Color = @Color, StockQuantity = @StockQuantity WHERE ProductFormatID = @ProductFormatID";

            SqlCommand command = new SqlCommand(sql, connection);

            command.Parameters.AddWithValue("@ProductFormatID", model.ProductFormatID);
            command.Parameters.AddWithValue("@ProductID", model.ProductID);
            command.Parameters.AddWithValue("@Size", model.Size);
            command.Parameters.AddWithValue("@Color", model.Color);
            command.Parameters.AddWithValue("@StockQuantity", model.StockQuantity);

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        public void Create(ProductFormat model)
        {
            SqlConnection connection = new SqlConnection(
                "data source=.; database=Commerce; integrated security=true");
            var sql = "INSERT INTO ProductFormat VALUES ( @ProductID, @Size, @Color, @StockQuantity)";

            SqlCommand command = new SqlCommand(sql, connection);

            command.Parameters.AddWithValue("@ProductID", model.ProductID);
            command.Parameters.AddWithValue("@Size", model.Size);
            command.Parameters.AddWithValue("@Color", model.Color);
            command.Parameters.AddWithValue("@StockQuantity", model.StockQuantity);


            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        public void Update(ProductFormat model) //修改
        {
            SqlConnection connection = new SqlConnection(
                SqlConnectionString.ConnectionString());
            var sql = "UPDATE ProductFormat SET ProductID=@ProductID, Size=@Size, Color=@Color,StockQuantity =@StockQuantity ,image=@image WHERE ProductFormatID = @ProductFormatID";

            SqlCommand command = new SqlCommand(sql, connection);

            command.Parameters.AddWithValue("@ProductFormatID", model.ProductFormatID);
            command.Parameters.AddWithValue("@ProductID", model.ProductID);
            command.Parameters.AddWithValue("@Size", model.Size);
            command.Parameters.AddWithValue("@Color", model.Color);
            command.Parameters.AddWithValue("@StockQuantity", model.StockQuantity);
            command.Parameters.AddWithValue("@image", model.Image);

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        public ProductFormat FindById(int ProductFormatID)
        {
            IDbConnection connection    = new SqlConnection(SqlConnectionString.ConnectionString());
            var           result        = connection.Query <ProductFormat>("SELECT * FROM ProductFormat WHERE ProductFormatID = @ProductFormatID", new { ProductFormatID });
            ProductFormat productFormat = null;

            foreach (var item in result)
            {
                productFormat = item;
            }
            return(productFormat);
            //SqlConnection connection = new SqlConnection(
            //    SqlConnectionString.ConnectionString());
            //var sql = "SELECT * FROM ProductFormat WHERE ProductFormatID = @ProductFormatID";

            //SqlCommand command = new SqlCommand(sql, connection);

            //command.Parameters.AddWithValue("@ProductFormatID", ProductFormatID);

            //connection.Open();

            //var reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            //ProductFormat productFormat = null;

            //while (reader.Read())
            //{
            //    productFormat = new ProductFormat();
            //    productFormat.ProductFormatID = (int)reader.GetValue(reader.GetOrdinal("ProductFormatID"));
            //    productFormat.ProductID = (int)reader.GetValue(reader.GetOrdinal("ProductID"));
            //    productFormat.Size = reader.GetValue(reader.GetOrdinal("Size")).ToString();
            //    productFormat.Color = reader.GetValue(reader.GetOrdinal("Color")).ToString();
            //    productFormat.StockQuantity = (int)reader.GetValue(reader.GetOrdinal("StockQuantity"));
            //}

            //reader.Close();

            //return productFormat;
        }