Example #1
0
        //  public bool postHopAddition(hoplist hopaddition)
        //  {
        //      RegistryKey adsfa = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
        //      string dataurl = GetDataProvider();
        //      var client = new RestClient(dataurl);
        //      RestRequest request = new RestRequest();
        //      if (hopaddition.id == "")
        //      {
        //          request = new RestRequest("/hopaddition/", Method.POST);
        //      } else {
        //          request = new RestRequest("/hopaddition/" + hopaddition.id, Method.POST);
        //      }
        //      request.RequestFormat = DataFormat.Json;
        //      request.AddHeader("Content-type", "application/json");
        //      request.AddJsonBody(
        //      new
        //      {
        //          recipeID = hopaddition.recipeID,
        //          hopID = hopaddition.hopID,
        //          amount = hopaddition.amount,
        //          type = hopaddition.type,
        //          time = hopaddition.time
        //      });
        //
        //      IRestResponse response = client.Execute(request);
        //      return true;
        //  }

        //   public string postFermentableAddition(fermentablelist fermentableAddition)
        //   {
        //       RegistryKey adsfa = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
        //       string dataurl = GetDataProvider();
        //       var client = new RestClient(dataurl);
        //       RestRequest request = new RestRequest();
        //       string returnable = "";
        //       if (fermentableAddition.id == null)
        //       {
        //           request = new RestRequest("/fermentableaddition/", Method.POST);
        //           returnable = "false";
        //       }
        //       else
        //       {
        //           request = new RestRequest("/fermentableaddition/" + fermentableAddition.id, Method.POST);
        //           returnable = fermentableAddition.id;
        //       }
        //       request.RequestFormat = DataFormat.Json;
        //       request.AddHeader("Content-type", "application/json");
        //       request.AddJsonBody(
        //       new
        //       {
        //           recipeID = fermentableAddition.recipeID,
        //           fermentableID = fermentableAddition.fermentableID,
        //           fermentable = fermentableAddition.fermentable,
        //           use = "Mash",
        //           weight = fermentableAddition.weight
        //       });
        //
        //       IRestResponse response = client.Execute(request);
        //       return returnable;
        //   }

        //     public bool postYeastAddition(yeastlist yeastAddition)
        //     {
        //         RegistryKey adsfa = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
        //         string dataurl = GetDataProvider();
        //         var client = new RestClient(dataurl);
        //         RestRequest request = new RestRequest();
        //         if (yeastAddition.ID == null)
        //         {
        //             request = new RestRequest("/yeastaddition/", Method.POST);
        //         }
        //         else
        //         {
        //             request = new RestRequest("/yeastaddition/" + yeastAddition.ID, Method.POST);
        //         }
        //         request.RequestFormat = DataFormat.Json;
        //         request.AddHeader("Content-type", "application/json");
        //         request.AddJsonBody(
        //         new
        //         {
        //             recipeID = yeastAddition.recipeID,
        //             yeastID = yeastAddition.yeastID
        //         });
        //
        //         IRestResponse response = client.Execute(request);
        //         return true;
        //     }

        //     public bool postAdjunctAddition(adjunctList adjunctAddition)
        //     {
        //         RegistryKey adsfa = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
        //         string dataurl = GetDataProvider();
        //         var client = new RestClient(dataurl);
        //         RestRequest request = new RestRequest();
        //         if (adjunctAddition.id == null)
        //         {
        //             request = new RestRequest("/adjunctaddition/", Method.POST);
        //         }
        //         else
        //         {
        //             request = new RestRequest("/adjunctaddition/" + adjunctAddition.id, Method.POST);
        //         }
        //         request.RequestFormat = DataFormat.Json;
        //         request.AddHeader("Content-type", "application/json");
        //         request.AddJsonBody(
        //         new
        //         {
        //             recipeID = adjunctAddition.recipeID,
        //             adjunctID = adjunctAddition.adjunctID,
        //             amount = adjunctAddition.amount,
        //             unit = adjunctAddition.unit,
        //             time = adjunctAddition.time,
        //             timeUnit = adjunctAddition.timeUnit,
        //             type = adjunctAddition.type
        //         });
        //
        //         IRestResponse response = client.Execute(request);
        //         return true;
        //     }
        public recipeResponse postRecipe(recipe2 recipe)
        {
            RegistryKey adsfa   = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
            string      dataurl = GetDataProvider();
            var         client  = new RestClient(dataurl);
            RestRequest request = new RestRequest();

            if (recipe.idString == null)
            {
                recipe.id          = new id();
                recipe.recipeStats = new RecipeStatistics();
                request            = new RestRequest("/beernet/recipe/", Method.POST);
            }
            else
            {
                request = new RestRequest("/beernet/recipe/" + recipe.idString, Method.POST);
            }
            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Content-type", "application/json");
            request.AddJsonBody(recipe);
            IRestResponse  response   = client.Execute(request);
            recipeResponse returnable = JsonConvert.DeserializeObject <recipeResponse>(response.Content);

            return(returnable);
        }
Example #2
0
        /*
         * Saves the information entered in the grids
         * */
        private void SaveButton_Click(object sender, EventArgs e)
        {
            // bool reload = false;
            APIHandler handler = new APIHandler();

            currentRecipe.name        = BeerNameBox.Text;
            currentRecipe.description = descriptionBox.Text;
            recipeResponse   resp  = handler.postRecipe(currentRecipe);
            RecipeStatistics stats = resp.recipeStats;

            currentRecipe.recipeStats = stats;
            currentRecipe.idString    = resp.idString;
            RefreshStatistics();
            updateStyleSliders();
            //  foreach (hoplist h in currentRecipe.hops)
            //  {
            //     // handler.postHopAddition(h);
            //  }
            //  foreach(fermentablelist f in currentRecipe.fermentables)
            //  {
            //    //  string response = handler.postFermentableAddition(f);
            //  //    if(response == "false")
            //  //    {
            //  //        reload = true;
            //  //    }
            //  }
            //  foreach (yeast2 y in currentRecipe.yeasts)
            //  {
            //     // handler.postYeastAddition(y);
            //  }
            //  foreach (adjunctList a in currentRecipe.adjuncts)
            //  {
            //   //   handler.postAdjunctAddition(a);
            //  }
            // handler.postRecipe(currentRecipe);
            //  if(reload)
            //  {
            //     // currentRecipe = handler.loadRecipe(currentRecipe.id);
            //      populateGrids();
            //     // RefreshStatistics();
            //  }
        }