using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JRCookbookBusiness { public class RecipeHighlights { public Guid? recipeID = null; public Guid? cookbookID = null; public Guid? cookbookchapterID = null; public String recipename = String.Empty; public RecipeHighlights() { } public RecipeHighlights(Guid recipeID) { PopulateByID(recipeID); } public void Delete() { Recipe.DeleteByID(recipeID.Value); } public static RecipeHighlights GetRecipeByID(Guid recipeID) { return new RecipeHighlights(recipeID); } public static List GetAllRecipes() { DataSet recordSet; var returnValue = new List(); recordSet = clsDatabaseLayer.GetDatabaseLayer().GetAllRecipes(); if (recordSet.Tables[0].Rows.Count > 0) { foreach(DataRow ldbrwRow in recordSet.Tables[0].Rows) { var newRecipe = new RecipeHighlights(); newRecipe.PopulateFromDataRow(ldbrwRow); returnValue.Add(newRecipe); } } return returnValue; } public static RecipeHighlights GetRecipeHighlightsByDataRow(DataRow row) { var newRecipe = new RecipeHighlights(); newRecipe.PopulateFromDataRow(row); return newRecipe; } private void PopulateByID(Guid recipeID) { DataSet recordSet; recordSet = clsDatabaseLayer.GetDatabaseLayer().GetRecipeByID(recipeID); if (recordSet.Tables[0].Rows.Count > 0) { DataRow ldbrwRow; ldbrwRow = recordSet.Tables[0].Rows[0]; PopulateFromDataRow(ldbrwRow); } } private void PopulateFromDataRow(DataRow dataRow) { InitializeAllFields(); if (dataRow.IsNull("recipeID")) recipeID = null; else recipeID = (Guid)dataRow["recipeID"]; if (dataRow.IsNull("cookbookID")) cookbookID = null; else cookbookID = (Guid)dataRow["cookbookID"]; if (dataRow.IsNull("cookbookchapterID")) cookbookchapterID = null; else cookbookchapterID = (Guid)dataRow["cookbookchapterID"]; if (dataRow.IsNull("recipename")) recipename = String.Empty; else recipename = (String)dataRow["recipename"]; } private void InitializeAllFields() { recipeID = null; cookbookID = null; cookbookchapterID = null; recipename = String.Empty; } } }