public PredictReorderQtyDTO GetPredictModel(CatalogueItemDTO item) { using (var client = new HttpClient()) { StockEF predictItem = stockEFF.FindStockByItemCode(item.ItemCode); //label encoding for the three features //contain the label encoding for category and also the average quantity based on category and uom int[] categoryAvgQty = LabelEncodeByCategory(predictItem.Category, predictItem.Uom); int uom = LabelEncodeByUOM(predictItem.Uom); int popularity = LabelEncodeByPopularity(predictItem.ItemCode, categoryAvgQty[1], uom); PredictReorderQtyDTO predModel = new PredictReorderQtyDTO(categoryAvgQty[0], popularity, uom); return(predModel); } }
public async Task <ActionResult> UpdateCatalogueItem(CatalogueItemDTO item, string decision) { if (decision == "Cancel") { return(RedirectToAction("ViewCatalogueItem", new { catalogueId = item.CatalogueId })); } if (decision == "Predict Reorder Quantity") { // get prediction from service using (var client = new HttpClient()) { PredictReorderQtyDTO predModel = predictService.GetPredictModel(item); // send a POST request to the server uri with the data and get the response as HttpResponseMessage object HttpResponseMessage res = await client.PostAsJsonAsync("http://127.0.0.1:5000/", predModel); // Return the result from the server if the status code is 200 (everything is OK) if (res.IsSuccessStatusCode) { int prediction = int.Parse(res.Content.ReadAsStringAsync().Result); ModelState.Remove("ReorderQty"); item.ReorderQty = prediction; } else { //set error message or view } // set it and throw it back to the update catalogue view return(View(item)); } } // decision == Save CatalogueItemEF catItem = new CatalogueItemEF() { CatalogueId = item.CatalogueId, ItemCode = item.ItemCode, ReorderLevel = item.ReorderLevel, ReorderQty = item.ReorderQty }; stockService.UpdateCatalogueItem(catItem); return(RedirectToAction("ViewCatalogueItem", new { catalogueId = catItem.CatalogueId })); }