public void UpdateMenu(ModelLibrary.Menu beforeMenu, ModelLibrary.Menu afterMenu)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();
            MenuCtrl menuCtrl         = new MenuCtrl();

            menuCtrl.UpdateMenu(beforeMenu, afterMenu);
        }
Beispiel #2
0
        public ModelLibrary.Menu ConvertMenuToModel(DatabaseAccessLibrary.Menu dbMenu)
        {
            var modelMenu = new ModelLibrary.Menu();
            List <ModelLibrary.Item> itemList = new List <ModelLibrary.Item>();
            ItemCtrl itemCtrl = new ItemCtrl();

            if (dbMenu == null)
            {
                return(modelMenu);
            }

            foreach (var Item in dbMenu.Items)
            {
                itemList.Add(itemCtrl.ConvertItemToModel(Item));
            }
            if (itemList.Count > 0)
            {
                modelMenu.RestaurantId = dbMenu.restaurantId;
                modelMenu.Id           = dbMenu.id;
                modelMenu.Name         = dbMenu.name;
                modelMenu.Items        = itemList;
                modelMenu.Active       = dbMenu.active;

                return(modelMenu);
            }
            modelMenu.RestaurantId = dbMenu.restaurantId;
            modelMenu.Id           = dbMenu.id;
            modelMenu.Name         = dbMenu.name;
            modelMenu.Active       = dbMenu.active;

            return(modelMenu);
        }
Beispiel #3
0
        private bool ValidateMenu(ModelLibrary.Menu menu)
        {
            var context = new ValidationContext(menu, null, null);
            var result  = new List <System.ComponentModel.DataAnnotations.ValidationResult>();

            return(Validator.TryValidateObject(menu, context, result, true));
        }
Beispiel #4
0
        public void UpdateMenu(ModelLibrary.Menu beforeMenu, ModelLibrary.Menu afterMenu)
        {
            var menuDb = new MenuDb();

            var beforeDbMenu = ConvertMenuToDb(beforeMenu);
            var afterDbMenu  = ConvertMenuToDb(afterMenu);

            menuDb.UpdateMenu(beforeDbMenu, afterDbMenu);
        }
        public static async Task <ModelLibrary.Menu> GetMenuAsync(int restaurantId)
        {
            var menuCtrl = new MenuCtrl();

            ModelLibrary.Menu menu = null;

            await Task.Run(() => menu = menuCtrl.GetActiveMenu(restaurantId));

            return(menu);
        }
Beispiel #6
0
        public ModelLibrary.Menu CreateMenu(ModelLibrary.Menu menu)
        {
            var      dbMenu   = new DatabaseAccessLibrary.Menu();
            ItemCtrl itemCtrl = new ItemCtrl();

            dbMenu.name         = menu.Name;
            dbMenu.restaurantId = menu.RestaurantId;
            dbMenu.active       = menu.Active;
            DatabaseAccessLibrary.MenuDb menuDb = new DatabaseAccessLibrary.MenuDb();
            menuDb.AddMenu(dbMenu);
            return(menu);
        }
Beispiel #7
0
        public ModelLibrary.Menu GetMenuByName(string name)
        {
            var menuDb = new MenuDb();
            var menu   = menuDb.GetMenuByName(name);

            ModelLibrary.Menu newMenu = null;
            var modelMenu             = ConvertMenuToModel(menu);

            if (menu != null)
            {
                return(modelMenu);
            }
            return(newMenu);
        }
Beispiel #8
0
        public ModelLibrary.Menu GetMenuById(int menuId)
        {
            var menuDb = new MenuDb();
            var menu   = menuDb.GetMenu(menuId);

            ModelLibrary.Menu newMenu = null;
            var modelMenu             = ConvertMenuToModel(menu);

            if (menu != null)
            {
                return(modelMenu);
            }
            return(newMenu);
        }
