public tblRecipe AddNewRecipe(tblRecipe recipe) { try { using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { tblRecipe newRecipe = new tblRecipe { RecipeName = recipe.RecipeName, RecipeType = recipe.RecipeType, IntendedFor = recipe.IntendedFor, Author = recipe.Author, Description = recipe.Description, DateCreated = recipe.DateCreated, }; context.tblRecipes.Add(newRecipe); context.SaveChanges(); return(newRecipe); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public tblRecipe UpdateRecipe(tblRecipe Updated) { try { using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { tblRecipe recipe = (from x in context.tblRecipes where x.RecipeID == Updated.RecipeID select x).First(); recipe.RecipeName = Updated.RecipeName; recipe.DateCreated = Updated.DateCreated; recipe.IntendedFor = Updated.IntendedFor; recipe.Description = Updated.Description; recipe.RecipeType = Updated.RecipeType; recipe.tblIngredients = Updated.tblIngredients; recipe.Author = Updated.Author; context.SaveChanges(); MessageBox.Show("Recipe successfully updated!", "Updated", MessageBoxButton.OK, MessageBoxImage.Information); return(recipe); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public List <vwRecipe> GetAllvwRecipes() { try { using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { return((from x in context.vwRecipes select x).ToList()); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
private void UpdateRecipeExecute() { try { using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { tblRecipe recipeToUpdate = ConvertTotblRepcipe(Recipe); UpdateRecipeView recipeView = new UpdateRecipeView(recipeToUpdate, User); recipeView.ShowDialog(); RecipeList = recipeService.GetAllvwRecipes(); } } catch (Exception ex) { MessageBox.Show("Exception" + ex.Message.ToString()); } }
public tblRecipe GetRecipeByID(int ID) { try { using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { return((from x in context.tblRecipes where x.RecipeID == ID select x).First()); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public void DeleteRecipe(int ID) { try { using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { context.tblRecipes.Remove((from x in context.tblRecipes where x.RecipeID == ID select x).FirstOrDefault()); context.SaveChanges(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); } }
public tblIngredient GetIngredientByName(string name) { try { using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { return((from x in context.tblIngredients where x.IngredientName.Equals(name) select x).First()); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public tblPerson GetUserByUserNameAndPass(string userName, string password) { try { using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { tblPerson user = (from x in context.tblPersons where x.Username == userName && x.Password == password select x).First(); return(user); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public tblPerson AddUser(tblPerson user) { try { using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { tblPerson newUser = new tblPerson(); newUser.Username = user.Username; newUser.Password = user.Password; newUser.FirstName = user.FirstName; newUser.LastName = user.LastName; context.tblPersons.Add(newUser); context.SaveChanges(); return(newUser); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
void Submit(object obj) { string encryptedString = (obj as PasswordBox).Password; if (encryptedString.Length < 5) { MessageBox.Show("Password has to be at least 5 characters long"); return; } string password = EncryptionHelper.Encrypt(encryptedString); if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(encryptedString)) { MessageBox.Show("Wrong user name or password"); return; } if (UserName.Equals("Admin") && !encryptedString.Equals("Admin123")) { MessageBox.Show("Wrong password for Admin"); return; } if (UserName.Equals("Admin") && encryptedString.Equals("Admin123")) { tblPerson adminInDb = personService.GetUserByUserNameAndPass(UserName, password); if (adminInDb == null) { tblPerson admin = new tblPerson(); admin.Username = UserName; admin.Password = password; adminInDb = personService.AddUser(admin); AdminMainView adminMain = new AdminMainView(adminInDb); adminMain.Show(); view.Close(); return; } else { AdminMainView adminMain = new AdminMainView(adminInDb); adminMain.Show(); view.Close(); return; } } tblPerson userInDb = personService.GetUserByUserName(UserName); if (userInDb == null) { FirstLogin firstLogin = new FirstLogin(UserName, password); firstLogin.Show(); view.Close(); return; } else { if (!userInDb.Password.Equals(password)) { MessageBox.Show("Wrong password for this user"); return; } tblPerson p; using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { p = (from x in context.tblPersons where x.Username == UserName select x).First(); } UserMain main = new UserMain(p); main.Show(); view.Close(); return; } }