Exemplo n.º 1
0
        public ComponentStocks CalculateNewStocks(ComponentUpdate componentUpdate, List <Component> componentList)
        {
            ComponentStocks componentStocks = new ComponentStocks();

            for (int i = 0; i < componentList.Count; i++)
            {
                if (componentList[i].ComponentName == "Milk")
                {
                    componentStocks.MilkInStock = componentList[i].Stock - componentUpdate.MilkNeed;
                    if (componentUpdate.ExtraMilk)
                    {
                        componentStocks.MilkInStock -= 1;
                    }
                }
                else if (componentList[i].ComponentName == "Coffe")
                {
                    componentStocks.CoffeInStock = componentList[i].Stock - componentUpdate.CoffeNeed;
                    if (componentUpdate.ExtraCoffe)
                    {
                        componentStocks.CoffeInStock -= 1;
                    }
                }
                else if (componentList[i].ComponentName == "Water")
                {
                    componentStocks.WaterInStock = componentList[i].Stock - componentUpdate.WaterNeed;
                    if (componentUpdate.ExtraWater)
                    {
                        componentStocks.WaterInStock -= 1;
                    }
                }
            }
            return(componentStocks);
        }
Exemplo n.º 2
0
        public IActionResult ConfirmOrder([FromBody] ComponentUpdate componentUpdate)
        {
            ComponentBussiness component       = new ComponentBussiness();
            ComponentStocks    componentStocks = component.ConfirmOrder(componentUpdate);

            return(Ok(componentStocks));
        }
        public async Task <ComponentStocks> ConfirmOrderAsync(decimal milkNeed, decimal coffeNeed, decimal waterNeed, bool milkCheck, bool coffeCheck, bool waterCheck)
        {
            var httpClient  = new HttpClient();
            var servicePath = new ServicePath();

            ComponentUpdate componentUpdate = new ComponentUpdate();

            componentUpdate.MilkNeed   = milkNeed;
            componentUpdate.CoffeNeed  = coffeNeed;
            componentUpdate.WaterNeed  = waterNeed;
            componentUpdate.ExtraMilk  = milkCheck;
            componentUpdate.ExtraCoffe = coffeCheck;
            componentUpdate.ExtraWater = waterCheck;

            var serialazeJSON = JsonConvert.SerializeObject(componentUpdate);
            var returnResult  = await httpClient.PutAsync(servicePath.ServiceURL + "component/confirmorder", new StringContent(serialazeJSON, Encoding.UTF8, "application/json"));

            var contents = await returnResult.Content.ReadAsStringAsync();

            ComponentStocks response = JsonConvert.DeserializeObject <ComponentStocks>(contents);

            return(response);
        }