Example #1
0
 public IHttpActionResult Post(string PhoneNumber, string Message)
 {
     if (!string.IsNullOrEmpty(SendMessageModels.SendWhatsAppMessage(PhoneNumber, Message)))
     {
         return(Ok());
     }
     else
     {
         return(InternalServerError());
     }
 }
        public IHttpActionResult Post([FromBody] Transaction transaction)
        {
            string        ConnectionString = "Connection-String";
            SqlConnection sqlConnection    = new SqlConnection(ConnectionString);

            sqlConnection.Open();

            SqlCommand sqlCommand = new SqlCommand($"Insert into [dbo].[Transactions] (TransactionID, TransactionDateTime, SKU, CustomerID, NetPrice, Quantity, State) Values('{transaction.TransactionID}', '{transaction.TransactionDateTime}', '{transaction.SKU}', '{transaction.CustomerID}', {transaction.NetPrice}, {transaction.Quantity}, '{transaction.State}')", sqlConnection);

            sqlCommand.ExecuteNonQuery();

            sqlCommand = new SqlCommand($"Update [dbo].[Inventory] SET Quantity = (Quantity - {transaction.Quantity}) Where SKU ='{transaction.SKU}'", sqlConnection);
            sqlCommand.ExecuteNonQuery();

            sqlCommand = new SqlCommand($"Select Quantity from [dbo].[Inventory] Where SKU='{transaction.SKU}'", sqlConnection);
            int Quantity = (int)sqlCommand.ExecuteScalar();

            sqlConnection.Close();

            int               predictionQuantity = 0;
            string            productname        = string.Empty;
            int               Weeks       = 0;
            List <Prediction> predictions = GetPredictions(transaction.SKU);

            foreach (var prediction in predictions)
            {
                productname         = prediction.ProductName;
                predictionQuantity += prediction.Quantity;
                Weeks = prediction.Period;
            }

            if (predictionQuantity > Quantity)
            {
                string Message = $"I am NCR Smart Predictor. I predict that '{productname}' is going to run Out of Stock by next Week. Please consider ordering {predictionQuantity} within next {Weeks} week(s).";
                SendMessageModels.SendWhatsAppMessage("Provide-Number", Message);
            }

            return(Ok());
        }