/// <summary> /// 更新喷漆车型档次分类 /// </summary> /// <param name="vehicleLevel"></param> /// <param name="vehicleIds"></param> /// <param name="initalWord"></param> /// <param name="operateUser"></param> /// <returns></returns> public bool UpdatePaintVehicleLevel(string vehicleLevel, string vehicleIds, string initalWord, string operateUser) { var result = false; try { var oldValue = SeletePaintVehicleByInitalWord(vehicleLevel, initalWord); dbScopeManagerCF.CreateTransaction(conn => { if (oldValue.Any()) { var isDeleteSuccess = DalSprayPaintVehicle.DeletePaintVehicleDataByInitalWord(conn, vehicleLevel, initalWord); if (isDeleteSuccess) { var toDelete = new List <VehicleLevelLog>(); if (!string.IsNullOrWhiteSpace(vehicleIds)) { foreach (var item in oldValue) { if (!vehicleIds.Split(',').Contains(item.VehicleId)) { toDelete.Add(item); } } } else { toDelete = oldValue; } if (toDelete.Any()) { foreach (var value in toDelete) { var log = new PaintVehicleOprLog { LogType = "PaintVehicleLevelConfig", VehicleLevel = value.VehicleLevel, VehicleId = value.VehicleId, OldValue = JsonConvert.SerializeObject(value), NewValue = null, Remarks = "Delete", OperateUser = operateUser, }; InsertLog("PaintVehicle", log); } } } } if (!string.IsNullOrWhiteSpace(vehicleIds)) { result = DalSprayPaintVehicle.AddPaintVehicleLevel(conn, vehicleLevel, vehicleIds); if (result) { Thread.Sleep(1000); var newValue = SeletePaintVehicleByInitalWord(vehicleLevel, initalWord); var toAdd = new List <VehicleLevelLog>(); foreach (var newData in newValue) { if (!oldValue.Any(p => p.VehicleId.Equals(newData.VehicleId))) { toAdd.Add(newData); } } if (toAdd.Any()) { foreach (var value in toAdd) { var log = new PaintVehicleOprLog { LogType = "PaintVehicleLevelConfig", VehicleLevel = value.VehicleLevel, VehicleId = value.VehicleId, OldValue = null, NewValue = JsonConvert.SerializeObject(value), Remarks = "Add", OperateUser = operateUser, }; InsertLog("PaintVehicle", log); } } } } else { result = true; } }); } catch (Exception ex) { Logger.Log(Level.Error, ex, "UpdatePaintVehicleLevel"); } return(result); }
/// <summary> /// 更新喷漆车型档次分类 /// </summary> /// <param name="vehicleLevel"></param> /// <param name="vehicleIds"></param> /// <param name="initalWord"></param> /// <param name="operateUser"></param> /// <returns></returns> public bool UpdatePaintVehicleLevel(string vehicleLevel, string vehicleIds, string initalWord, string type, string operateUser) { var result = false; try { var oldValue = SeletePaintVehicleByInitalWord(vehicleLevel, initalWord, type); var isValiad = type == PaintVehicleLevelTypeEnum.Offline.ToString() && dbScopeManagerCF.Execute(conn => DalSprayPaintVehicle.IsRepeatPaintVehicleLevelConfig(conn, vehicleIds, type)); var isDeleteSuccess = false; var isAddSuccess = false; if (isValiad) { result = false; } else { dbScopeManagerCF.CreateTransaction(conn => { if (type == PaintVehicleLevelTypeEnum.Online.ToString()) { //删除线下占用的车型喷漆 DalSprayPaintVehicle.DeletePaintVehicleDataByType(conn, vehicleIds, PaintVehicleLevelTypeEnum.Offline.ToString()); } if (oldValue.Any()) { isDeleteSuccess = DalSprayPaintVehicle.DeletePaintVehicleDataByInitalWord(conn, vehicleLevel, initalWord, type); } if (!string.IsNullOrWhiteSpace(vehicleIds)) { result = DalSprayPaintVehicle.AddPaintVehicleLevel(conn, vehicleLevel, vehicleIds, type); isAddSuccess = result; } else { result = true; } }); } if (isDeleteSuccess) { var toValue = new List <VehicleLevelLog>(); if (!string.IsNullOrWhiteSpace(vehicleIds)) { foreach (var item in oldValue) { if (!vehicleIds.Split(',').Contains(item.VehicleId)) { toValue.Add(item); } } } else { toValue = oldValue; } SavePaintVehicleLevelLog(toValue, "Delete", vehicleIds, operateUser); } if (isAddSuccess) { Thread.Sleep(1000); var toValue = new List <VehicleLevelLog>(); var newValue = SeletePaintVehicleByInitalWord(vehicleLevel, initalWord, type); foreach (var newData in newValue) { { if (!oldValue.Any(p => p.VehicleId.Equals(newData.VehicleId))) { toValue.Add(newData); } } } SavePaintVehicleLevelLog(newValue, "Add", vehicleIds, operateUser); } } catch (Exception ex) { Logger.Error("UpdatePaintVehicleLevel", ex); } return(result); }