public IHttpActionResult PutMenuItemIngredient(int id, MenuItemIngredient menuItemIngredient)
        {
            if (!Global.CheckUserIDAndPasswordWithSiteID(db, menuItemIngredient.UILoginUserID, menuItemIngredient.UILoginPassword, menuItemIngredient.SiteID, "PutMenuItemIngredient"))
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != menuItemIngredient.ID)
            {
                return(BadRequest());
            }

            MenuItemIngredient mii = db.MenuItemIngredients.AsNoTracking().SingleOrDefault(p => p.ID == id);

            if (mii == null)
            {
                return(NotFound());
            }
            if (mii.SiteID != menuItemIngredient.SiteID)
            {
                return(BadRequest());
            }
            User user = db.Users.Find(menuItemIngredient.UILoginUserID);

            if (!user.IsRootUser && !user.IsSiteAdmin && mii.EntryByUserID != user.ID)
            {
                return(BadRequest());
            }
            db.Entry(menuItemIngredient).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MenuItemIngredientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public void GetMenuItemsId_ReturnsMenuItemsId_Int()
        {
            //Arrange
            string             menuItemIngredientDescription = "Avocadoes";
            int                menuItemsId           = 1;
            int                storeId               = 1;
            MenuItemIngredient newMenuItemIngredient = new MenuItemIngredient(menuItemIngredientDescription, menuItemsId, storeId);

            //Act
            int result = newMenuItemIngredient.GetMenuItemsId();

            //Assert
            Assert.AreEqual(menuItemsId, result);
        }
Beispiel #3
0
        public ActionResult Show(int menuItemIngredientId)
        {
            MenuItemIngredient menuItemIngredient = MenuItemIngredient.Find(menuItemIngredientId);
            int      menuItemId = menuItemIngredient.GetMenuItemsId();
            MenuItem menuItem   = MenuItem.Find(menuItemId);
            int      storeId    = menuItemIngredient.GetStoreId();
            Store    store      = Store.Find(storeId);
            Dictionary <string, object> model = new Dictionary <string, object>();

            model.Add("menuItemIngredient", menuItemIngredient);
            model.Add("menuItem", menuItem);
            model.Add("store", store);
            return(View(model));
        }
        public IHttpActionResult PostMenuItemIngredient(MenuItemIngredient menuItemIngredient)
        {
            if (!Global.CheckUserIDAndPasswordWithSiteID(db, menuItemIngredient.UILoginUserID, menuItemIngredient.UILoginPassword, menuItemIngredient.SiteID, "PostMenuItemIngredient"))
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.MenuItemIngredients.Add(menuItemIngredient);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = menuItemIngredient.ID }, menuItemIngredient));
        }
        public void Find_ReturnsMenuItemIngredientInDatabase_MenuItemIngredient()
        {
            //Arrange
            string             menuItemIngredientDescription = "Avocadoes";
            int                menuItemsId           = 1;
            int                storeId               = 1;
            MenuItemIngredient newMenuItemIngredient = new MenuItemIngredient(menuItemIngredientDescription, menuItemsId, storeId);

            newMenuItemIngredient.Save();

            //Act
            MenuItemIngredient foundMenuItemIngredient = MenuItemIngredient.Find(newMenuItemIngredient.GetId());

            //Assert
            Assert.AreEqual(newMenuItemIngredient, foundMenuItemIngredient);
        }
        public void SetIngredientDescription_SetIngredientDescription_String()
        {
            //Arrange
            string             menuItemIngredientDescription = "Avocadoes";
            int                menuItemsId           = 1;
            int                storeId               = 1;
            MenuItemIngredient newMenuItemIngredient = new MenuItemIngredient(menuItemIngredientDescription, menuItemsId, storeId);

            //Act
            string updatedIngredientDescription = "Tomatoes";

            newMenuItemIngredient.SetIngredientDescription(updatedIngredientDescription);
            string result = newMenuItemIngredient.GetIngredientDescription();

            //Assert
            Assert.AreEqual(updatedIngredientDescription, result);
        }
        public void SetStoreId_SetStoreId_Int()
        {
            //Arrange
            string             menuItemIngredientDescription = "Avocadoes";
            int                menuItemsId           = 1;
            int                storeId               = 1;
            MenuItemIngredient newMenuItemIngredient = new MenuItemIngredient(menuItemIngredientDescription, menuItemsId, storeId);

            //Act
            int updatedStoreId = 2;

            newMenuItemIngredient.SetStoreId(updatedStoreId);
            int result = newMenuItemIngredient.GetStoreId();

            //Assert
            Assert.AreEqual(updatedStoreId, result);
        }
        public void Save_SavesMenuItemIngredientToDatabase_MenuItemIngredientList()
        {
            //Arrange
            string             menuItemIngredientDescription = "Avocadoes";
            int                menuItemsId           = 1;
            int                storeId               = 1;
            MenuItemIngredient newMenuItemIngredient = new MenuItemIngredient(menuItemIngredientDescription, menuItemsId, storeId);

            newMenuItemIngredient.Save();

            //Act
            List <MenuItemIngredient> result   = MenuItemIngredient.GetAll();
            List <MenuItemIngredient> testList = new List <MenuItemIngredient> {
                newMenuItemIngredient
            };

            //Assert
            CollectionAssert.AreEqual(testList, result);
        }
        public void DeleteAll_DeletesAllMenuItemIngredientsFromDatabase()
        {
            //Arrange
            string             menuItemIngredientDescription = "Avocadoes";
            int                menuItemsId           = 1;
            int                storeId               = 1;
            MenuItemIngredient newMenuItemIngredient = new MenuItemIngredient(menuItemIngredientDescription, menuItemsId, storeId);

            newMenuItemIngredient.Save();
            MenuItemIngredient.DeleteAll();

            //Act
            List <MenuItemIngredient> newList = new List <MenuItemIngredient> {
                newMenuItemIngredient
            };
            List <MenuItemIngredient> resultList = MenuItemIngredient.GetAll();

            //Assert
            CollectionAssert.AreNotEqual(newList, resultList);
        }
