Ejemplo n.º 1
1
        public RecipesViewModel()
        {
            // initialize commands
            m_addNewRecipeCommand = new RelayCommand(AddNewRecipe);
            m_deleteRecipeCommand = new RelayCommand<RecipeDataModel>(DeleteRecipe);
            m_addHopsIngredientToRecipeCommand = new RelayCommand<Hops>(AddHopsIngredient);
            m_addFermentableIngredientToRecipeCommand = new RelayCommand<Fermentable>(AddFermentableIngredient);
            m_changeYeastCommand = new RelayCommand<Yeast>(ChangeYeast);
            m_deleteHopsIngredientCommand = new RelayCommand<IHopsIngredient>(DeleteHopsIngredient);
            m_deleteFermentableIngredientCommand = new RelayCommand<IFermentableIngredient>(DeleteFermentableIngredient);

            // get available ingredients
            List<IngredientTypeBase> allAvailableIngredients = RecipeUtility.GetAvailableIngredients().OrderBy(ingredient => ingredient.Name).ToList();
            m_availableHops = allAvailableIngredients.OfType<Hops>().ToReadOnlyObservableCollection();
            m_availableFermentables = allAvailableIngredients.OfType<Fermentable>().ToReadOnlyObservableCollection();
            m_availableYeasts = allAvailableIngredients.OfType<Yeast>().ToReadOnlyObservableCollection();

            List<Style> beerStyles = RecipeUtility.GetAvailableBeerStyles().OrderBy(style => style.Name).ToList();
            m_availableBeerStyles = beerStyles.ToReadOnlyObservableCollection();
            m_savedRecipes = new ObservableCollection<RecipeDataModel>(RecipeUtility.GetSavedRecipes(beerStyles));

            GetSettings();

            // set the current recipe to the first in the collection
            CurrentRecipe = m_savedRecipes.FirstOrDefault();
        }
Ejemplo n.º 2
0
        public MainViewModel()
        {
            try
            {
                NewStudent = new Student();
                SelectedDate = DateTime.Now.Date;

                AddNewStudentCommand = new RelayCommand(AddNewStudent, CanAddNewStudent);
                AddClassCommand = new RelayCommand(AddClass, CanAddClass);
                CancelNewStudentCommand = new RelayCommand(() => { IsNewStudentOpen = false; });
                OpenAddStudentCommand = new RelayCommand(() => { IsNewStudentOpen = true; });
                RemoveClassCommand = new RelayCommand<Class>(c => RemoveClass(c));

                _repository = new StudentRepository();

                IList<Student> allStudents = _repository.GetAll();
                if (allStudents != null)
                {
                    AllStudents = new ObservableCollection<Student>(allStudents.OrderBy(s => s.LastName).ThenBy(s => s.FirstName));
                    SelectedStudent = AllStudents.FirstOrDefault();
                }
            }
            catch(Exception e)
            {
                System.IO.File.AppendAllText(@"C:\log.txt", string.Format("{0}\r\n{1}", e.Message, e.StackTrace));
            }
        }
Ejemplo n.º 3
0
 public void CommandExecutes()
 {
     bool executed = false;
     RelayCommand target = new RelayCommand(() => executed = true);
     target.Execute(null);
     Assert.IsTrue(executed);
 }
Ejemplo n.º 4
0
        public BatchesViewModel()
        {
            m_addNewBatchCommand = new RelayCommand<RecipeDataModel>(AddNewBatch, CanAddNewBatch);
            m_deleteBatchCommand = new RelayCommand<BatchDataModel>(DeleteBatch);
            m_addGravityReadingCommand = new RelayCommand(AddGravityReading, CanAddGravityReading);
            m_deleteGravityReadingCommand = new RelayCommand<GravityReadingDataModel>(DeleteGravityReading);

            List<Style> beerStyles = RecipeUtility.GetAvailableBeerStyles().OrderBy(style => style.Name).ToList();
            m_availableRecipes = new ObservableCollection<RecipeDataModel>(RecipeUtility.GetSavedRecipes(beerStyles));
            m_savedBatches = new ObservableCollection<BatchDataModel>(BatchUtility.GetSavedBatches(m_availableRecipes));

            CurrentBatch = m_savedBatches.FirstOrDefault();
        }
Ejemplo n.º 5
0
        public void ReceiveCorrectParameter()
        {
            bool canExecuteGotParam = false;
            bool executeGotParam = false;
            
            string paramValue = "whatever";

            RelayCommand<string> target = new RelayCommand<string>(
                (param) => executeGotParam = (param == paramValue), 
                (param) => canExecuteGotParam = (param == paramValue));

            target.CanExecute(paramValue);
            target.Execute(paramValue);

            Assert.IsTrue(canExecuteGotParam);
            Assert.IsTrue(executeGotParam);
        }
Ejemplo n.º 6
0
 public void CanExecuteReturnsFalse()
 {
     RelayCommand target = new RelayCommand(() => Console.WriteLine(), () => false);
     bool result = target.CanExecute(null);
     Assert.IsFalse(result);
 }