/// <summary>
        /// MSCS 701-702 Topics in Math Sts, & Comp Sci
        /// Service Oriented Architecture (SOA)
        /// Spring 2019
        /// Omar Waller
        ///
        /// Description: This class contains CRUD and Get queries to the Inventory table in the Warehouse database configured
        /// in the app.config file.
        /// </summary>

        // This method creates a Inventory record in the Warehouse database and returns true if the operation was successful.
        public bool Create(DataModel.Inventory inventory, ref string msg)
        {
            using (var context = new DataModel.WarehouseContext())
            {
                // Create and save a new Products
                DataModel.Inventory newInventory = new DataModel.Inventory();
                bool success = false;

                newInventory.Product_Quantity = inventory.Product_Quantity;
                newInventory.Inventory_ID     = inventory.Inventory_ID;
                newInventory.Product_ID       = inventory.Product_ID;
                newInventory.Warehouse_ID     = inventory.Warehouse_ID;

                context.Inventories.Add(newInventory);

                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result != 1)
                {
                    msg = "Inventory not created in DB - DAL";
                }
                else
                {
                    msg     = "Inventory object successfully created.";
                    success = true;
                }

                return(success);
            }
        }
        /// <summary>
        /// MSCS 701-702 Topics in Math Sts, & Comp Sci
        /// Service Oriented Architecture (SOA)
        /// Spring 2019
        /// Omar Waller, Andrew Jacobson
        ///
        /// Description: This class contains CRUD and Get queries to the Warehouse table in the Warehouse database configured
        /// in the app.config file.
        /// </summary>

        //Given a Warehouse object, add to Warehouses table
        //Returns a boolean
        public bool Create(DataModel.Warehouse warehouse_in, ref string msg)
        {
            var ret = true;

            using (var context = new DataModel.WarehouseContext())
            {
                // Create and save a new Warehouse
                var newWarehouse = new DataModel.Warehouse();

                newWarehouse.Warehouse_Name = warehouse_in.Warehouse_Name;
                newWarehouse.Street         = warehouse_in.Street;
                newWarehouse.City           = warehouse_in.City;
                newWarehouse.State          = warehouse_in.State;
                newWarehouse.Zipcode        = warehouse_in.Zipcode;

                //Add the Warehouse
                context.Warehouses.Add(newWarehouse);

                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result != 1)
                {
                    msg = "Warehouse was not added";
                    ret = false;
                }
                else
                {
                    msg = "Warehouse added";
                }
            }

            return(ret);
        }
        // This method updates a Category record in the Warehouse database and returns true if the operation was successful.
        public bool Update_Category_By_ID(DataModel.Category category)
        {
            using (var context = new DataModel.WarehouseContext())
            {
                // Get and update Category
                bool success = false;
                var  cat     = context.Categories.SingleOrDefault(c => c.Category_ID == category.Category_ID);
                if (cat != null)
                {
                    cat.Category_Name        = category.Category_Name;
                    cat.Category_Description = category.Category_Description;

                    //Apply change
                    context.Categories.Attach(cat);
                    context.Entry(cat).State = System.Data.Entity.EntityState.Modified;
                }

                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result != 1)
                {
                    success = false;
                }

                return(success);
            }
        }
        //Given an ID, delete Warehouse from Warehouses
        //Returns a boolean
        public bool Delete_Warehouse_By_ID(int warehouse_id, ref string msg)
        {
            var ret = true;

            using (var context = new DataModel.WarehouseContext())
            {
                // Delete Warehouse from the database using warehouse ID
                var warehouse = new DataModel.Warehouse {
                    Warehouse_ID = warehouse_id
                };
                context.Warehouses.Attach(warehouse);
                context.Warehouses.Remove(warehouse);

                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result != 1)
                {
                    msg = "Warehouse was not deleted";
                    ret = false;
                }
                else
                {
                    msg = "Warehouse deleted";
                }
            }

            return(ret);
        }
Exemplo n.º 5
0
        //Given a UPC code, delete Product from Products table
        //Returns a boolean
        public bool Delete_Product_By_UPC(long product_UPC, ref string msg)
        {
            var ret = true;

            using (var context = new DataModel.WarehouseContext())
            {
                // Delete Product from the database using product UPC
                DataModel.Product product = new DataModel.Product {
                    Product_UPC = product_UPC
                };
                context.Products.Attach(product);
                context.Products.Remove(product);

                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result != 1)
                {
                    msg = "Product was not deleted";
                    ret = false;
                }
                else
                {
                    msg = "Product deleted";
                }
            }

            return(ret);
        }
