public Coolite.Ext.Web.Response SaveGameSimpleVersionList(string data)//保存GameSimpleVersionList { Response sr = new Response(true); if (VerirySecurityIP(GetIP4Address())) { sr.Success = false; sr.Msg = msgNoSafe; Log.Warn(msgNoSafe + Context.Request.UserHostAddress + "<>" + GSSServerIP + ""); return(sr); } try { GameCoreDBDataContext db = new GameCoreDBDataContext(); StoreDataHandler dataHandler = new StoreDataHandler(data); ChangeRecords <T_GameSimpleVersionList> dataList = dataHandler.ObjectData <T_GameSimpleVersionList>(); foreach (T_GameSimpleVersionList GameSimpleVersionList in dataList.Deleted) { db.T_GameSimpleVersionList.Attach(GameSimpleVersionList); db.T_GameSimpleVersionList.DeleteOnSubmit(GameSimpleVersionList); } foreach (T_GameSimpleVersionList GameSimpleVersionList in dataList.Updated) { db.T_GameSimpleVersionList.Attach(GameSimpleVersionList); db.Refresh(RefreshMode.KeepCurrentValues, GameSimpleVersionList); } foreach (T_GameSimpleVersionList GameSimpleVersionList in dataList.Created) { db.T_GameSimpleVersionList.InsertOnSubmit(GameSimpleVersionList); } db.SubmitChanges(); } catch (Exception ex) { sr.Success = false; sr.Msg = ex.Message; Log.Warn("SaveGameSimpleVersionList", ex); } return(sr); }
public Coolite.Ext.Web.Response SaveBattleZones(string data)//保存战区信息 { //首先进行数据处理:传递过来的数据情形可能如下: /* * { * "Created":[{ * "F_ZoneName":"内网联测","F_ZoneState2":"", * "F_ZoneState1":"","F_ZoneState0":"", * "F_ZoneState":"128","F_ZoneLine":"1", * "F_ZoneAttrib4":"1","F_ZoneAttrib2":"01", * "F_ZoneAttrib1":"1","F_ZoneAttrib0":"1", * "F_ChargeType":"0","F_CurVersion":"1", * "F_BigZoneID":"0" * }] * }*/ Response sr = new Response(true); if (VerirySecurityIP(GetIP4Address())) { sr.Success = false; sr.Msg = msgNoSafe; Log.Warn(msgNoSafe + Context.Request.UserHostAddress + "<>" + GSSServerIP + ""); return(sr); } try { data = data.Replace("\",\"F_ZoneState1\":\"", "").Replace("\",\"F_ZoneState0\":\"", ""); data = data.Replace("\"F_ZoneAttrib4\":", "\"F_ZoneAttrib\":").Replace("\",\"F_ZoneAttrib2\":\"", "").Replace("\",\"F_ZoneAttrib1\":\"", "").Replace("\",\"F_ZoneAttrib0\":\"", ""); //处理后的数据【在将json格式数据转换为对象时失败 string>short】 /* * { \"Created\": * [{ \"F_ZoneName\":\"Json\",\"F_ZoneState2\":\"\", \"F_ZoneState\":\"128\",\"F_ZoneLine\":\"1\", \"F_ZoneAttrib\":\"10011\",\"F_ChargeType\":\"0\", \"F_CurVersion\":\"2\",\"F_BigZoneID\":\"0\" * }] * } */ GameCoreDBDataContext db = new GameCoreDBDataContext(); RequestData request = JsonConvert.DeserializeObject <RequestData>(data); ChangeRecords <T_BattleZone> dataList = new ChangeRecords <T_BattleZone>(); dataList.Created = request.Created == null?null: request.Created.Select(s => s.MapObject <BattleZoneRequest, T_BattleZone>() ).ToList(); dataList.Updated = request.Updated == null ? null : request.Updated.Select(s => s.MapObject <BattleZoneRequest, T_BattleZone>()).ToList(); dataList.Deleted = request.Deleted == null ? null : request.Deleted.Select(s => s.MapObject <BattleZoneRequest, T_BattleZone>()).ToList(); //StoreDataHandler dataHandler = new StoreDataHandler(data); //ChangeRecords<T_BattleZone> dataList = dataHandler.ObjectData<T_BattleZone>(); foreach (T_BattleZone battlezone in dataList.Deleted) { battlezone.F_ZoneState = battlezone.F_ZoneState; battlezone.F_ZoneAttrib = Get10From2((int)battlezone.F_ZoneAttrib); db.T_BattleZone.Attach(battlezone); db.T_BattleZone.DeleteOnSubmit(battlezone); } foreach (T_BattleZone battlezone in dataList.Updated) { battlezone.F_ZoneState = battlezone.F_ZoneState; battlezone.F_ZoneAttrib = Get10From2((int)battlezone.F_ZoneAttrib); db.T_BattleZone.Attach(battlezone); db.Refresh(RefreshMode.KeepCurrentValues, battlezone); } foreach (T_BattleZone battlezone in dataList.Created) { battlezone.F_ZoneState = battlezone.F_ZoneState; battlezone.F_ZoneAttrib = Get10From2((int)battlezone.F_ZoneAttrib); db.T_BattleZone.InsertOnSubmit(battlezone); } db.SubmitChanges(); } catch (Exception ex) { sr.Success = false; sr.Msg = ex.Message; Log.Warn("SaveBattleZones", ex); } return(sr); }