예제 #1
0
        public Dish ChoseDish(TimeOfEat timeOfEat, float calories, float limit)
        {
            Dish        selectedDish = null;
            List <Dish> listOfDish   = new List <Dish>();
            //pobranie wszystkich dan z naszego przedziału
            var listDish = db.Dish.Select(n => n).Where(n => n.EatingTime == timeOfEat && (n.Calories - calories <= limit && n.Calories - calories >= -limit));

            foreach (var item in listDish)
            {
                listOfDish.Add(item);
            }

            if (listOfDish.Count == 0)
            {
                selectedDish = ChoseDish(timeOfEat, calories, limit + 100);
                return(selectedDish);
            }
            //wybór dania do zwrócenia
            Random rnd = new Random();

            int randomDish = rnd.Next(0, (listOfDish.Count));

            selectedDish = listOfDish[randomDish];

            return(selectedDish);
        }
예제 #2
0
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            var user = _userRegistry.GetUser(Username.Text, PasswordHelper.GetHash(Password.Password));

            if (user == null)
            {
                MessageBox.Show("Incorrect data");
                Clear();
                return;
            }

            var timeOfEat = new TimeOfEat
            {
                Owner = this
            };

            timeOfEat.ShowDialog();

            Clear();
        }