Ejemplo n.º 1
0
        /// <summary>
        /// 将车次信息写入数据库
        /// </summary>
        /// <param name="table"></param>
        private static void WriteTrainNo(TimeTable table)
        {
            var trainNoBll = new TrainNoBll();

            table.TrainNo = trainNoBll.Insert(table.TrainNo);

            DataUpdateLog.SingleUpdate(nameof(TrainNo), table.TrainNo.Id, DataUpdateType.Insert); // 将数据更新记录同步到DbUpdataLog表中

            _trainNoCaches.Add(table.TrainNo);
        }
Ejemplo n.º 2
0
        public JsonResult SaveTrainNo()
        {
            var trainNoJson = Request["trainNo"];
            var trainNo     = JsonHelper.Deserialize <TrainNo>(trainNoJson);

            if (trainNo == null)
            {
                return(Json(ErrorModel.InputError));
            }

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

            var trainNoBll    = new TrainNoBll();
            var updateSuccess = false;

            if (trainNo.Id > 0)
            {
                updateSuccess = trainNoBll.Update(trainNo);
            }
            else
            {
                // 验证是否存在相同的车次
                var condition = string.Format("FullName='{0}' AND IsDelete=0", trainNo.FullName);
                if (trainNoBll.Exists(condition))
                {
                    return(Json(ErrorModel.ExistSameItem));
                }

                var insertedTrainNo = trainNoBll.Insert(trainNo);
                updateSuccess = insertedTrainNo.Id > 0;
            }

            if (!updateSuccess)
            {
                return(Json(ErrorModel.OperateFailed));
            }

            DataUpdateLog.SingleUpdate(typeof(TrainNo).Name, trainNo.Id, updateType);

            var linesJson = Request["lines"];
            var lines     = JsonHelper.Deserialize <TrainNoLine[]>(linesJson);

            if (lines == null || !lines.Any())
            {
                return(Json(ErrorModel.InputError));
            }

            var linesToInsert = lines.Where(line => line.Id == 0).ToArray();

            if (linesToInsert.Any())
            {
                linesToInsert.ForEach(line => { line.TrainNoId = trainNo.Id; });

                var trainNoLineBll = new TrainNoLineBll();
                var maxId          = (int)trainNoLineBll.GetMaxId();

                trainNoLineBll.BulkInsert(linesToInsert);

                DataUpdateLog.BulkUpdate(typeof(TrainNoLine).Name, maxId);
            }

            return(Json(ErrorModel.OperateSuccess));
        }