Exemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "")
            {
                MessageBox.Show("Please fill food's name.");
                return;
            }

            DAL.MenuItem newMenuItem = new DAL.MenuItem
            {
                Name   = txtName.Text,
                Price  = txtPrice.Value,
                Image  = Utilities.UtilsImage.ImageToByteArray(this.pictureBox.Image),
                MenuID = menu.ID
            };

            MenuItemBLL menuItemBLL = new MenuItemBLL();

            if (this.MenuItem == null)
            {
                menuItemBLL.CreateMenuItem(newMenuItem);
            }
            else
            {
                menuItemBLL.Update(this.MenuItem, newMenuItem);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 2
0
        public void TestCRUDMenuItem()
        {
            List <Menu> menus = menuBLL.ListMenu();

            int    menuIDTest     = menus[0].ID;
            string nameTest       = "Phá lấu bò gà heo";
            int    priceTest      = 30000;
            int    priceAfterTest = 25000;
            string rootPath       = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.Parent.FullName;

            byte[] imageTest = File.ReadAllBytes(rootPath + "/data/images/com-chien-ca-man.jpg");

            MenuItem menuItemTest = new MenuItem();

            menuItemTest.MenuID     = menuIDTest;
            menuItemTest.Name       = nameTest;
            menuItemTest.Price      = priceTest;
            menuItemTest.PriceAfter = priceAfterTest;
            menuItemTest.Image      = imageTest;

            MenuItem        menuItemExpected = menuItemBLL.CreateMenuItem(menuItemTest);
            bool            isCreated        = false;
            List <MenuItem> menuItems        = menuItemBLL.FindByMenuID(menus[0]);

            for (int i = 0; i < menuItems.Count; i++)
            {
                if (menuItemExpected.ID == menuItems[i].ID &&
                    menuItemExpected.MenuID == menuItems[i].MenuID &&
                    menuItemExpected.Name == menuItems[i].Name &&
                    menuItemExpected.Price == menuItems[i].Price &&
                    menuItemExpected.PriceAfter == menuItems[i].PriceAfter &&
                    menuItemExpected.Image == imageTest)
                {
                    isCreated = true;
                }
            }

            Assert.AreEqual(true, isCreated);

            TestUpdateMenuItem(menuItemExpected);
        }