예제 #1
0
        // GET: Admin/MenuItem/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            MenuItem res = _menuFacade.FindById((int)id);

            if (res == null)
            {
                return(HttpNotFound());
            }

            ViewBag.dietInfoId = new SelectList(_dietInfoFacade.Get().OrderBy(d => d.Name), "id", "name", "Select diet information");
            ViewBag.categoryId = new SelectList(_menuItemTypeFacade.Get().OrderBy(d => d.Name), "id", "name", "Select category");

            Session["MenuItemId"] = res.Id;

            return(View(new MenuItemViewVM
            {
                Id = res.Id,
                Name = res.Name,
                Description = res.Description,
                ImageId = res.ImageId,
                Price = res.Price,
                DietInfo = res.DietInfo,
                Types = res.Types
            }));
        }
        private async Task GetValues()
        {
            int id = Arguments.GetInt("id");

            if (id > 0)
            {
                restaurant = await _restaurantFacade.FindById(id);

                types = await _menuItemTypeFacade.Get();
            }
        }
        //GET: Restaurant/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Restaurant restaurant = _restaurantFacade.FindById((int)id);

            if (restaurant == null)
            {
                return(HttpNotFound());
            }

            IEnumerable <MenuItemType> types      = _menuItemTypeFacade.Get();
            List <MenuIndexCategoryVM> categories = new List <MenuIndexCategoryVM>();

            foreach (var type in types)
            {
                categories.Add(new MenuIndexCategoryVM
                {
                    Category  = type,
                    MenuItems = restaurant.MenuItems.Where(m => m.Types.Where(t => t.Id == type.Id).Any()).Select(m => new MenuItemViewVM
                    {
                        Id          = m.Id,
                        Name        = m.Name,
                        Description = m.Description ?? "No Description",
                        Price       = m.Price,
                        ImageId     = m.ImageId,
                        DietInfoS   = m.DietInfo.Any() ? String.Join(", ", m.DietInfo.Select(d => d.Name)) : "N/A",
                        TypesS      = m.Types.Any() ? String.Join(", ", m.Types.Select(t => t.Name)) : "N/A"
                    })
                });
            }

            return(View(new RestaurantDetailsVM
            {
                Id = restaurant.Id,
                CompanyId = restaurant.CompanyId,
                Name = restaurant.Name,
                PhoneNo = restaurant.PhoneNo,
                AddressStreet = restaurant.AddressStreet,
                AddressTown = restaurant.AddressTown,
                AddressCounty = restaurant.AddressCounty,
                AddressPostalCode = restaurant.AddressPostalCode,
                MenuItems = categories.AsEnumerable(),
                TableCount = restaurant.Tables.Count(),
                ImageIds = restaurant.ImageIds
            }));
        }
 private async Task GetValues()
 {
     menuItemTypes = await _menuItemTypeFacade.Get();
 }
