예제 #1
0
        public JsonResult GetLineInfo(int id)
        {
            var lineBll  = new BaseLineBll();
            var lineData = lineBll.QuerySingle(id);

            if (lineData == null)
            {
                return(Json(ErrorModel.GetDataFailed));
            }

            var lineStationBll = new LineStationsBll();
            var lineStations   = lineStationBll.QueryList("LineId=" + id);

            var data = new
            {
                line     = lineData,
                stations = lineStations
            };

            return(Json(ErrorModel.GetDataSuccess(data)));
        }
예제 #2
0
        public ActionResult TrainMoment(int?trainNoId)
        {
            if (trainNoId == null)
            {
                return(RedirectToAction("TrainNo"));
            }

            var trainNoBll     = new TrainNoBll();
            var trainMomentBll = new ViewTrainMomentBll();

            var trainNo = trainNoBll.QuerySingle(trainNoId);

            if (trainNo == null)
            {
                return(RedirectToAction("TrainNo"));
            }

            var moments = trainMomentBll.QueryList("TrainNoId=" + trainNoId, null, null, "Sort").ToList();

            var trainMomentHasAdded = true;

            if (!moments.Any())
            {
                trainMomentHasAdded = false;

                var lineStationBll     = new LineStationsBll();
                var viewTrainNoLineBll = new ViewTrainNoLIneBll();

                var lines   = viewTrainNoLineBll.QueryList("Id=" + trainNoId, null, null, "Sort");
                var lineIds = lines.Select(item => item.LineId);

                var condition = string.Format("LineId IN({0})", string.Join(",", lineIds));
                var stations  = lineStationBll.QueryList(condition);

                var lineStationDic = new List <KeyValuePair <ViewTrainNoLIne, List <LineStations> > >();
                lines.ForEach(line =>
                {
                    // 将线路与其经过的车站以键值对的方式按顺序归到一起
                    var theStations = stations.Where(item => item.LineId == line.LineId).OrderBy(item => item.Sort);

                    lineStationDic.Add(new KeyValuePair <ViewTrainNoLIne, List <LineStations> >(line, theStations.ToList()));
                });

                // 构造一个ViewTrainMoment集合以便在前台统一展示
                var lineCounter  = 0;
                var stationOrder = 0;
                moments = new List <ViewTrainMoment>();
                lineStationDic.ForEach(item =>
                {
                    lineCounter++;

                    var tempLine    = item.Key;
                    var tempSations = item.Value;

                    var stationCounter = 0;
                    tempSations.ForEach(t =>
                    {
                        stationCounter++;
                        if (lineCounter > 1 && stationCounter == 1)
                        {
                            // 由于上一条线的终点站与下一站的终点站相同,此处去掉后一条线的起点站
                            return;
                        }

                        stationOrder++;

                        var model            = new ViewTrainMoment();
                        model.FullName       = trainNo.FullName;
                        model.Sort           = stationOrder;
                        model.StationName    = t.StationName;
                        model.TrainNoId      = trainNo.Id;
                        model.TrainNoLineId  = tempLine.TrainNoLineId;
                        model.TrainStationId = t.StationId;
                        model.LineId         = t.LineId;
                        model.LineName       = tempLine.LineName;

                        moments.Add(model);
                    });
                });
            }

            ViewBag.Id          = trainNoId;
            ViewBag.TrainNo     = trainNo;
            ViewBag.Moments     = moments.ToList();
            ViewBag.IsFirstTime = !trainMomentHasAdded;

            return(View());
        }