public async Task <IActionResult> Put([FromBody] RecipeNew recipe) { try { var retVal = await ContentProcesses.UpdateRecipeAsync(recipe); switch (retVal.State) { case CallReturnState.Success: return(Ok(retVal)); case CallReturnState.Warning: case CallReturnState.ValidationError: return(BadRequest(retVal.Errors)); case CallReturnState.Failure: return(StatusCode((int)HttpStatusCode.InternalServerError, retVal.Errors)); } } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex)); } return(StatusCode((int)HttpStatusCode.InternalServerError)); }
internal static async Task <int> CreateAsync(RecipeNew recipe) { int id; try { using (var connection = new SqlConnection(GlobalSettings.DbConnectionString)) { using (var cmd = new SqlCommand(StoredProc.Recipe_Create, connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(Parameter.Id, SqlDbType.Int).Direction = ParameterDirection.Output; cmd.Parameters.AddWithValue(Parameter.RecipeName, recipe.RecipeName); cmd.Parameters.AddWithValue(Parameter.Ingredients, recipe.Ingredients); await connection.OpenAsync(); await cmd.ExecuteNonQueryAsync(); id = Int32.Parse(cmd.Parameters[Parameter.Id].Value.ToString()); } } } catch (Exception) { throw; } return(id); }
protected void Page_Load(object sender, EventArgs e) { //Instantiate object Blogic myBL = new Blogic(); //Instantiate object Utility Util = new Utility(); int CatId = (int)Util.Val(Request.QueryString["catid"]); //Display random recipe GetRandomrecipe(CatId); //Get the newest 10 recipes. Change the value to 5 if you want to display only 5 newest recipes. int TopNewest = 10; //Get the 15 popular recipes. Change the value to 5 or 10 if you want to display only 5/10 most popular recipes. int TopPopular = 15; NewestRecipeSideMenuProvider GetNewestRecipe = new NewestRecipeSideMenuProvider(CatId, TopNewest); PopularRecipeSideMenuProvider GetPopularRecipe = new PopularRecipeSideMenuProvider(CatId, TopPopular); string CategoryName = GetNewestRecipe.Category; if (!string.IsNullOrEmpty(this.Request.QueryString["catid"])) { lblcatname.Text = CategoryName.ToString() + " "; lblcatnamepop.Text = CategoryName.ToString() + " "; lblrancatname.Text = CategoryName.ToString() + " "; lbTopCnt.Text = TopNewest.ToString(); } else { lblcatname.Text = ""; lbTopCnt.Text = TopNewest.ToString(); } RecipeNew.DataSource = GetNewestRecipe.GetNewestRecipe(); RecipeNew.DataBind(); TopRecipe.DataSource = GetPopularRecipe.GetPopularRecipe(); TopRecipe.DataBind(); if (!string.IsNullOrEmpty(this.Request.QueryString["catid"])) { lblpopcounter.Text = "Top Recipes"; } else { lblpopcounter.Text = "Top 15 Recipes"; } //Release allocated memory GetNewestRecipe = null; GetPopularRecipe = null; Util = null; }
public static async Task <CallReturn <Recipe> > CreateRecipeAsync(RecipeNew recipe) { var retVal = new CallReturn <Recipe>(); try { retVal.Object = await RecipeDBAsync.CreateAsync(new RecipeNew { RecipeName = recipe.RecipeName }); } catch (Exception ex) { Console.WriteLine(ex); retVal.SetError(ErrorType.SystemError, ex); } return(retVal); }
public static async Task <CallReturn <int> > UpdateRecipeAsync(RecipeNew recipe) { var retVal = new CallReturn <int>(); try { await RecipeDBAsync.UpdateAsync(new RecipeNew { Id = recipe.Id, RecipeName = recipe.RecipeName }); } catch (Exception ex) { retVal.SetError(ErrorType.SystemError, ex); throw; } return(retVal); }
internal static async Task UpdateAsync(RecipeNew recipe) { try { using (var connection = new SqlConnection(GlobalSettings.DbConnectionString)) { using (var cmd = new SqlCommand(StoredProc.Recipe_Update, connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(Parameter.Id, recipe.Id); cmd.Parameters.AddWithValue(Parameter.RecipeName, recipe.RecipeName); await connection.OpenAsync(); await cmd.ExecuteNonQueryAsync(); } } } catch (Exception) { throw; } }
public void Put([FromBody] RecipeNew recipe) { }