示例#1
0
        private void SaveExecute()
        {
            try
            {
                using (CookbookEntities context = new CookbookEntities())
                {
                    int id = recipe.RecipeID;

                    tblRecipe   newRecipe = (from x in context.tblRecipes where x.RecipeID == id select x).First();
                    tblUserData user      = (from y in context.tblUserDatas where y.UserDataID == recipe.UserDataID select y).First();

                    newRecipe.Name = recipe.Name;

                    string type = recipe.Type.ToUpper();

                    // type validation
                    if ((type == "A" || type == "M" || type == "D"))
                    {
                        newRecipe.Type = recipe.Type;
                    }
                    else
                    {
                        MessageBox.Show("Wrong Type input, please enter A, M or D.\n(Appetizer/Main course/Dessert)");
                    }

                    newRecipe.Description  = recipe.Description;
                    newRecipe.DateCreated  = recipe.DateCreated;
                    newRecipe.PersonsCount = recipe.PersonsCount;

                    newRecipe.RecipeID   = recipe.RecipeID;
                    newRecipe.UserDataID = user.UserDataID;

                    context.SaveChanges();

                    IsUpdateRecipe = true;

                    MessageBox.Show("The recipe updated successfully.");
                }
                updateRecipe.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Wrong inputs, please check your inputs or try again.");
            }
        }
示例#2
0
        private void SaveExecute()
        {
            try
            {
                using (CookbookEntities context = new CookbookEntities())
                {
                    tblRecipe newRecipe = new tblRecipe();

                    newRecipe.Name = recipe.Name;

                    string type = recipe.Type.ToUpper();

                    // type validation
                    if ((type == "A" || type == "M" || type == "D"))
                    {
                        newRecipe.Type = recipe.Type;
                    }
                    else
                    {
                        MessageBox.Show("Wrong Type input, please enter A, M or D.\n(Appetizer/Main course/Dessert)");
                    }

                    newRecipe.Description  = recipe.Description;
                    newRecipe.DateCreated  = DateTime.Now;
                    newRecipe.PersonsCount = recipe.PersonsCount;

                    newRecipe.RecipeID   = recipe.RecipeID;
                    newRecipe.UserDataID = user.UserDataID;

                    context.tblRecipes.Add(newRecipe);
                    context.SaveChanges();

                    IsUpdateRecipe = true;

                    MessageBox.Show("The recipe created successfully.");
                }
                addRecipe.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Wrong inputs, please check your inputs or try again.");
            }
        }