Пример #1
0
        public ActionResult OnGet()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToPage("/Account/Login", new { area = "Identity" }));
            }
            try
            {
                string cs = _config.GetConnectionString("Default");
                Restaurants = fd.GetRestaurantList(cs);
                var foodtypes = fd.GetFoodTypeList(cs);
                var when      = fd.GetWhenList(cs);

                FoodType = new List <SelectListItem>();
                When     = new List <SelectListItem>();

                foodtypes.ForEach(x =>
                {
                    FoodType.Add(new SelectListItem {
                        Value = x.FoodTypeID.ToString(), Text = x.FoodTypeText
                    });
                });
                when.ForEach(x =>
                {
                    When.Add(new SelectListItem {
                        Value = x.WhenID.ToString(), Text = x.WhenText
                    });
                });

                RandomRestaurant = fd.GetRandomRestaurant(cs);

                return(Page());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
Пример #2
0
        public async Task <IActionResult> OnGet()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToPage("/Account/Login", new { area = "Identity" }));
            }
            try
            {
                string cs = _config.GetConnectionString("Default");
                RestaurantDetails = fd.GetRestaurantDetails(cs, Id).FirstOrDefault();
                if (RestaurantDetails != null)
                {
                    if (RestaurantDetails != null)
                    {
                        var foodtypes = fd.GetFoodTypeList(cs);
                        var when      = fd.GetWhenList(cs);

                        //FoodType = FoodTypes.Where(x => x.FoodTypeID == RestaurantDetails.FoodTypeID).FirstOrDefault()?.FoodTypeText;

                        FoodTypes = new List <SelectListItem>();
                        When      = new List <SelectListItem>();

                        foodtypes.ForEach(x =>
                        {
                            FoodTypes.Add(new SelectListItem {
                                Value = x.FoodTypeID.ToString(), Text = x.FoodTypeText
                            });
                        });
                        when.ForEach(x =>
                        {
                            When.Add(new SelectListItem {
                                Value = x.WhenID.ToString(), Text = x.WhenText
                            });
                        });

                        //FoodTypes.ForEach(x =>
                        //{
                        //    if (RestaurantDetails.FoodTypeID == x.FoodTypeID)
                        //    {
                        //        FoodTypes.Add(new SelectListItem { Value = x.FoodTypeID.ToString(), Text = x.FoodTypeText, Selected = true });
                        //    }
                        //    else
                        //    {
                        //        FoodTypes.Add(new SelectListItem { Value = x.FoodTypeID.ToString(), Text = x.FoodTypeText });
                        //    }
                        //});
                        //Whens.ForEach(x =>
                        //{
                        //    if (RestaurantDetails.WhenID == x.WhenID)
                        //    {
                        //        Whens.Add(new SelectListItem { Value = x.WhenID.ToString(), Text = x.WhenName, Selected = true });
                        //    }
                        //    else
                        //    {
                        //        Whens.Add(new SelectListItem { Value = x.WhenID.ToString(), Text = x.WhenName });
                        //    }
                        //});
                    }
                }

                return(Page());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }