public ActionResult <List <MenuPreBuilt> > GetAll()
 {
     log.Info("Retreiving all Menu from database");
     return(Repo.GetAllMenuPreBuilt().ToList());
 }
Пример #2
0
        // GET: api/UserHaasPreBuildMenuAndInv

        // GET: api/Inventory/5

        public ActionResult <UserHasPreBuildMenuAndInvModel> GetUserPreMade(string test)
        {
            var user         = Repo.GetUserByUsername(test);
            var inv          = Repo.GetInventories().ToList();
            var loc          = Repo.GetLocations().ToList();
            var userId       = user.UserId;
            var orderList    = Repo.GetOrders().Where(x => x.UserId == userId).ToList();
            var count        = orderList.Count;
            var preBuiltList = Repo.GetMenuPreBuiltHasOrders();
            var getPreOrder  = new List <MenuPrebuiltHasOrders>();

            foreach (var item in orderList)
            {
                foreach (var item2 in preBuiltList)
                {
                    if (item.OrderId == item2.OrdersId)
                    {
                        getPreOrder.Add(item2);
                    }
                }
            }


            #region
            decimal[] Price = new decimal[count];
            for (int i = 0; i < count; i++)
            {
                Random  rnd    = new Random();
                decimal number = rnd.Next(1, 13);
                Price[i] = number;
            }
            #endregion

            var getPreOrderMenu = Repo.GetAllMenuPreBuilt().ToList();


            IEnumerable <LocationModel> location2 = loc.Select(x => new LocationModel
            {
                Id = x.Id, City = x.City
            });
            IEnumerable <InventoryModel> inventory2 = inv.Select(x => new InventoryModel
            {
                Id = x.Id, IngredientName = x.IngredientName, Price = x.Price
            });
            IEnumerable <OrderModel> order2 = orderList.Select(x => new OrderModel
            {
                OrderId = x.OrderId, UserId = x.UserId, LocationId = x.LocationId, OrderTime = x.OrderTime
            });
            IEnumerable <MenuPrebuiltHasOrdersModel> PreOr = getPreOrder.Select(x => new MenuPrebuiltHasOrdersModel
            {
                Id = x.Id, MenuPreBuildId = x.MenuPreBuildId, OrdersId = x.OrdersId
            });
            IEnumerable <MenuPreBuiltModel> PreBuilt = getPreOrderMenu.Select(x => new MenuPreBuiltModel
            {
                Id = x.Id, NameOfMenu = x.NameOfMenu, Price = x.Price, TwentyOneOver = x.TwentyOneOver
            });


            UserHasPreBuildMenuAndInvModel model = new UserHasPreBuildMenuAndInvModel
            {
                User             = user.Username.ToString(),
                Location         = location2,
                Inventories      = inventory2,
                Order            = order2,
                PreBuilt         = PreBuilt,
                PreBuiltHasOrder = PreOr,
                Price            = Price
            };

            return(model);
        }