コード例 #1
0
        public HttpResponseMessage GenerateSchedule([FromUri] ScheduleParamsModel parameters)
        {
            //var dateFrom = (DateTime?)DateHelper.GetSunday(DateTime.Now);
            //var dateTo = (DateTime?)dateFrom.Value.AddDays(7).Date;
            //parameters.DateFrom = DateHelper.DateToString(dateFrom);
            //parameters.DateTo = DateHelper.DateToString(dateTo);

            var dateFrom = DateHelper.StringToDate(parameters.DateFrom);
            var dateTo   = DateHelper.StringToDate(parameters.DateTo);
            var fakeId   = 0;

            if (!dateFrom.HasValue || !dateTo.HasValue || string.IsNullOrEmpty(parameters.LinesIds))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            var schedule = scheduleService.GenerateSchedule(parameters)
                           .Select(x => new ScheduleItemModel(x))
                           .ToList();

            return(Request.CreateResponse(
                       HttpStatusCode.OK,
                       new
            {
                rows = schedule
            }));
        }
コード例 #2
0
        public HttpResponseMessage GetSchedule([FromUri] ScheduleParamsModel parameters, bool _search, string nd, int rows, int page, string sidx, string sord, string filters = "")
        {
            var items        = new List <ScheduleItemModel>();
            var totalRecords = 0;
            var linesIdsList = parameters.LinesIds != null
                ? parameters.LinesIds.Split(',').Select(int.Parse)
                : null;

            var dateFromDt = DateHelper.StringToDate(parameters.DateFrom);
            var dateToDt   = DateHelper.StringToDate(parameters.DateTo);

            using (var logic = new tblScheduleLogic())
            {
                items = logic.GetPaged(linesIdsList, dateFromDt, dateToDt, _search, rows, page, sidx, sord, filters)
                        .Select(z => new ScheduleItemModel(z)).ToList();
                totalRecords = logic.Schedule.Count();
            }
            return(Request.CreateResponse(
                       HttpStatusCode.OK,
                       new
            {
                total = (totalRecords + rows - 1) / rows,
                page,
                records = totalRecords,
                rows = items
            }));
        }
コード例 #3
0
        public IEnumerable <tblSchedule> GenerateSchedule(ScheduleParamsModel parameters)
        {
            var dateFrom = DateHelper.StringToDate(parameters.DateFrom);
            var dateTo   = DateHelper.StringToDate(parameters.DateTo);
            var schedule = new List <tblSchedule>();
            var fakeId   = 0;

            if (!dateFrom.HasValue || !dateTo.HasValue || string.IsNullOrEmpty(parameters.LinesIds))
            {
                return(null);
            }

            using (var logic = new LineLogic())
            {
                var lines = logic.GetLinesByPlan(parameters.LinesIds.Split(',').Select(int.Parse));

                foreach (var line in lines)
                {
                    var dates = GetScheduleLineDates(line, dateFrom.Value, dateTo.Value, parameters);
                    foreach (var date in dates)
                    {
                        var item = GenerateSingleSchedule(line, date, parameters.LeaveTime, parameters.ArriveTime);
                        item.Id = fakeId++;
                        schedule.Add(item);
                    }
                }
            }
            return(schedule);
        }
コード例 #4
0
        public bool PopulateLinesPlan()
        {
            var linesIds = new List <int>();
            var dateFrom = DateHelper.GetSunday(DateTime.Now); // DateTime.Now.AddDays(1).Date;
            var dateTo   = dateFrom.AddDays(7).Date;

            using (var logic = new LineLogic())
            {
                linesIds = logic.GetList().Select(x => x.Id).ToList();
            }
            var parameters = new ScheduleParamsModel
            {
                LinesIds   = string.Join(",", linesIds),
                DateFrom   = DateHelper.DateToString(dateFrom),
                DateTo     = DateHelper.DateToString(dateTo),
                ArriveTime = true,
                LeaveTime  = true,
                Sun        = true,
                Mon        = true,
                Tue        = true,
                Wed        = true,
                Thu        = true,
                Fri        = true,
                Sut        = true,
            };

            using (var logic = new tblLinesPlanLogic()) {
                // 0 Step - Remove all plans that has no line attached to it
                logic.DeleteAllUnbindedPlans();
                // 1 Step - Setting tblLines to LinesPlan state
                logic.SyncLinesToPlans();
            }
            // 2 Step - Generate new schedule sets by tblLines state
            var schedule = GenerateSchedule(parameters).ToList();

            // 3 Step - save new sets to tblSchedule
            return(SaveGeneratedShcedule(schedule, dateFrom, dateTo));
        }
コード例 #5
0
        private List <DateTime> GetScheduleLineDates(IWeekDatedObject line, DateTime dateFrom, DateTime dateTo, ScheduleParamsModel parameters)
        {
            var dates = new List <DateTime>();

            for (DateTime date = dateFrom; date <= dateTo; date = date.AddDays(1))
            {
                switch (date.DayOfWeek)
                {
                case DayOfWeek.Sunday:
                    if (line.Sun.HasValue && line.Sun.Value && parameters.Sun)
                    {
                        dates.Add(date);
                    }
                    break;

                case DayOfWeek.Monday:
                    if (line.Mon.HasValue && line.Mon.Value && parameters.Mon)
                    {
                        dates.Add(date);
                    }
                    break;

                case DayOfWeek.Tuesday:
                    if (line.Tue.HasValue && line.Tue.Value && parameters.Tue)
                    {
                        dates.Add(date);
                    }
                    break;

                case DayOfWeek.Wednesday:
                    if (line.Wed.HasValue && line.Wed.Value && parameters.Wed)
                    {
                        dates.Add(date);
                    }
                    break;

                case DayOfWeek.Thursday:
                    if (line.Thu.HasValue && line.Thu.Value && parameters.Thu)
                    {
                        dates.Add(date);
                    }
                    break;

                case DayOfWeek.Friday:
                    if (line.Fri.HasValue && line.Fri.Value && parameters.Fri)
                    {
                        dates.Add(date);
                    }
                    break;

                case DayOfWeek.Saturday:
                    if (line.Sut.HasValue && line.Sut.Value && parameters.Sut)
                    {
                        dates.Add(date);
                    }
                    break;
                }
            }
            return(dates);
        }