Beispiel #10
0
 public MenuItemIngredientsControllerTest()
 {
     DBConfiguration.ConnectionString = "server=localhost;user id=root;password=root;port=8889;database=event_planner_tests;";
     _controller         = new MenuItemIngredientsController();
     _menuItemIngredient = new MenuItemIngredient("TestDescription", 0, 0);
 }
Beispiel #11
0
 public ActionResult DeleteAll()
 {
     MenuItemIngredient.DeleteAll();
     return(RedirectToAction("Index"));
 }
Beispiel #12
0
        public ActionResult Index()
        {
            List <MenuItemIngredient> allMenuItemIngredients = MenuItemIngredient.GetAll();

            return(View(allMenuItemIngredients));
        }
 /// <summary>
 /// need to decide how to handle the
 /// </summary>
 /// <param name="upd"></param>
 private void UpdateIngredientXref(UpdateObject upd)
 {
     var linkedingredients = new MenuItemIngredient();
         linkedingredients.menuitemingredientid = upd.xrefpk;
         linkedingredients.menuitemid = upd.menuid;
         linkedingredients.ingredientid = upd.ingredientid;
         linkedingredients.sortindex = upd.sortindex;
         linkedingredients.ServiceObjectId = upd.ServiceObjectId ?? new Guid();
         linkedingredients.DataObjectId = upd.DataObjectId ?? new Guid();
         linkedingredients.Insert();
 }
 public void Dispose()
 {
     MenuItemIngredient.ClearAll();
 }
