Exemple #1
0
        public JsonResult CalculateSum(decimal quantity, int productId)
        {
            var order = new OrderViewModel();
            var sum   = order.CalculateSum(quantity, productId);

            return(Json(sum, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
 internal int saveOrder(OrderViewModel newOrder)
 {
     using (SqlConnection sqlConnection = new SqlConnection(Main_Connectionstring))
     {
         using (SqlCommand command = new SqlCommand("spSaveOrder", sqlConnection))
         {
             try
             {
                 sqlConnection.Open();
                 command.CommandType = CommandType.StoredProcedure;
                 command.Parameters.AddWithValue("@ProductId", newOrder.ProductId);
                 command.Parameters.AddWithValue("@Quantity", newOrder.Quantity);
                 command.Parameters.AddWithValue("@Username", newOrder.Username);
                 command.Parameters.AddWithValue("@Sum", newOrder.CalculateSum(newOrder.Quantity, newOrder.ProductId));
                 return(Convert.ToInt32(command.ExecuteScalar()));
             }
             catch (Exception ex)
             {
                 return(0);
             }
         }
     }
 }