Exemplo n.º 6
0
        //Given a Product object, update the Products table on Product_ID
        //Returns a boolean
        public bool Update_Product_By_Product_ID(DataModel.Product product_in)
        {
            var ret = true;

            using (var context = new DataModel.WarehouseContext())
            {
                // Get and update Product
                var product = context.Products.SingleOrDefault(p => p.Product_ID == product_in.Product_ID);
                if (product != null)
                {
                    product.Product_Name  = product_in.Product_Name;
                    product.Product_Price = product_in.Product_Price;
                    product.Product_UPC   = product_in.Product_UPC;
                    product.CategoryRefID = product_in.CategoryRefID;

                    //Apply change
                    context.Products.Attach(product);
                    context.Entry(product).State = System.Data.Entity.EntityState.Modified;

                    //Check execution of transaction - we expect 1 change to have occurred
                    var execution_result = context.SaveChanges();
                    if (execution_result != 1)
                    {
                        ret = false;
                    }
                }
                else
                {
                    ret = false;
                }
            }

            return(ret);
        }
Exemplo n.º 7
0
        /// <summary>
        /// MSCS 701-702 Topics in Math Sts, & Comp Sci
        /// Service Oriented Architecture (SOA)
        /// Spring 2019
        /// Omar Waller, Andrew Jacobson
        ///
        /// Description: This class contains queries to the Products table in the database configured in the app.config file. .

        /// </summary>

        //Given a Product object, add to Products table
        //Returns a boolean
        public bool Create(DataModel.Product product_in, ref string msg)
        {
            var ret = true;

            using (var context = new DataModel.WarehouseContext())
            {
                // Create and save a new Product
                var newProduct = new DataModel.Product();

                newProduct.Product_Name  = product_in.Product_Name;
                newProduct.Product_Price = product_in.Product_Price;
                newProduct.Product_UPC   = product_in.Product_UPC;
                newProduct.CategoryRefID = product_in.CategoryRefID;

                //Add the Product
                context.Products.Add(newProduct);

                //Check execution of transaction - we expect 1 change to have occurred
                if (context.SaveChanges() != 1)
                {
                    msg = "Issue adding product";
                    ret = false;
                }
                else
                {
                    msg = "Product created";
                }
            }

            return(ret);
        }
        //Given a Warehouse object, update the Warehouses table on Warehouse_ID
        //Returns a boolean
        public bool Update(DataModel.Warehouse warehouse_in, ref string msg)
        {
            var ret = true;

            using (var context = new DataModel.WarehouseContext())
            {
                // Get and update Warehouse
                var warehouse = context.Warehouses.First(w => w.Warehouse_ID == warehouse_in.Warehouse_ID);
                if (warehouse != null)
                {
                    warehouse.Warehouse_Name = warehouse_in.Warehouse_Name;
                    warehouse.Street         = warehouse_in.Street;
                    warehouse.City           = warehouse_in.City;
                    warehouse.State          = warehouse_in.State;
                    warehouse.Zipcode        = warehouse_in.Zipcode;

                    //Apply change
                    context.Warehouses.Attach(warehouse);
                    context.Entry(warehouse).State = System.Data.Entity.EntityState.Modified;

                    //Check execution of transaction - we expect 1 change to have occurred
                    var execution_result = context.SaveChanges();
                    if (execution_result != 1)
                    {
                        msg = "Warehouse was not updated";
                        ret = false;
                    }
                    else
                    {
                        msg = "Warehouse updated";
                    }
                }
                else
                {
                    msg = "No Warehouse found with the provided ID";
                    ret = false;
                }
            }

            return(ret);
        }
        // This method deletes a Category record in the Warehouse database and returns true if the operation was successful.
        public bool Delete_Category_By_ID(int category_id)
        {
            using (var context = new DataModel.WarehouseContext())
            {
                // Delete the category using category ID
                bool success = false;
                DataModel.Category category = new DataModel.Category {
                    Category_ID = category_id
                };
                context.Categories.Attach(category);
                context.Categories.Remove(category);


                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result != 1)
                {
                    success = false;
                }

                return(success);
            }
        }
        // This method creates a Category record in the Warehouse database and returns true if the operation was successful.
        public bool Create(DataModel.Category category)
        {
            using (var context = new DataModel.WarehouseContext())
            {
                // Create and save a new Category

                DataModel.Category newCategory = new DataModel.Category();
                bool success = false;

                newCategory.Category_Description = category.Category_Description;
                newCategory.Category_Name        = category.Category_Name;

                context.Categories.Add(newCategory);

                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result == 1)
                {
                    return(true);
                }

                return(success);
            }
        }