public void Load(int recipeid) { ChefsCornerEntities dc = new ChefsCornerEntities(); var ingredients = from rin in dc.tblRecipeIngredients join i in dc.tblIngredients on rin.in_Id equals i.in_Id join m in dc.tblMeasures on rin.ms_Id equals m.ms_Id where rin.rc_Id == recipeid select new { i.in_Id, i.in_Description, m.ms_Id, m.ms_Description, rin.ri_Quantity }; foreach (var mi in ingredients.ToList()) { MeasuredIngredient MI = new MeasuredIngredient(); MI.Id = mi.in_Id; MI.Description = mi.in_Description; MI.Measurement.Id = mi.ms_Id; MI.Measurement.Description = mi.ms_Description; MI.Quantity = mi.ri_Quantity; this.Add(MI); } }
public int Update() { // Create result variable for this method (int) int result = 0; try { // Using statement for connection string, and create a new instance of it using (ChefsCornerEntities dc = new ChefsCornerEntities()) { // If a specific user is selected, update the user information. Otherwise, throw an exception. tblMeasure Measure = dc.tblMeasures.Where(i => i.ms_Id == this.Id).FirstOrDefault(); if (Measure != null) { Measure.ms_Description = this.Description; result = dc.SaveChanges(); } } return(result); } catch (Exception e) { throw e; } }
public int Update() { // Create result variable for this method(int) int result = 0; try { //Using connection string statement and creating new instance of it using (ChefsCornerEntities dc = new ChefsCornerEntities()) { // If ingredient is selected, update the description. Otherwise, throw an exception. tblIngredient ingredient = dc.tblIngredients.Where(i => i.in_Id == this.Id).FirstOrDefault(); if (ingredient != null) { ingredient.in_Description = this.Description; result = dc.SaveChanges(); } } return(result); } catch (Exception e) { throw e; } }
public static void CheckIngredients(List <Ingredient> ingredients) { try { ChefsCornerEntities dc = new ChefsCornerEntities(); IngredientList Ingredients = new IngredientList(); Ingredients.Load(); foreach (Ingredient i in ingredients) { bool found = false; foreach (Ingredient n in Ingredients) { if (i.Description == n.Description) { found = true; i.Id = n.Id; } } if (!found) { i.Insert(); } } } catch (Exception e) { throw e; } }
public int Update() { int result = 0; try { using (ChefsCornerEntities dc = new ChefsCornerEntities()) { tblRecipe recipe = dc.tblRecipes.Where(r => r.rc_Id == this.Id).FirstOrDefault(); if (recipe != null) { recipe.rc_Name = this.Name; recipe.rc_Description = this.Description; recipe.rc_Directions = this.Directions; recipe.rc_Image = ConvertImage(this.Image); recipe.rc_Ingredients = this.Ingredients; result = dc.SaveChanges(); } } return(result); } catch (Exception e) { return(0); throw e; } }
public int Delete(int id) { // Create result variable for this method (int) int result = 0; try { // Using statement for connection string, and create a new instance of it using (ChefsCornerEntities dc = new ChefsCornerEntities()) // If Measure is selected, delete measure from tblMeasures and its Id number. Otherwise, throw exception { tblMeasure Measure = dc.tblMeasures.Where(i => i.ms_Id == id).FirstOrDefault(); if (Measure != null) { dc.tblMeasures.Remove(Measure); result = dc.SaveChanges(); } } return(result); } catch (Exception e) { throw e; } }
public int Delete(int id) { // Create result variable for this method(int) int result = 0; try { //Using connection string statement and creating new instance of it using (ChefsCornerEntities dc = new ChefsCornerEntities()) { // If ingredient is selected, delete the ingredient along with the Id associated with it. Otherwise, throw an exception. tblIngredient ingredient = dc.tblIngredients.Where(i => i.in_Id == id).FirstOrDefault(); if (ingredient != null) { dc.tblIngredients.Remove(ingredient); result = dc.SaveChanges(); } } return(result); } catch (Exception e) { throw e; } }
public void LoadById(int id) { try { // Create new instance of ChefsCornerEntities/ Connection string using (ChefsCornerEntities dc = new ChefsCornerEntities()) { // Find specific measure with the Id number, otherwise throw an exception tblMeasure Measure = dc.tblMeasures.Where(i => i.ms_Id == id).FirstOrDefault(); if (Measure != null) { this.Id = Measure.ms_Id; this.Description = Measure.ms_Description; } else { throw new Exception("Measure not found."); } } } catch (Exception e) { throw e; } }
public int Insert() { // Create result variable for this method (int) int result = 0; try { // Using statement for connection string, and create a new instance of it using (ChefsCornerEntities dc = new ChefsCornerEntities()) { // Create new instance of tblMeasure called Measure tblMeasure measure = new tblMeasure(); // Insert new user into tblMeasures by adding new Id number, otherwise throw exception measure.ms_Id = 1; if (dc.tblMeasures.Any()) { measure.ms_Id = dc.tblMeasures.Max(i => i.ms_Id) + 1; } this.Id = measure.ms_Id; measure.ms_Description = this.Description; dc.tblMeasures.Add(measure); result = dc.SaveChanges(); return(result); } } catch (Exception e) { throw e; } }
public int Insert() { // Create result variable for this method (int) int result = 0; try { //Using connection string statement and creating new instance of it using (ChefsCornerEntities dc = new ChefsCornerEntities()) { // Create new instance of tblIngredient tblIngredient ingredient = new tblIngredient(); ingredient.in_Id = 1; if (dc.tblIngredients.Any()) { ingredient.in_Id = dc.tblIngredients.Max(i => i.in_Id) + 1; } this.Id = ingredient.in_Id; ingredient.in_Description = this.Description; dc.tblIngredients.Add(ingredient); result = dc.SaveChanges(); return(result); } } catch (Exception e) { throw e; } }
public int Insert() { // Declare result variable for this method (int) int result = 0; try { // Using statement for connection string, and create a new instance of it using (ChefsCornerEntities dc = new ChefsCornerEntities()) { // Create new instance of tblRecipe called recipe tblRecipe recipe = new tblRecipe(); recipe.rc_Id = 1; if (dc.tblRecipes.Any()) { recipe.rc_Id = dc.tblRecipes.Max(r => r.rc_Id) + 1; } this.Id = recipe.rc_Id; recipe.rc_Name = this.Name; recipe.rc_Description = this.Description; recipe.rc_Directions = this.Directions; recipe.rc_Image = ConvertImage(this.Image); recipe.us_Id = this.UserId; recipe.rc_Ingredients = this.Ingredients; dc.tblRecipes.Add(recipe); result = dc.SaveChanges(); } return(result); } catch (Exception e) { throw e; } }
public bool SignIn() { try { // If Username and/ or Password text boxes are not empty, then login. Otherwise, return false. if (ScreenName != null && ScreenName != string.Empty) { if (Password != null && Password != string.Empty) { // Create new instance of ChefsCornerEntities/ Connection string ChefsCornerEntities dc = new ChefsCornerEntities(); tblUser user = dc.tblUsers.FirstOrDefault(u => u.us_ScreenName == this.ScreenName); if (user != null) { if (user.us_Pass == this.GetHash()) { // Successful login Email = user.us_Email; Id = user.us_Id; return(true); } else { return(false); } } else { return(false); } } else { return(false); } } else { return(false); } } catch (Exception e) { throw e; } }
//public MeasuredIngredientList Ingredients { get; set; } // Instantiate the class and create an instance of IngredientList //public Recipe() //{ // Ingredients = new MeasuredIngredientList(); //} public void LoadById(int id) { try { // Using statement using (ChefsCornerEntities dc = new ChefsCornerEntities()) { var recipe = (from rc in dc.tblRecipes join u in dc.tblUsers on rc.us_Id equals u.us_Id where rc.rc_Id == id select new { rc.rc_Id, rc.us_Id, u.us_ScreenName, rc.rc_Description, rc.rc_Directions, rc.rc_Name, rc.rc_Image, rc.rc_Ingredients }).FirstOrDefault(); // If specific recipe is loaded by Id number, load the list of ingredients. Otherwise, throw an exception. if (recipe != null) { this.Id = recipe.rc_Id; this.UserId = recipe.us_Id; this.UserName = recipe.us_ScreenName; this.Description = recipe.rc_Description; this.Directions = recipe.rc_Directions; this.Name = recipe.rc_Name; this.Image = (HttpPostedFileBase) new HttpByteFileBase(recipe.rc_Image); ConvertedImage = Convert.ToBase64String(recipe.rc_Image); this.Thumbnail = GetThumbnail(ConvertedImage); this.Ingredients = recipe.rc_Ingredients; } else { throw new Exception("Recipe not found."); } } } catch (Exception e) { throw e; } }
public void Load() { try { // Create new instance of ChefsCornerEntities/ Connection string ChefsCornerEntities dc = new ChefsCornerEntities(); foreach (tblIngredient ingredient in dc.tblIngredients) { Ingredient i = new Ingredient(ingredient.in_Id, ingredient.in_Description); Add(i); } } catch (Exception e) { throw e; } }
public void Load() { try { // Create new instance for ChefsCornerEntities/ Connection string ChefsCornerEntities dc = new ChefsCornerEntities(); foreach (tblMeasure Measure in dc.tblMeasures) { Measure i = new Measure(Measure.ms_Id, Measure.ms_Description); Add(i); } } catch (Exception e) { throw e; } }
public static void Delete(int recipeid, int ingredientid, int measureid) { try { // Create new instance of ChefsCornerEntities/ Connection string ChefsCornerEntities dc = new ChefsCornerEntities(); tblRecipeIngredient rin = dc.tblRecipeIngredients.FirstOrDefault(rci => rci.rc_Id == recipeid && rci.in_Id == ingredientid && rci.ms_Id == measureid); if (rin != null) { dc.tblRecipeIngredients.Remove(rin); dc.SaveChanges(); } } catch (Exception e) { throw e; } }
public void Insert() { try { // Create new instance of ChefsCornerEntities/ Connection string using (ChefsCornerEntities dc = new ChefsCornerEntities()) { // Create new instance of tblUser called user tblUser user = new tblUser(); // Insert new user into tblUsers by adding new Id number, otherwise throw exception Id = dc.tblUsers.Any() ? dc.tblUsers.Max(u => u.us_Id) + 1 : 1; Map(user); dc.tblUsers.Add(user); dc.SaveChanges(); } } catch (Exception e) { throw e; } }
public void Delete(int id) { try { // Using statement for connection string, and create a new instance of it using (ChefsCornerEntities dc = new ChefsCornerEntities()) { // If user with a specific id is selected, delete the user and the Id associated with it. Otherwise, throw an exception. tblUser user = dc.tblUsers.Where(u => u.us_Id == id).FirstOrDefault(); if (user != null) { dc.tblUsers.Remove(user); dc.SaveChanges(); } } } catch (Exception e) { throw e; } }
public void Update() { try { // Using statement for connection string, and create a new instance of it using (ChefsCornerEntities dc = new ChefsCornerEntities()) { tblUser user = dc.tblUsers.Where(u => u.us_Id == this.Id).FirstOrDefault(); // If a user is selected, update the user info. Otherwise, throw an exception. if (user != null) { Map(user); dc.SaveChanges(); } } } catch (Exception e) { throw e; } }
public static void Add(int recipeid, int ingredientid, int measureid) { try { // Create new instance of ChefsCornerEntities ChefsCornerEntities dc = new ChefsCornerEntities(); // Create new instance of tblRecipeIngredient tblRecipeIngredient rin = new tblRecipeIngredient(); // Add new Ids for recipes, ingredients, and measures to tblRecipeIngredients. Otherwise, throw an exception. rin.ri_Id = dc.tblRecipeIngredients.Any() ? dc.tblRecipeIngredients.Max(r => r.ri_Id) + 1 : 1; rin.in_Id = ingredientid; rin.rc_Id = recipeid; rin.ms_Id = measureid; dc.tblRecipeIngredients.Add(rin); dc.SaveChanges(); } catch (Exception e) { throw e; } }
public int Delete(int id) { int result = 0; try { using (ChefsCornerEntities dc = new ChefsCornerEntities()) { tblRecipe recipe = dc.tblRecipes.Where(r => r.rc_Id == id).FirstOrDefault(); if (recipe != null) { dc.tblRecipes.Remove(recipe); result = dc.SaveChanges(); } } return(result); } catch (Exception e) { return(0); throw e; } }
public void Load(int?userId) { using (ChefsCornerEntities dc = new ChefsCornerEntities()) { var recipes = (from rc in dc.tblRecipes join u in dc.tblUsers on rc.us_Id equals u.us_Id where rc.us_Id == userId || userId == null select new { rc.rc_Id, rc.rc_Name, rc.rc_Description, rc.rc_Directions, rc.rc_Image, u.us_Id, u.us_ScreenName, rc.rc_Ingredients }).ToList(); foreach (var rc in recipes) { Recipe recipe = new Recipe(); recipe.Id = rc.rc_Id; recipe.Name = rc.rc_Name; recipe.Description = rc.rc_Description; recipe.Directions = rc.rc_Directions; recipe.Image = (HttpPostedFileBase) new HttpByteFileBase(rc.rc_Image); recipe.ConvertedImage = Convert.ToBase64String(rc.rc_Image); recipe.UserId = rc.us_Id; recipe.UserName = rc.us_ScreenName; recipe.Ingredients = rc.rc_Ingredients; recipe.Thumbnail = recipe.GetThumbnail(recipe.ConvertedImage); // recipe.LoadIngredients(); this.Add(recipe); } } }
public void LoadById(int id) { try { //Using connection string statement and creating new instance of it using (ChefsCornerEntities dc = new ChefsCornerEntities()) { tblIngredient ingredient = dc.tblIngredients.Where(i => i.in_Id == id).FirstOrDefault(); if (ingredient != null) { this.Id = ingredient.in_Id; this.Description = ingredient.in_Description; } else { throw new Exception("Ingredient not found."); } } } catch (Exception e) { throw e; } }