public ActionResult ShowAllTable(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Restaurant restaurant = db.Restaurants.Find(id);

            if (restaurant == null)
            {
                return(HttpNotFound());
            }
            RestaurantDetailsSearchViewModel model = new RestaurantDetailsSearchViewModel();
            ModelSearch search = new ModelSearch();

            model.Search         = search;
            model.Restaurant     = restaurant;
            model.TablesBySearch = restaurant.Tables.ToList();
            return(View("~/Views/Search/ViewDetailsSearchRestaurant.cshtml", model));
        }
Esempio n. 2
0
        // IdRest = item.Id, Search = Model.ModelSearch, TypeSearch = Model.TypeSearch
        //public ActionResult ViewDetailsSearch (int IdRest, ModelSearch Search, string TypeSearch)
        public ActionResult ViewDetailsSearchRestaurant(ViewDetailsSearchModel model)
        {
            Restaurant    restaurant     = db.Restaurants.Find(model.IdRest);
            IList <Table> tables         = null;
            int           dayWeekSearch  = -1;
            string        date           = String.Empty;
            DateTime      dateTimeSearch = DateTime.Now;

            if (model.Date != null)
            {
                dayWeekSearch = (int)model.Date.Value.DayOfWeek;
                date          = model.Date.Value.Date.ToString("dd/MM/yyyy");
                //date = model.Date.Value.Date.ToString("MM/dd/yyyy");
                if (model.Time != null)
                {
                    dateTimeSearch = (DateTime)(model.Date + model.Time);
                }
            }
            if (restaurant == null)
            {
                return(HttpNotFound());
            }
            switch (model.TypeSearch)
            {
            case "City":
            case "Object":
            case "CityObject":
            {
                return(RedirectToAction("Details", "Restaurant", new { id = model.IdRest }));
            }

            case "CityPerson":
            case "ObjectPerson":
            case "CityObjectPerson":
            {
                tables = restaurant.Tables.Where(t => t.MaxNumberPeople >= model.NumberPersons &&
                                                 t.MinNumberPeople <= model.NumberPersons && t.Availability == true).ToList();
            }
            break;

            case "CityDateTime":
            {
                // where ot.OrderTimeFrom <= dateTimeSearch && ot.OrderTimeTo > dateTimeSearch
                tables = restaurant.Tables.Where(t => !(t.OrderTables.Where(ot => ot.OrderTimeFrom <= dateTimeSearch && ot.OrderTimeTo > dateTimeSearch).Select(s => s.TableId)).Contains(t.Id) &&
                                                 t.Availability == true).ToList();
            } break;

            case "CityDate":
            {
                int workMinute = restaurant.WorkSchedules.Where(ws => ws.DayOfWeek == 8 || ws.DayOfWeek == dayWeekSearch).Sum(s => s.WorkMinutes);
                tables = restaurant.Tables.Where(t => (workMinute -
                                                       t.OrderTables.Where(ot => ot.OrderTimeFrom.Date == model.Date.Value.Date).Sum(m => m.BookingMinutes)) > 30 &&
                                                 t.Availability == true).ToList();
            } break;

            case "CityDatePerson":
            {
                int workMinute = restaurant.WorkSchedules.Where(ws => ws.DayOfWeek == 8 || ws.DayOfWeek == dayWeekSearch).Sum(s => s.WorkMinutes);
                tables = restaurant.Tables.Where(t => (workMinute -
                                                       t.OrderTables.Where(ot => ot.OrderTimeFrom.Date == model.Date.Value.Date).Sum(m => m.BookingMinutes)) > 30 &&
                                                 t.Availability == true &&
                                                 t.MaxNumberPeople >= model.NumberPersons &&
                                                 t.MinNumberPeople <= model.NumberPersons).ToList();
            } break;

            case "CityDateTimePerson":
            {
                tables = restaurant.Tables.Where(t =>
                                                 !(t.OrderTables.Where(ot => ot.OrderTimeFrom <= dateTimeSearch && ot.OrderTimeTo > dateTimeSearch).Select(s => s.TableId)).Contains(t.Id) &&
                                                 t.MaxNumberPeople >= model.NumberPersons &&
                                                 t.MinNumberPeople <= model.NumberPersons && t.Availability == true).ToList();
            } break;

            default:
                break;
            }
            ModelSearch search = new ModelSearch()
            {
                Place = model.Place, Date = model.Date, Time = model.Time, NumberPersons = model.NumberPersons
            };
            RestaurantDetailsSearchViewModel restaurantDetailsSearchViewModel = new RestaurantDetailsSearchViewModel()
            {
                Restaurant     = restaurant,
                Search         = search,
                TablesBySearch = tables
            };

            return(View(restaurantDetailsSearchViewModel));
        }