コード例 #1
0
        public IActionResult FinalizedOrder(string guestCode)
        {
            ctx.Guests.ToList();
            ctx.Dishes.ToList();
            ctx.SubDishTypes.ToList();
            ctx.Orders.ToList();
            ctx.DishTypes.ToList();

            Order g = ctx.Orders.Where(x => x.Owner.Code == guestCode).LastOrDefault();
            var   a = g.Finalized;


            if (a == null)
            {
                a = new List <Dish>();
            }

            List <Dish> b = a.ToList();

            OrderDishTypeViewModel c = new OrderDishTypeViewModel()
            {
                orderDishes = b,
            };

            //return View();
            return(View(new GuestCodeWithModel <OrderDishTypeViewModel>(c, guestCode)));
        }
コード例 #2
0
        public async Task <IActionResult> OrderOverview(string guestCode)
        {
            if (guestCode == null)
            {
                return(RedirectToAction("ErrorView"));
            }

            await DBCreationTask;

            //creating cache for entity framework

            ctx.Orders.ToList();
            ctx.Guests.ToList();
            ctx.DishTypes.ToList();
            ctx.SubDishTypes.ToList();
            ctx.Dishes.ToList();

            List <Order> order = ctx.Orders.ToList();

            List <Dish> selectedOrderItems = new List <Dish>();

            //ICollection<Dish> orders = ctx.Orders.Where(x => x.Owner.Code == guestCode).Select(x=>x.Finalized).LastOrDefault().ToList();

            //Dictionary<DishType, int> output = new Dictionary<DishType, int>();

            //foreach (var a in orders)
            //{
            //    output.Add(a, 0);
            //}
            //ctx.Orders.ToList();

            List <DishType>    allDishtypes = ctx.DishTypes.ToList();
            var                subDishes    = allDishtypes.Where(x => x.SubDishType != null).Select(x => x.SubDishType).ToList();
            List <SubDishType> uniqueDishes = subDishes.GroupBy(x => x.SubType).Select(x => x.FirstOrDefault()).ToList();

            Dictionary <DishType, int> output = new Dictionary <DishType, int>();

            foreach (var d in allDishtypes)
            {
                output.Add(d, 0);
            }

            ctx.Orders.ToList();

            Order order1 = ctx.Orders.Where(x => x.Owner.Code == guestCode).FirstOrDefault();

            ctx.Dishes.ToList();

            if (order1.Finalized != null)
            {
                ctx.DishTypes.ToList();
                List <Dish> a = order1.Finalized.ToList();

                var b = a.GroupBy(x => x.Course.Name).Select(x => new { type = x.LastOrDefault().Course, quantity = x.Count() }).ToList();

                foreach (var item in b)
                {
                    output[item.type] = item.quantity;
                }
            }

            var test = output;


            foreach (var item in order)
            {
                if (item.Owner.Code == guestCode && item.Selected != null)
                {
                    selectedOrderItems = item.Selected.ToList();
                }
            }

            OrderDishTypeViewModel orderDishTypeViewModel = new OrderDishTypeViewModel
            {
                orderDishes = selectedOrderItems
            };

            //return View();
            return(View(new GuestCodeWithModel <OrderDishTypeViewModel>(orderDishTypeViewModel, guestCode)));
        }