예제 #5
0
        // GET: Menu
        public ActionResult Index(MenuIndexVM indexVM = null)
        {
            IQueryable <MenuItem> res = _menuFacade.Get().AsQueryable();

            ViewBag.Type     = new SelectList(_menuItemTypeFacade.Get().OrderBy(d => d.Name), "id", "name", "Select category");
            ViewBag.DietInfo = new SelectList(_dietInfoFacade.Get().OrderBy(d => d.Name), "id", "name", "Select diet information");

            if (indexVM != null)
            {
                if (indexVM.Type != null)
                {
                    res = res.Where(m => m.Types.Select(mm => mm.Id).ToList().Contains((int)indexVM.Type));
                }

                if (indexVM.DietInfo != null)
                {
                    res = res.Where(m => m.DietInfo.Select(mm => mm.Id).ToList().Contains((int)indexVM.DietInfo));
                }

                if (indexVM.StartPrice != null)
                {
                    res = res.Where(m => m.Price >= indexVM.StartPrice);
                }

                if (indexVM.EndPrice != null)
                {
                    res = res.Where(m => m.Price <= indexVM.EndPrice);
                }

                IEnumerable <MenuItemType> types      = _menuItemTypeFacade.Get();
                List <MenuIndexCategoryVM> categories = new List <MenuIndexCategoryVM>();

                foreach (var type in types)
                {
                    categories.Add(new MenuIndexCategoryVM
                    {
                        Category  = type,
                        MenuItems = res.Where(m => m.Types.Where(t => t.Id == type.Id).Any()).Select(m => new MenuItemViewVM
                        {
                            Id          = m.Id,
                            Name        = m.Name,
                            Description = m.Description ?? "No Description",
                            Price       = m.Price,
                            ImageId     = m.ImageId,
                            DietInfoS   = m.DietInfo.Any() ? String.Join(", ", m.DietInfo.Select(d => d.Name)) : "N/A",
                            TypesS      = m.Types.Any() ? String.Join(", ", m.Types.Select(t => t.Name)) : "N/A"
                        })
                    });
                }

                return(View(categories.AsEnumerable()));
            }

            return(View(new MenuIndexVM
            {
                MenuItems = res.Select(m => new MenuItemViewVM
                {
                    Id = m.Id,
                    Name = m.Name,
                    Description = m.Description ?? "No Description",
                    Price = m.Price,
                    ImageId = m.ImageId,
                    DietInfoS = m.DietInfo.Any() ? String.Join(", ", m.DietInfo.Select(d => d.Name)) : "N/A",
                    TypesS = m.Types.Any() ? String.Join(", ", m.Types.Select(t => t.Name)) : "N/A"
                }).AsEnumerable()
            }));
        }
        // GET: Admin/MenuItemCategory
        public ActionResult Index()
        {
            IEnumerable <MenuItemType> res = _menuItemTypeFacade.Get();

            return(View(res));
        }
        private void Setup()
        {
            int id = Arguments.GetInt("id");

            if (id > 0)
            {
                LibBookingService.Dtos.Restaurant restaurant = _restaurantFacade.FindById(id).Result;
                //LibBookingService.Dtos.Restaurant restaurant = new LibBookingService.Dtos.Restaurant
                //{
                //    Id = 1,
                //    CompanyId = 2,
                //    Name = "Restaurant 1",
                //    PhoneNo = "01429354096",
                //    AddressStreet = "21 Restaurant Road",
                //    AddressTown = "Hartlepool",
                //    AddressCounty = "Cleveland",
                //    AddressPostalCode = "TS248GX",
                //    MenuItems = new List<MenuItem>
                //    {
                //        new MenuItem { Id = 4, Description = "A fresh bowl of caesar salad", Price = 4.38, ImageId = 4, Name = "Caesar Salad", DietInfo = new List<DietInfo> { new DietInfo { Name = "Vegan", Id = 2 } }, Types = new List<MenuItemType> { new MenuItemType { Id = 1, Name = "Starter" } } },
                //        new MenuItem { Id = 5, Description = null, Price = 3.59, ImageId = 5, Name = "Chocolate Fudge Cake", DietInfo = new List<DietInfo> { new DietInfo { Name = "Contains Dairy", Id = 4 } }, Types = new List<MenuItemType> { new MenuItemType { Id = 3, Name = "Dessert" }, new MenuItemType { Id = 4, Name = "Special" } } },
                //        new MenuItem { Id = 2, Description = "A fresh cod fillet served with thick cut chips and mushy peas", Price = 6.00, ImageId = 2, Name = "Fish and Chips", DietInfo = new List<DietInfo> { }, Types = new List<MenuItemType> { new MenuItemType { Id = 2, Name = "Main" }, new MenuItemType { Id = 4, Name = "Special" } } }
                //    }
                //};

                IEnumerable <MenuItemType> types = _menuItemTypeFacade.Get().Result;
                //IEnumerable<MenuItemType> types = new List<MenuItemType>
                //{
                //    new MenuItemType { Id = 1, Name = "Starter" },
                //    new MenuItemType { Id = 2, Name = "Main" },
                //    new MenuItemType { Id = 3, Name = "Dessert" },
                //    new MenuItemType { Id = 4, Name = "Special" }
                //}.AsEnumerable();

                newBooking.RestaurantId = restaurant.Id;

                view.FindViewById <TextView>(Resource.Id.booking_new_restaurant_name).Text    = restaurant.Name;
                view.FindViewById <TextView>(Resource.Id.booking_new_restaurant_address).Text = restaurant.AddressStreet + ", " + restaurant.AddressTown + ", " + restaurant.AddressCounty + ", " + restaurant.AddressPostalCode;

                Spinner time          = view.FindViewById <Spinner>(Resource.Id.booking_new_time);
                Spinner paymentMethod = view.FindViewById <Spinner>(Resource.Id.booking_new_payment_method);

                List <TimeSpan> times = GetTimes();

                List <PaymentMethod> paymentMethods = new List <PaymentMethod>
                {
                    new PaymentMethod {
                        Name = "Please select a payment method"
                    }
                };
                paymentMethods.AddRange(_paymentFacade.GetPaymentMethod().Result);

                var timeAdapter = new ArrayAdapter <TimeSpan>(Activity, Android.Resource.Layout.SimpleSpinnerDropDownItem, times);
                timeAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
                time.Adapter = timeAdapter;

                var paymentMethodAdapter = new ArrayAdapter <PaymentMethod>(Activity, Android.Resource.Layout.SimpleSpinnerDropDownItem, paymentMethods);
                paymentMethodAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
                paymentMethod.Adapter = paymentMethodAdapter;

                int initialSpinnerPosition = time.SelectedItemPosition;
                time.ItemSelected += (sender, args) =>
                {
                    if (args.Position != initialSpinnerPosition)
                    {
                        newBooking.StartTime = times[args.Position];
                    }
                };

                paymentMethod.ItemSelected += (sender, args) =>
                {
                    if (args.Position != initialSpinnerPosition)
                    {
                        newPayment.PaymentMethod = paymentMethods[args.Position];
                    }
                };

                LinearLayout layoutContainer = view.FindViewById <LinearLayout>(Resource.Id.booking_new_container);

                //Dictionary<MenuItemType, IEnumerable<MenuItem>> categories = new Dictionary<MenuItemType, IEnumerable<MenuItem>>();

                //foreach (var type in types)
                //{
                //    categories.Add(type, restaurant.MenuItems.Where(m => m.Types.Where(t => t.Id == type.Id).Any()));
                //}

                //foreach (KeyValuePair<MenuItemType, IEnumerable<MenuItem>> entry in categories)
                //{
                //    TextView lbl = new TextView(Activity);
                //    lbl.Text = entry.Key.Name;

                //    LinearLayout menuItem = new LinearLayout(Activity);
                //    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent);
                //    menuItem.LayoutParameters = layoutParams;
                //    menuItem.WeightSum = 4;

                //}

                miCounts = new Dictionary <MenuItem, int>();

                foreach (var mi in restaurant.MenuItems)
                {
                    View menuItem = LayoutInflater.From(Activity).Inflate(Resource.Layout.booking_new_menu, null);
                    LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent)
                    {
                        TopMargin = 16
                    };
                    menuItem.LayoutParameters = layout;

                    menuItem.FindViewById <TextView>(Resource.Id.booking_new_menu_item).Text = mi.Name + " - " + String.Join(", ", mi.Types.Select(t => t.Name));
                    miCounts.Add(mi, 0);

                    TextView    miCount = menuItem.FindViewById <TextView>(Resource.Id.booking_new_menu_item_count);
                    FrameLayout miMinus = menuItem.FindViewById <FrameLayout>(Resource.Id.booking_new_menu_item_remove);
                    FrameLayout miAdd   = menuItem.FindViewById <FrameLayout>(Resource.Id.booking_new_menu_item_add);

                    miAdd.Click += delegate
                    {
                        miCounts[mi] += 1;
                        miCount.Text  = miCounts[mi].ToString();
                    };

                    miMinus.Click += delegate
                    {
                        if (miCounts[mi] > 0)
                        {
                            miCounts[mi] = miCounts[mi] - 1;
                        }

                        miCount.Text = miCounts[mi].ToString();
                    };

                    layoutContainer.AddView(menuItem);
                }
            }
        }