private void populate(Recipe r) { litName.Text = r.Name; litDesc.Text = r.Description; litDishType.Text = r.DishTypeId.ToString(); litCuisine.Text = r.CuisineTypeId.ToString(); litPrepTime.Text = r.PreparationTime.ToString(); litCookTime.Text = r.CookingTime.ToString(); litNumServs.Text = r.NumberOfServings.ToString(); litNotes.Text = r.Notes; }
protected void btnSubmit_Click(object sender, EventArgs e) { if (IsValid) { Recipe r = new Recipe(); r.Name = txtName.Text.Trim(); r.Description = txtDesc.Text.Trim(); r.DishTypeId = new Guid(ddlDishType.SelectedValue); r.CuisineTypeId = new Guid(ddlCuisine.SelectedValue); r.PreparationTime = Int32.Parse(txtPrepTime.Text); r.CookingTime = int.Parse(txtCookTime.Text); r.NumberOfServings = Int32.Parse(txtNumServings.Text); r.Notes = txtNotes.Text.Trim(); r.Save(); Response.Write("Recipe saved: ID: " + r.RecipeId); Response.Redirect("/RecipeBuilder/Edit/?Recipe=" + r.RecipeId); } }
private static void populate(Recipe r, SqlDataReader rdr) { r.RecipeId = (Guid)rdr["RecipeId"]; r.Name = rdr["Name"].ToString(); r.Description = rdr["Description"].ToString(); r.DishTypeId = (Guid)rdr["DishTypeId"]; r.CuisineTypeId = (Guid)rdr["CuisineTypeId"]; r.PreparationTime = Int32.Parse(rdr["PreparationTime"].ToString()); r.CookingTime = Int32.Parse(rdr["CookingTime"].ToString()); r.Notes = rdr["Notes"].ToString(); r.NumberOfServings = Int32.Parse(rdr["Numberofservings"].ToString()); }
public static List<Recipe> Create(List<Recipe> lst) { Recipe r; using (SqlConnection con = DBUtils.GetConnection()){ con.Open(); using (SqlDataReader rdr = DBUtils.GetReader("Core.Recipe_Select", new SqlParameter[0], con) ) { if (rdr.HasRows){ while(rdr.Read()){ r= new Recipe(); populate(r, rdr); lst.Add(r); } } } } return lst; }
public static Recipe Create(Guid rId) { Recipe r; using (SqlConnection conn = DBUtils.GetConnection()) { conn.Open(); using (SqlDataReader rdr = DBUtils.GetReader("Core.Recipe_Select", new SqlParameter[]{ new SqlParameter("@RecipeId", rId)}, conn)) { if (rdr.HasRows) { r = new Recipe(); while (rdr.Read()) { populate(r, rdr); } return r; } else{ throw new ApplicationException(string.Format("Recipe with ID:{0} was not found.", rId)); } } } }