private bool ValidatePrice(ModelLibrary.Price price)
        {
            var context = new ValidationContext(price, null, null);
            var result  = new List <System.ComponentModel.DataAnnotations.ValidationResult>();

            return(Validator.TryValidateObject(price, context, result, true));
        }
        private async void buttonCreate_Click(object sender, RoutedEventArgs e)
        {
            var    selectedItem = (ModelLibrary.Item)dataGridItemList.SelectedItem;
            double price;
            bool   success = double.TryParse(textBoxNamePrice.Text, out price);

            if (success)
            {
                var priceObj = new ModelLibrary.Price
                {
                    VarPrice  = price,
                    StartDate = DateTime.Now,
                    EndDate   = DateTime.Now.AddYears(100)
                };

                var item = new ModelLibrary.Item
                {
                    Description = textBoxDescription.Text,
                    Name        = textBoxName.Text,
                    Price       = priceObj
                };

                //var itemCat = (ModelLibrary.ItemCat)comboBoxCategory.SelectedItem;
                if (comboBoxCategory.SelectedItem != null)
                {
                    var validation      = ValidateItem(item);
                    var priceValidation = ValidatePrice(priceObj);
                    if (validation == true && priceValidation)
                    {
                        var selectedCategory = (ModelLibrary.ItemCat)comboBoxCategory.SelectedItem;
                        await Services._ItemProxy.CreateItemAsync(item, amenuId, selectedCategory.Id);

                        var returnedItem = await Services._ItemProxy.GetItemByNameAsync(item.Name);

                        await Services._PriceProxy.CreatePriceAsync(priceObj, returnedItem.Id);

                        dataGridItemList.Items.Clear();
                        var modelMenu = await Services._ItemProxy.GetAllItemsByMenuAsync(amenuId);

                        foreach (Item itemo in modelMenu)
                        {
                            dataGridItemList.Items.Add(itemo);
                        }
                        ;
                    }
                    else
                    {
                        MessageBox.Show("Validation did not pass");
                    }
                }
                else
                {
                    MessageBox.Show("Select category");
                }
            }
            else
            {
                MessageBox.Show("Price needs to be a double(NN.N(N))");
            }
        }
Beispiel #3
0
        public void CreatePrice(ModelLibrary.Price price, int itemId) //ModelLibrary.Price price, int itemId
        {
            var priceCtrl = new PriceCtrl();

            priceCtrl.CreatePrice(price, itemId);
            //priceCtrl.CreatePrice(price, itemId);
        }
        public ModelLibrary.Price GetItemPrice(int itemId)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();
            var prices = db.Prices.Where(p => p.itemId == itemId).OrderByDescending(p => p.startDate);
            var price  = prices.First();

            if (price != null)
            {
                ModelLibrary.Price varPrice = new ModelLibrary.Price
                {
                    StartDate = price.startDate,
                    EndDate   = price.endDate,
                    VarPrice  = price.price1
                };

                return(varPrice);
            }
            return(null);
        }
        public void Create_Item_With_Price_Service_Test()
        {
            ItemCtrl itemCtrl = new ItemCtrl();
            ItemDb   itemDb   = new ItemDb();

            //Setup
            #region creates ModelItem, ModelPrice
            ModelLibrary.Price newPrice = new ModelLibrary.Price
            {
                VarPrice  = 12,
                StartDate = DateTime.Now,
                EndDate   = DateTime.Now.AddYears(100)
            };
            ModelLibrary.Item newItem = new ModelLibrary.Item
            {
                Name        = "testName",
                Description = "testDescr",
                Price       = newPrice
            };
            ItemService  itemService  = new ItemService();
            PriceService priceService = new PriceService();
            #endregion
            //Act
            JustFeastDbDataContext db = new JustFeastDbDataContext();
            itemService.CreateItem(newItem, 1000000, 1000000);
            var checkItem = db.Items.SingleOrDefault(p => p.name == newItem.Name && p.description == newItem.Description);
            priceService.CreatePrice(newPrice, checkItem.id);


            //Get Item(1,1,"PerfectlyGoodName");

            //Assert

            Assert.IsNotNull(db.Items.SingleOrDefault(p => p.id == checkItem.id));
            Assert.IsNotNull(db.Prices.Where(p => p.itemId == checkItem.id).OrderByDescending(p => p.startDate).First());
        }
        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);
        }
        private async void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            double price;

            ModelLibrary.Item selectedItem = (ModelLibrary.Item)dataGridItemList.SelectedItem;


            bool success = double.TryParse(textBoxNamePrice.Text, out price);

            if (success)

            {
                ModelLibrary.Price priceo = new ModelLibrary.Price
                {
                    VarPrice = double.Parse(textBoxNamePrice.Text)
                };

                ModelLibrary.Item updatedItem = new ModelLibrary.Item
                {
                    Id          = selectedItem.Id,
                    Description = textBoxDescription.Text,
                    Name        = textBoxName.Text,
                    Price       = priceo
                };
                await Services._PriceProxy.UpdatePriceAsync(priceo, selectedItem.Id);

                var catItem       = (ModelLibrary.ItemCat)comboBoxCategory.SelectedItem;
                var selectedCatId = catItem == null ? 0 : catItem.Id;

                if (catItem != null)
                {
                    var itemValidation  = ValidateItem(updatedItem);
                    var priceValidation = ValidatePrice(priceo);
                    if (itemValidation == true && priceValidation == true)
                    {
                        await Services._ItemProxy.UpdateItemAsync(updatedItem, amenuId, selectedCatId); // IFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

                        dataGridItemList.Items.Clear();
                        var modelMenu = await Services._ItemProxy.GetAllItemsByMenuAsync(amenuId);

                        foreach (Item itemo in modelMenu)
                        {
                            dataGridItemList.Items.Add(itemo);
                        }
                        ;
                    }
                    else
                    {
                        MessageBox.Show("Validation did not pass!");
                    }
                }
                else
                {
                    MessageBox.Show("Select category");
                }
            }
            else
            {
                MessageBox.Show("Price needs to be a double(NN.N(N))");
            }
        }
Beispiel #8
0
        public void UpdatePrice(ModelLibrary.Price price, int itemId)
        {
            var priceCtrl = new PriceCtrl();

            priceCtrl.UpdatePrice(price, itemId);
        }