コード例 #1
0
ファイル: HomeNewController.cs プロジェクト: carrental/mvc
        /// <summary>
        /// Select cars
        /// </summary>
        /// <param name="context">context</param>
        /// <param name="state">state</param>
        /// <returns>IQueryable of car</returns>
        protected IQueryable <CarRental.Data.Car> _SelectCars(CarRental.Data.CarRentalDb context, FormState state)
        {
            IQueryable <CarRental.Data.Car> cars = from car in context.Cars select car;

            if (state == null)
            {
                return(cars);
            }

            //filter by car type
            if (state.Type != null)
            {
                cars = cars.Where(c => c.TypeId == state.Type.Value);
            }

            //filter by date
            if (state.DateFilter && state.DateFrom != null && state.DateTo != null)
            {
                cars = from car in cars
                       where car.Orders.Where(o => o.end_date > state.DateFrom.Value && o.start_date < state.DateTo.Value).Count() == 0
                       select car;
            }

            //filter by price
            if (state.MinPrice != null && state.MaxPrice != null)
            {
                cars = cars.Where(c => c.Price <= state.MaxPrice.Value && c.Price >= state.MinPrice.Value);
            }

            return(cars);
        }
コード例 #2
0
ファイル: HomeNewController.cs プロジェクト: carrental/mvc
        public ActionResult FilterCars(FormState state)
        {
            var context = new CarRental.Data.CarRentalDb();
            var cars    = _SelectCars(context, _PrepareFormState(state));

            return(Content(new SchedulerAjaxData(cars), "text/json"));
        }
コード例 #3
0
ファイル: HomeNewController.cs プロジェクト: carrental/mvc
 /// <summary>
 /// Update view data
 /// </summary>
 /// <param name="scheduler">scheduler</param>
 /// <param name="context">context</param>
 /// <param name="state">state</param>
 protected void _UpdateViewData(DHXScheduler scheduler, CarRental.Data.CarRentalDb context, FormState state)
 {
     ViewData["PriceRange"] = _CreatePriceSelect(scheduler, state.PriceRange);
     ViewData["Type"]       = _CreateTypeSelect(context.Types, state, context);
     ViewData["DateFrom"]   = state.DateFrom;
     ViewData["DateTo"]     = state.DateTo;
     ViewData["TimeFrom"]   = _CreateTimeSelect(scheduler, state.TimeFrom);
     ViewData["TimeTo"]     = _CreateTimeSelect(scheduler, state.TimeTo);
     ViewData["DateFilter"] = state.DateFilter;
 }
コード例 #4
0
ファイル: HomeNewController.cs プロジェクト: carrental/mvc
        protected IEnumerable <CarRental.Data.Order> _GetOrders(CarRental.Data.CarRentalDb context, FormState state)
        {
            // all orders
            var orders = from order in context.Orders select order;

            //filter by car type
            if (state.DateFilter && state.DateFrom != null && state.DateTo != null)
            {
                //select cars, which are available in specified time range
                orders = orders.Where(o => o.end_date > state.DateFrom.Value && o.start_date < state.DateTo.Value);
            }

            return(orders.ToList());
        }
コード例 #5
0
ファイル: HomeNewController.cs プロジェクト: carrental/mvc
        /// <summary>
        /// Index
        /// </summary>
        /// <returns>View with model</returns>
        public ActionResult Index(FormState state)
        {
            if (!isDefaultFilter(state))
            {
                ViewData["filtered"] = true;
            }

            state = _PrepareFormState(state);
            var scheduler = new DHXScheduler();

            scheduler.Extensions.Add(SchedulerExtensions.Extension.Collision);
            scheduler.Extensions.Add(SchedulerExtensions.Extension.Minical);

            scheduler.Extensions.Add(SchedulerExtensions.Extension.Tooltip);



            scheduler.Extensions.Add(SchedulerExtensions.Extension.ActiveLinks);
            scheduler.Extensions.Add(SchedulerExtensions.Extension.LiveUpdates);
            scheduler.Config.fix_tab_position = false;
            scheduler.EnableDynamicLoading(SchedulerDataLoader.DynamicalLoadingMode.Week);
            //call custom template initialization
            scheduler.BeforeInit.Add("defineTemplates();");
            scheduler.AfterInit.Add("afterInit()");
            scheduler.Config.time_step = 60;
            scheduler.InitialValues.Add("text", "");

            //set max dispay events in month
            scheduler.Config.max_month_events = 4;

            //if 'Pick Up Date' selected - make it initial date for calendar
            if (state.DateFrom != null)
            {
                scheduler.InitialDate = state.DateFrom.Value;
            }

            //var context = new RentalDataContext();
            var context = new CarRental.Data.CarRentalDb();

            //selecting cars according to form values
            var cars = _SelectCars(context, state).ToList();

            //if no cars found - show message and load default set
            if (cars.Count() == 0)
            {
                ViewData["Message"] = "Nothing was found on your request";
                cars = _SelectCars(context).ToList();//select default set of events
            }



            var list = new List <CarChildModel>();

            _ConfigureLightbox(scheduler, cars);

            //load cars to the timeline view
            _ConfigureViews(scheduler, cars);

            //assign ViewData values
            _UpdateViewData(scheduler, context, state);

            //data loading/saving settings

            scheduler.LoadData            = true;
            scheduler.EnableDataprocessor = false;
            scheduler.Skin = DHXScheduler.Skins.Terrace;

            scheduler.SaveAction = Url.Action("Save", "HomeNew");
            scheduler.DataAction = Url.Action("Data", "HomeNew");

            //collect model
            var model = new ViewModel();

            model.Scheduler     = scheduler;
            model.CategoryCount = cars.Count();
            model.ChildCount    = list.Count();
            return(View(model));
        }
コード例 #6
0
ファイル: HomeNewController.cs プロジェクト: carrental/mvc
 /// <summary>
 /// Select cars
 /// </summary>
 /// <param name="context">context</param>
 /// <returns>IQueryable of car</returns>
 protected IQueryable <CarRental.Data.Car> _SelectCars(CarRental.Data.CarRentalDb context)
 {
     return(_SelectCars(context, null));
 }
コード例 #7
0
ファイル: HomeNewController.cs プロジェクト: carrental/mvc
        /// <summary>
        /// Create type select
        /// </summary>
        /// <param name="types">types</param>
        /// <param name="selected">selected</param>
        /// <returns>list with select list item</returns>
        private List <SelectListItem> _CreateTypeSelect(IEnumerable <CarRental.Data.CarType> types, FormState state, CarRental.Data.CarRentalDb context)
        {
            var selected  = state.Type;
            var typesList = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Value = "", Text = "Any"
                }
            };

            foreach (var type in types)
            {
                state.Type = type.Id;
                var item = new SelectListItem()
                {
                    Value = type.Id.ToString(), Text = string.Format("{0}: {1} cars", type.title, _SelectCars(context, state).Count())
                };
                if (selected != null && type.Id == selected.Value)
                {
                    item.Selected = true;
                }
                typesList.Add(item);
            }
            return(typesList);
        }