Beispiel #15
0
        public static void Initialize(RestaurantContext context)
        {
            context.Database.EnsureCreated();

            //Look for any orders
            if (context.CustomerOrders.Any())
            {
                return;   //DB has been seeded
            }

            //Define restaurants
            var restaurants = new Restaurant[]
            {
                new Restaurant {
                    Name = "Stevens Point"
                },
                new Restaurant {
                    Name = "Wausau"
                }
            };

            //Iterate through Restaurant entities and add to DB context
            foreach (Restaurant r in restaurants)
            {
                context.Restaurants.Add(r);
            }

            //Save changes to DB
            context.SaveChanges();

            //Define ingredients
            var ingredients = new Ingredient[]
            {
                new Ingredient {
                    Name = "Beef", StockLevel = 10, WholeSalePrice = 3.99M
                },
                new Ingredient {
                    Name = "Chicken", StockLevel = 10, WholeSalePrice = 1.99M
                },
                new Ingredient {
                    Name = "Rice", StockLevel = 10, WholeSalePrice = 0.99M
                }
            };

            foreach (Ingredient i in ingredients)
            {
                context.Ingredients.Add(i);
            }

            context.SaveChanges();

            //Define menu items
            var fooditems = new MenuItem[]
            {
                new MenuItem {
                    Name = "Beef and Rice", Description = "Delicious!", Price = 9.99M
                },
                new MenuItem {
                    Name = "Chicken and Rice", Description = "Even More Delicious!", Price = 8.99M
                }
            };

            foreach (MenuItem f in fooditems)
            {
                context.MenuItems.Add(f);
            }

            context.SaveChanges();

            //Join table between Menu Items and Ingredients
            var ingredientmappings = new MenuItemIngredient[]
            {
                new MenuItemIngredient {
                    MenuItemID = 1, IngredientID = 1, Quantity = 1
                },
                new MenuItemIngredient {
                    MenuItemID = 1, IngredientID = 3, Quantity = 1
                },
                new MenuItemIngredient {
                    MenuItemID = 2, IngredientID = 2, Quantity = 1
                },
                new MenuItemIngredient {
                    MenuItemID = 2, IngredientID = 3, Quantity = 1
                }
            };

            foreach (MenuItemIngredient im in ingredientmappings)
            {
                context.MenuItemIngredients.Add(im);
            }

            context.SaveChanges();

            //Order statuses
            var orderstatuses = new OrderStatus[]
            {
                new OrderStatus {
                    StatusText = "Ordered"
                },
                new OrderStatus {
                    StatusText = "Being prepared"
                },
                new OrderStatus {
                    StatusText = "Ready for pickup"
                }
            };

            foreach (OrderStatus os in orderstatuses)
            {
                context.OrderStatuses.Add(os);
            }

            context.SaveChanges();

            //Cart
            var cart = new Cart[]
            {
                new Cart {
                }
            };

            foreach (Cart ca in cart)
            {
                context.MyCart.Add(ca);
            }

            context.SaveChanges();

            //Orders
            var customerorders = new CustomerOrder[]
            {
                new CustomerOrder {
                    Email = "*****@*****.**", OrderDate = DateTime.Now, OrderStatusID = 1, RestaurantID = 1, CCExpirationDate = DateTime.Today, CCNumber = "1111222233334444"
                },
                new CustomerOrder {
                    Email = "*****@*****.**", OrderDate = DateTime.Now, OrderStatusID = 1, RestaurantID = 2, CCExpirationDate = DateTime.Today, CCNumber = "5555222233334444"
                }
            };

            foreach (CustomerOrder co in customerorders)
            {
                context.CustomerOrders.Add(co);
            }

            context.SaveChanges();

            //Join table between Orders and Menu Items

            var orderitems = new OrderItem[]
            {
                new OrderItem {
                    CustomerOrderID = 1, MenuItemID = 1, Quantity = 3
                },
                new OrderItem {
                    CustomerOrderID = 2, MenuItemID = 2, Quantity = 1
                }
            };

            foreach (OrderItem oi in orderitems)
            {
                context.OrderItems.Add(oi);
            }

            context.SaveChanges();
        }