public static List <SupplierAndWarehoseModel> SelectWarehouse()
 {
     try
     {
         var list = new List <SupplierAndWarehoseModel>();
         using (var clint = new WarehouseClient())
         {
             var reuslt    = clint.QueryAllWarehouses(new QueryAllWarehousesRequest());
             var warehouse = reuslt.Result;
             warehouse.Warehouses.ForEach(r =>
             {
                 list.Add(new SupplierAndWarehoseModel()
                 {
                     WarehouseId   = r.LocationId,
                     WarehouseName = r.Location
                 });
             });
         }
         return(list);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
        /*
         * CheckAllWarehouses Method
         * This method will retrieve all Warehouses in the DB and display it on the text box
         */
        private string CheckAllWarehouses()
        {
            // warehouse = new Warehouse();
            var client = new WarehouseClient();
            var result = "";

            try
            {
                var alwhs = client.GetAllWarehouses();
                var sb    = new StringBuilder();
                sb.Append("*** List of all Warehouses in the DB ***");
                sb.Append("\r\n");
                foreach (var Warehouse in alwhs)
                {
                    sb.Append("ID# " + Warehouse.WarehouseID + " ");
                    sb.Append("Name: " + Warehouse.WarehouseName);
                    sb.Append("\r\n");
                }


                result = sb.ToString();
            }
            catch (Exception ex)
            {
                result = "Exception: " + ex.Message.ToString();
            }

            return(result);
        }
        /*
         * UpdateWarehouse Method
         * This method will allow the user to update address information
         * of the warehouse specified by the user.
         */
        private string UpdateWarehouse()
        {
            Warehouse warehouse = new Warehouse();
            var       client    = new WarehouseClient();
            var       result    = "";
            var       message   = "";

            try
            {
                int warehouseID = Int32.Parse(whidbox.Text);
                warehouse = client.GetWarehouse(warehouseID);


                //Move text field values to object properties



                //var upwh = (Warehouse)client.GetWarehouse(warehouseID);

                bool updateWh = client.UpdateWarehouse(warehouse, ref message);

                warehouse.WarehouseAddressStreet  = newstreetbox.Text;
                warehouse.WarehouseAddressCity    = newcitybox.Text;
                warehouse.WarehouseAddressState   = newstatebox.Text;
                warehouse.WarehouseAddressZipcode = newzipcodebox.Text;

                client.UpdateWarehouse(warehouse, ref message);


                var sb = new StringBuilder();
                if (updateWh == true)
                {
                    sb.Append("***Updating was successfull***");
                    sb.Append("\n");
                    sb.Append("WarehouseID:" + warehouse.WarehouseID);
                    sb.Append("\n");
                    sb.Append("WarehouseName:" + warehouse.WarehouseName);
                    sb.Append("\n");
                    sb.Append("WarehouseNewStreet:" + warehouse.WarehouseAddressStreet);
                    sb.Append("\n");
                    sb.Append("WarehouseNewCity:" + warehouse.WarehouseAddressCity);
                    sb.Append("\n");
                    sb.Append("WarehouseNewState:" + warehouse.WarehouseAddressState);
                    sb.Append("\n");
                    sb.Append("WarehouseNewZipcode:" + warehouse.WarehouseAddressZipcode);
                    sb.Append("\n");
                }
                else
                {
                    sb.Append("***Updating warehouse failed***");
                }
                result = sb.ToString();
            }
            catch (Exception ex)
            {
                result = "Exception: " + ex.Message;
            }
            return(result);
        }
Beispiel #4
0
        private static async Task <List <Product> > GetAllProductsAsync(WarehouseClient warehouseClient)
        {
            var initialProductResponse = await warehouseClient.GetAllProductsAsync();

            initialProductResponse.EnsureSuccessStatusCode();
            var initialProducts = await initialProductResponse.Content.ReadAsAsync <List <Product> >();

            return(initialProducts);
        }
Beispiel #5
0
        public async Task Health_Get_ReturnsOk()
        {
            // Arrange
            var warehouseClient = new WarehouseClient(Configuration, Logger);

            // Act
            var response = await warehouseClient.GetHealthAsync();

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        private void Submit_Click(object sender, EventArgs e)
        {
            Inventory inventory = new Inventory();
            var       client    = new Inventory_ServiceClient();
            var       message   = "";
            var       result    = "";

            //Check if the user searched for a product and that the UPC box is populated and that the UPC is different from the existing product
            if (upc_product == null)
            {
                result = "Search for a product first!";
            }
            else if (string.IsNullOrEmpty(whnamebox.Text))
            {
                result = "Enter a Warehouse Name!";
            }
            else if (string.IsNullOrEmpty(qtybox.Text))
            {
                result = "Enter a Quantity!";
            }
            else
            {
                try
                {
                    var       whclient        = new WarehouseClient();
                    string    whname          = whnamebox.Text;
                    Warehouse warehousebyname = whclient.GetWarehouseByName(whname);

                    //move text field value to object properties
                    inventory.Product_ID       = upc_product.ProductID;
                    inventory.Product_Quantity = int.Parse(qtybox.Text);
                    inventory.Warehouse_ID     = warehousebyname.WarehouseID;

                    //call service mrthod
                    client.Create_Inventory(inventory, ref message);
                    //Check result of update
                    var sb = new StringBuilder();
                    sb.Append("New Inventory is created successfully" + "\r\n");
                    sb.Append("Product Name: " + upc_product.ProductName + "\r\n");
                    sb.Append("Warehouse Name: " + warehousebyname.WarehouseID + "\r\n");
                    sb.Append("Quantity: " + inventory.Product_Quantity + "\r\n");

                    result = sb.ToString();
                }
                catch (Exception ex)
                {
                    result = "Exception: " + ex.Message.ToString();
                }
            }

            inboundhistory.Text = result;
        }
Beispiel #7
0
        public async Task Products_AddNewProductWithConflictingName_ReturnsConflict()
        {
            // Arrange
            var warehouseClient = new WarehouseClient(Configuration, Logger);
            var initialProducts = await GetAllProductsAsync(warehouseClient);

            Assert.True(initialProducts.Any());

            // Act
            var response = await warehouseClient.NewProductAsync(initialProducts.First());

            // Assert
            Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
        }
Beispiel #8
0
        public async Task Products_GetAll_ReturnsOk()
        {
            // Arrange
            var warehouseClient = new WarehouseClient(Configuration, Logger);

            // Act
            var response = await warehouseClient.GetAllProductsAsync();

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var products = response.Content.ReadAsAsync <List <Product> >();

            Assert.NotNull(products);
        }
        // Try to make use of "MessageBox.show("Warehouse was add to the Database successfully"); message if true OR faild otherwise"
        private void btncreatewh_Click(object sender, EventArgs e)
        {
            //allwhbox.Text = CreateNewWarehouse(
            //    warehousenamebox,
            //    streetbox,
            //    citybox,
            //    statebox,
            //    zipcodebox,
            //    ref warehouse);

            Warehouse warehouse = new Warehouse();
            var       client    = new WarehouseClient();
            var       message   = "";
            var       result    = "";

            try
            {
                //Move text field values to object properties
                warehouse.WarehouseName           = warehousenamebox.Text;
                warehouse.WarehouseAddressStreet  = streetbox.Text;
                warehouse.WarehouseAddressCity    = citybox.Text;
                warehouse.WarehouseAddressState   = statebox.Text;
                warehouse.WarehouseAddressZipcode = zipcodebox.Text;

                //Call service method
                client.CreateWarehouse(warehouse, ref message);

                var sb = new StringBuilder();
                sb.Append(message + "\r\n");
                sb.Append("WarehouseName: " + warehouse.WarehouseName + "\r\n");
                sb.Append("WarehouseStreet: " + warehouse.WarehouseAddressStreet + "\r\n");
                sb.Append("WarehouseCity: " + warehouse.WarehouseAddressCity + "\r\n");
                sb.Append("WarehouseState: " + warehouse.WarehouseAddressState + "\r\n");
                sb.Append("WarehouseZipcode: " + warehouse.WarehouseAddressZipcode + "\r\n");

                result = sb.ToString();
            }
            catch (Exception ex)
            {
                result = "Exception:" + ex.Message.ToString();
            }

            //Set text box with output
            allwhbox.Text = result;
        }
Beispiel #10
0
        public async Task Products_AddNewProduct_ReturnsCreated()
        {
            // Arrange
            var warehouseClient = new WarehouseClient(Configuration, Logger);
            var initialProducts = await GetAllProductsAsync(warehouseClient);

            var newProduct = GenerateNewProduct();

            // Act
            var response = await warehouseClient.NewProductAsync(newProduct);

            // Assert
            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            var newProducts = await GetAllProductsAsync(warehouseClient);

            Assert.Contains(newProducts, p => p.Name.Equals(newProduct.Name, StringComparison.InvariantCultureIgnoreCase));
            Assert.True(newProducts.Count == initialProducts.Count + 1);
        }