Beispiel #9
0
        private async void buttonSaveName_Click(object sender, RoutedEventArgs e)
        {
            var  selectedItem = (ModelLibrary.Menu)dataGridItemList.SelectedItem;
            bool newBool      = checkBoxActive.IsChecked ?? false;

            if (textBoxName.Text.Length < 2)
            {
                MessageBox.Show("NameInvalid");
            }
            else
            {
                var oldMenu = new ModelLibrary.Menu
                {
                    Id           = selectedItem.Id,
                    Active       = selectedItem.Active,
                    Items        = selectedItem.Items,
                    Name         = selectedItem.Name,
                    RestaurantId = restaurantId
                };
                var newMenu = new ModelLibrary.Menu
                {
                    Id           = selectedItem.Id,
                    Items        = selectedItem.Items,
                    Active       = newBool,
                    Name         = textBoxName.Text,
                    RestaurantId = restaurantId
                };
                var validation = ValidateMenu(newMenu);
                if (validation == true)
                {
                    await Services._MenuProxy.UpdateMenuAsync(oldMenu, newMenu);

                    dataGridItemList.Items.Clear();
                    var modelMenu = await Services._MenuProxy.GetAllMenusByRestaurantAsync(restaurantId);

                    foreach (ModelLibrary.Menu item in modelMenu)
                    {
                        dataGridItemList.Items.Add(item);
                    }
                    ;
                }
                else
                {
                    MessageBox.Show("Validation did not pass!");
                }
            }
        }
Beispiel #10
0
        public DatabaseAccessLibrary.Menu ConvertMenuToDb(ModelLibrary.Menu menu)
        {
            if (menu == null)
            {
                return(null);
            }

            var dbMenu = new DatabaseAccessLibrary.Menu
            {
                id           = menu.Id,
                active       = menu.Active,
                name         = menu.Name,
                restaurantId = menu.RestaurantId
            };

            return(dbMenu);
        }
        public void Create_Item_Service()
        {
            ItemCtrl itemCtrl = new ItemCtrl();
            //Setup
            var menu = new ModelLibrary.Menu
            {
                Active       = false,
                Id           = 1000000,
                Name         = "newName",
                RestaurantId = 1000000,
            };
            var itemCat = new ModelLibrary.ItemCat
            {
                Id   = 1000000,
                Name = "Soup"
            };
            var price = new ModelLibrary.Price
            {
                StartDate = DateTime.Now.Date,
                EndDate   = new DateTime(9999, 12, 31),
                VarPrice  = 12.5
            };
            var item = new ModelLibrary.Item
            {
                Id          = 1000000,
                Name        = "Controllerforabi",
                Description = "Totallynotadescription",
                Price       = price,
            };

            //Act
            var itemdb = itemCtrl.CreateItem(item, menu.Id, itemCat.Id);

            //Assert
            Assert.AreEqual(item.Name, itemdb.Name);
        }
Beispiel #12
0
        private async void buttonCreateMenu_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxName.Text.Length < 2)
            {
                MessageBox.Show("InvalidName");
            }
            else
            {
                bool newBool = checkBoxActive.IsChecked ?? false;
                ModelLibrary.Menu modelMenu = new ModelLibrary.Menu
                {
                    RestaurantId = restaurantId,
                    Name         = textBoxName.Text,
                    Items        = null,
                    Active       = newBool //////////////////////////CHECK BOXXXXXXXXXXXXXXXXXXXXXXXXXX
                };
                var validation = ValidateMenu(modelMenu);
                if (validation == true)
                {
                    await Services._MenuProxy.CreateMenuAsync(modelMenu);

                    dataGridItemList.Items.Clear();
                    var modelMenu1 = await Services._MenuProxy.GetAllMenusByRestaurantAsync(restaurantId);

                    foreach (ModelLibrary.Menu item in modelMenu1)
                    {
                        dataGridItemList.Items.Add(item);
                    }
                    ;
                }
                else
                {
                    MessageBox.Show("Validation did not pass!");
                }
            }
        }
        public void CreateMenu(ModelLibrary.Menu menu)
        {
            var menuCtrl = new MenuCtrl();

            menuCtrl.CreateMenu(menu);
        }