//fills the database if it empty.
        public void FillDatabase()
        {
            if (_restaurantRepository.Read().Count == 0)
            {
                var res = new Restaurant
                {
                    Name       = "Bones",
                    Address    = "BonesAddres",
                    Describing = "kendt for et spareRibs",
                    Webside    = "bones.dk",
                    Foods      = new List <Food>()
                };


                var resWithId = _restaurantRepository.Create(res);


                var food = new Food
                {
                    Describing   = "smagte godt",
                    Name         = "SpareRibs",
                    Price        = 120,
                    Rating       = 3,
                    RestaurantId = resWithId.Id
                };

                _foodRespository.Create(food);
                res.Foods.Add(food);
                _restaurantRepository.Update(res);
            }
        }
Example #2
0
        private async void Delete(object sender, EventArgs e)
        {
            if (FoodList.SelectedItem != null)
            {
                var food   = FoodList.SelectedItem as Food;
                var answer = await DisplayAlert("Delete " + food.Name, "Do you want to Delete " + food.Name + "?", "Yes", "No");

                if (answer == true)
                {
                    var restaurantId = food.RestaurantId;
                    _foodRespository.Delete(food.Id);
                    FoodList.ItemsSource = _restaurantRespository.Read(restaurantId).Foods;
                }
            }
        }
Example #3
0
        private async void Options(object sender, EventArgs e)
        {
            var action = await DisplayActionSheet("choose Option", "", "", "Add Restaurant", "Details", "Delete Restaurant", "Cancel");

            switch (action)
            {
            case "Add Restaurant":
                await Navigation.PushAsync(new CreateResPage());

                break;

            case "Details":
                if (ResList.SelectedItem != null)
                {
                    restaurant = ResList.SelectedItem as Restaurant;
                    await Navigation.PushAsync(new ResDetailPage(restaurant));
                }
                break;

            case "Delete Restaurant":
                if (ResList.SelectedItem != null)
                {
                    restaurant = ResList.SelectedItem as Restaurant;
                    var answer = await DisplayAlert("Delete " + restaurant.Name, "Do you want to Delete " + restaurant.Name + "?", "Yes", "No");

                    if (answer == true)
                    {
                        foreach (var food in restaurant.Foods)
                        {
                            _FoodRepository.Delete(food.Id);
                        }
                        _restaurantRepository.Delete(restaurant.Id);
                        ResList.ItemsSource = _restaurantRepository.Read();
                    }
                }
                break;

            case "Cancel":
                break;
            }
        }
        public void CreateTest_when_exist_record_should_update_budget()
        {
            this._budgetService = new BudgetService(_budgetRepositoryStub);
            var budgetFromDb = new Budget {
                Amount = 999, YearMonth = "2017-02"
            };

            _budgetRepositoryStub.Read(Arg.Any <Func <Budget, bool> >()).ReturnsForAnyArgs(budgetFromDb);
            var model = new BudgetAddViewModel {
                Amount = 2000, Month = "2017-02"
            };
            var wasUpdated = false;

            this._budgetService.Updated += (sender, args) => wasUpdated = true;
            this._budgetService.Create(model);
            _budgetRepositoryStub.Received().Save(Arg.Is <Budget>(x => x == budgetFromDb && x.Amount == 2000));
            Assert.IsTrue(wasUpdated);
        }
Example #5
0
        public void Create(BudgetAddViewModel model)
        {
            var budget = _budgetRespository.Read(x => x.YearMonth == model.Month);

            if (budget == null)
            {
                this._budgetRespository.Save(new Budget {
                    Amount = model.Amount, YearMonth = model.Month
                });
                var handler = this.Created;
                handler?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                budget.Amount = model.Amount;
                this._budgetRespository.Save(budget);
                var handler = this.Updated;
                handler?.Invoke(this, EventArgs.Empty);
            }
        }