Exemplo n.º 1
0
        public JsonResult LineEdit()
        {
            var lineJson = Request["line"];
            var line     = JsonHelper.Deserialize <BaseLine>(lineJson);

            var updateType = line.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert;

            // 更新线路
            var lineUpdateRes = false;
            var lineBll       = new BaseLineBll();

            if (line.Id > 0)
            {
                lineUpdateRes = lineBll.Update(line);
            }
            else
            {
                var condition = string.Format("LineName='{0}' AND IsDelete=0", line.LineName);
                if (lineBll.Exists(condition))
                {
                    return(Json(ErrorModel.ExistSameItem));
                }

                var insertedLine = lineBll.Insert(line);
                lineUpdateRes = insertedLine.Id > 0;
            }

            // 更新车站
            if (lineUpdateRes)
            {
                // 写入更新记录
                DataUpdateLog.SingleUpdate(typeof(BaseLine).Name, line.Id, updateType);

                var stationsJson = Request["stations"];
                var stations     = JsonHelper.Deserialize <LineStations[]>(stationsJson);
                if (!stations.Any())
                {
                    return(Json(ErrorModel.OperateSuccess));
                }

                stations.ForEach(f => { f.LineId = line.Id; });

                var stationsToInsert = stations.Where(f => f.Id == 0);
                var lineStationsBll  = new LineStationsBll();

                var maxId = (int)lineStationsBll.GetMaxId();

                lineStationsBll.BulkInsert(stationsToInsert);

                // 写入更新记录
                DataUpdateLog.BulkUpdate(typeof(LineStations).Name, maxId);

                return(Json(ErrorModel.OperateSuccess));
            }

            return(Json(ErrorModel.OperateFailed));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 构造线路-车站关系并写入数据库
        /// </summary>
        /// <param name="table"></param>
        private static void WriteLineStaionRelation(TimeTable table)
        {
            // 构造线路-车站关系并写入数据库
            var lineStationRelation = new List <LineStations>();

            for (var i = 0; i < table.Stations.Count; i++)
            {
                lineStationRelation.Add(new LineStations
                {
                    LineId      = table.Line.Id,
                    Sort        = i,
                    StationId   = table.Stations[i].Id,
                    StationName = table.Stations[i].StationName
                });
            }
            var lineStationsBll = new LineStationsBll();

            var startId = (int)lineStationsBll.GetMaxId(); // 记录插入之前的最大ID

            lineStationsBll.BulkInsert(lineStationRelation);
            DataUpdateLog.BulkUpdate(nameof(LineStations), startId); // 将数据更新记录同步到DbUpdataLog表中
        }