Exemplo n.º 1
0
        /// <summary>
        /// Creates am order in the database.
        /// </summary>
        /// <param name="order"></param>
        /// <returns>string</returns>
        public string CreateOrder(Order order)
        {
            string result;

            try
            {
                using (var connection = new SqlConnection(db.GetConnectionString()))
                    using (var cmd = connection.CreateCommand())
                    {
                        connection.Open();
                        cmd.CommandText = "INSERT INTO Table_Order (price, isShipped, username) VALUES(@price, @isShipped, @username)";
                        cmd.Parameters.AddWithValue("price", order.Price);
                        cmd.Parameters.AddWithValue("isShipped", order.IsShipped);
                        cmd.Parameters.AddWithValue("username", order.Username);
                        cmd.ExecuteNonQuery();
                        connection.Close();

                        result = "Success";
                    }
            }

            catch (Exception exception)
            {
                result = OrderException(exception).Username;
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a product in the database.
        /// </summary>
        /// <param name="product"></param>
        /// <returns>string</returns>
        public string CreateProduct(Product product)
        {
            string result;

            try
            {
                if (product.Name == null || product.Price < 0.0)
                {
                    throw new ArgumentNullException("The product doesn't have any valid information");
                }

                else
                {
                    using (var connection = new SqlConnection(db.GetConnectionString()))
                        using (var cmd = connection.CreateCommand())
                        {
                            connection.Open();
                            cmd.CommandText = "INSERT INTO Table_Product (name, price) VALUES(@name, @price)";
                            cmd.Parameters.AddWithValue("name", product.Name);
                            cmd.Parameters.AddWithValue("price", product.Price);
                            cmd.ExecuteNonQuery();
                            connection.Close();

                            result = "Success";
                        }
                }
            }

            catch (Exception exception)
            {
                result = ProductException(exception).Name;
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an order detail in the database.
        /// </summary>
        /// <param name="order_detail"></param>
        /// <returns>string</returns>
        public string CreateOrderDetail(OrderDetail order_detail)
        {
            string result;

            try
            {
                using (var connection = new SqlConnection(db.GetConnectionString()))
                    using (var cmd = connection.CreateCommand())
                    {
                        connection.Open();
                        cmd.CommandText = "INSERT INTO Table_OrderDetail (orderId, productId) VALUES(@orderId, @productId)";
                        cmd.Parameters.AddWithValue("orderId", order_detail.OrderId);
                        cmd.Parameters.AddWithValue("productId", order_detail.ProductId);
                        cmd.ExecuteNonQuery();
                        connection.Close();
                    }

                result = "Success";
            }

            catch (Exception exception)
            {
                result = exception.Message;
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creas an user in the database.
        /// </summary>
        /// <param name="user"></param>
        /// <returns>string</returns>
        public string CreateUser(CustomUser user)
        {
            string result;

            try
            {
                using (var connection = new SqlConnection(db.GetConnectionString()))
                    using (var cmd = connection.CreateCommand())
                    {
                        connection.Open();
                        cmd.CommandText = "INSERT INTO Table_User (username, userPassword, email, isActive, loggedIn, wallet) VALUES(@username, @userPassword, @email, @isActive, @loggedIn, @wallet)";
                        cmd.Parameters.AddWithValue("username", user.Username);
                        cmd.Parameters.AddWithValue("userPassword", user.Password);
                        cmd.Parameters.AddWithValue("email", user.Email);
                        cmd.Parameters.AddWithValue("isActive", user.IsActive);
                        cmd.Parameters.AddWithValue("loggedIn", user.IsActive);
                        cmd.Parameters.AddWithValue("wallet", user.Wallet);
                        cmd.ExecuteNonQuery();
                        connection.Close();
                    }

                result = "Success";
            }

            catch (Exception exception)
            {
                result = exception.Message;
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a user product in the database.
        /// </summary>
        /// <param name="user_product"></param>
        /// <returns>string</returns>
        public string CreateUserProduct(UserProduct user_product)
        {
            string result;

            try
            {
                using (var connection = new SqlConnection(db.GetConnectionString()))
                    using (var cmd = connection.CreateCommand())
                    {
                        connection.Open();
                        cmd.CommandText = "INSERT INTO Table_UserProduct (username, productId, isActive) VALUES(@username, @productId, @isActive)";
                        cmd.Parameters.AddWithValue("username", user_product.Username);
                        cmd.Parameters.AddWithValue("productId", user_product.ProductId);
                        cmd.Parameters.AddWithValue("isActive", user_product.IsActive);
                        cmd.ExecuteNonQuery();
                        connection.Close();

                        result = "Success";
                    }
            }

            catch (Exception exception)
            {
                result = UserProductException(exception).Username;
            }

            return(result);
        }